Skip to content

Commit

Permalink
Fixed dot notation being too aggressive, and removed it from variadic…
Browse files Browse the repository at this point in the history
… subscripts
  • Loading branch information
Obbut committed Dec 10, 2016
1 parent aabad31 commit 15714e7
Showing 1 changed file with 5 additions and 26 deletions.
31 changes: 5 additions & 26 deletions Sources/Document+Subscripts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,23 @@ extension Document {
get {
guard let meta = getMeta(forKeyBytes: [UInt8](key.utf8)) else {
// use dot syntax
var parts = key.components(separatedBy: ".")
let parts = key.components(separatedBy: ".")

guard parts.count >= 2 else {
return .nothing
}

let firstPart = parts.removeFirst()

var value: Value = self[firstPart]
while !parts.isEmpty {
let part = parts.removeFirst()

value = value[part]
}

return value
return self[parts]
}

return getValue(atDataPosition: meta.dataPosition, withType: meta.type)
}

set {
let parts = key.characters.split(separator: ".", maxSplits: 1, omittingEmptySubsequences: false)
let parts = key.components(separatedBy: ".")

if parts.count == 2 {
let firstPart = String(parts[0])
let secondPart = String(parts[1])

self[firstPart][secondPart] = newValue
if parts.count > 1 {
self[parts] = newValue
return
}

Expand Down Expand Up @@ -108,15 +96,6 @@ extension Document {
set {
if parts.count == 1 {
let key = parts[0]
let parts = key.characters.split(separator: ".", maxSplits: 1, omittingEmptySubsequences: false)

if parts.count == 2 {
let firstPart = String(parts[0])
let secondPart = String(parts[1])

self[firstPart][secondPart] = newValue
return
}

if let meta = getMeta(forKeyBytes: [UInt8](key.utf8)) {
let len = getLengthOfElement(withDataPosition: meta.dataPosition, type: meta.type)
Expand Down

0 comments on commit 15714e7

Please sign in to comment.