Skip to content

Commit

Permalink
Fix #40
Browse files Browse the repository at this point in the history
Fixes bug where certain classes may fail to generate the appropriate open tag to string with right XML-style format
  • Loading branch information
vincentneo committed Jun 6, 2019
1 parent 49646fe commit 92a064a
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 9 deletions.
3 changes: 1 addition & 2 deletions Classes/GPXBounds.swift
Expand Up @@ -85,7 +85,6 @@ open class GPXBounds: GPXElement {
if let maxLongitude = maxLongitude {
attribute.appendFormat(" maxlon=\"%f\"", maxLongitude)
}

gpx.appendFormat("%@<%@%@>\r\n", indent(forIndentationLevel: indentationLevel))
gpx.appendOpenTag(indentation: indent(forIndentationLevel: indentationLevel), tag: tagName(), attribute: attribute)
}
}
2 changes: 1 addition & 1 deletion Classes/GPXCopyright.swift
Expand Up @@ -84,7 +84,7 @@ open class GPXCopyright: GPXElement {
attribute.appendFormat(" author=\"%@\"", author)
}

gpx.appendFormat("%@<%@%@>\r\n", tagName())
gpx.appendOpenTag(indentation: indent(forIndentationLevel: indentationLevel), tag: tagName(), attribute: attribute)
}

override func addChildTag(toGPX gpx: NSMutableString, indentationLevel: Int) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/GPXEmail.swift
Expand Up @@ -77,6 +77,6 @@ open class GPXEmail: GPXElement {
if let domain = domain {
attribute.appendFormat(" domain=\"%@\"", domain)
}
gpx.appendFormat("%@<%@%@>\r\n", indent(forIndentationLevel: indentationLevel), self.tagName(), attribute)
gpx.appendOpenTag(indentation: indent(forIndentationLevel: indentationLevel), tag: tagName(), attribute: attribute)
}
}
2 changes: 1 addition & 1 deletion Classes/GPXLink.swift
Expand Up @@ -107,7 +107,7 @@ open class GPXLink: GPXElement, Codable {
if let href = href {
attribute.appendFormat(" href=\"%@\"", href)
}
gpx.appendFormat("%@<%@%@>\r\n", indent(forIndentationLevel: indentationLevel), self.tagName(), attribute)
gpx.appendOpenTag(indentation: indent(forIndentationLevel: indentationLevel), tag: tagName(), attribute: attribute)
}

override func addChildTag(toGPX gpx: NSMutableString, indentationLevel: Int) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/GPXPoint.swift
Expand Up @@ -56,7 +56,7 @@ open class GPXPoint: GPXElement {
attribute.appendFormat(" lon=\"%f\"", longitude)
}

gpx.appendFormat("%@<%@%@>\r\n", indent(forIndentationLevel: indentationLevel), self.tagName(), attribute)
gpx.appendOpenTag(indentation: indent(forIndentationLevel: indentationLevel), tag: tagName(), attribute: attribute)
}

override func addChildTag(toGPX gpx: NSMutableString, indentationLevel: Int) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/GPXRoot.swift
Expand Up @@ -303,7 +303,7 @@ open class GPXRoot: GPXElement {

gpx.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n")

gpx.appendFormat("%@<%@%@>\r\n", self.indent(forIndentationLevel: indentationLevel), self.tagName(), attribute)
gpx.appendOpenTag(indentation: indent(forIndentationLevel: indentationLevel), tag: tagName(), attribute: attribute)
}

override func addChildTag(toGPX gpx: NSMutableString, indentationLevel: Int) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/GPXWaypoint.swift
Expand Up @@ -278,7 +278,7 @@ open class GPXWaypoint: GPXElement, Codable {
attribute.appendFormat(" lon=\"%f\"", longitude!)
}

gpx.appendFormat("%@<%@%@>\r\n", indent(forIndentationLevel: indentationLevel), self.tagName(), attribute)
gpx.appendOpenTag(indentation: indent(forIndentationLevel: indentationLevel), tag: tagName(), attribute: attribute)
}

override func addChildTag(toGPX gpx: NSMutableString, indentationLevel: Int) {
Expand Down
42 changes: 42 additions & 0 deletions Classes/NSMutableString+XML.swift
@@ -0,0 +1,42 @@
//
// NSMutableString+XML.swift
// Pods
//
// Created by Vincent Neo on 6/6/19.
//

import Foundation

/**
To ensure that all appended tags are appended with the right formats.
For both open and close tags.
*/
extension NSMutableString {

/// 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
func appendOpenTag(indentation: NSMutableString, tag: String, attribute: NSMutableString) {
self.appendFormat("%@<%@%@>\r\n", indentation, tag, attribute)
}

/// 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
func appendCloseTag(indentation: NSMutableString, tag: String) {
self.appendFormat("%@</%@>\r\n", indentation, tag)
}

}
2 changes: 1 addition & 1 deletion CoreGPX.podspec
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'CoreGPX'
s.version = '0.5.5'
s.version = '0.5.6'
s.summary = 'A library for reading and creation of GPX location log files.'

# This description is used to generate tags and improve search results.
Expand Down
9 changes: 9 additions & 0 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 92a064a

Please sign in to comment.