-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathKeyValueBuilder.swift
35 lines (28 loc) · 1.04 KB
/
KeyValueBuilder.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// NilBuilder.swift
// Eject
//
// Created by Brian King on 10/19/16.
// Copyright © 2016 Brian King. All rights reserved.
//
import Foundation
struct KeyValueBuilder: Builder, CharacterBuilder {
let value: BasicValue
let ignoredKeys: [String]
init(value: String = "", format: ValueFormat = .raw, ignoredKeys: [String] = []) {
self.value = BasicValue(value: value, format: format)
self.ignoredKeys = ignoredKeys
}
func buildElement(attributes: inout [String: String], document: XIBDocument, parent: Reference?) throws -> Reference? {
if let parent = parent {
let key = try attributes.removeRequiredValue(forKey: "key")
guard !ignoredKeys.contains(key) else { return parent }
value.value = attributes.removeValue(forKey: "value") ?? value.value
try document.addVariableConfiguration(for: parent.identifier, attribute: key, value: value)
}
return parent
}
func found(characters: String) {
value.value.append(characters)
}
}