-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathString+XML.swift
55 lines (46 loc) · 1.5 KB
/
String+XML.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// NSMutableString+XML.swift
// CoreGPX
//
// Created by Vincent Neo on 6/6/19.
//
import Foundation
extension String {
/// Appends an open tag
///
/// This function will append an open tag with the right format.
///
/// **Format it will append to:**
///
/// "%@<%@%@>\r\n"
/// //indentations <tagName attributes> \r\n
mutating func appendOpenTag(indentation: String, tag: String, attribute: String) {
self.append(String(format: "%@<%@%@>\r\n", indentation, tag, attribute))
}
mutating func appendOpenTag(indentation: String, tag: String, attributes: [TCXAttribute]) {
var attributeStr = String()
for attribute in attributes {
attributeStr += attribute.text()
}
self.append(String(format: "%@<%@%@>\r\n", indentation, tag, attributeStr))
}
/// Appends a close tag
///
/// This function will append an close tag with the right format.
/// Not currently used, but included, for ease of use when needed.
///
/// **Format it will append to:**
///
/// "%@</%@>\r\n"
/// //indentations </tagName> \r\n
mutating func appendCloseTag(indentation: String, tag: String) {
self.append(String(format: "%@</%@>\r\n", indentation, tag))
}
}
struct TCXAttribute {
var name: String
var value: String
func text() -> String {
return " \(name)=\"\(value)\""
}
}