From 92a064a92233d7f666f8cd0ab20f5295b6d0d018 Mon Sep 17 00:00:00 2001 From: Vincent Neo <23420208+vincentneo@users.noreply.github.com> Date: Thu, 6 Jun 2019 09:58:48 +0800 Subject: [PATCH] Fix #40 Fixes bug where certain classes may fail to generate the appropriate open tag to string with right XML-style format --- Classes/GPXBounds.swift | 3 +- Classes/GPXCopyright.swift | 2 +- Classes/GPXEmail.swift | 2 +- Classes/GPXLink.swift | 2 +- Classes/GPXPoint.swift | 2 +- Classes/GPXRoot.swift | 2 +- Classes/GPXWaypoint.swift | 2 +- Classes/NSMutableString+XML.swift | 42 +++++++++++++++++++++ CoreGPX.podspec | 2 +- Example/Pods/Pods.xcodeproj/project.pbxproj | 9 +++++ 10 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 Classes/NSMutableString+XML.swift diff --git a/Classes/GPXBounds.swift b/Classes/GPXBounds.swift index 3316e9a..eab9b46 100644 --- a/Classes/GPXBounds.swift +++ b/Classes/GPXBounds.swift @@ -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) } } diff --git a/Classes/GPXCopyright.swift b/Classes/GPXCopyright.swift index 882f46e..077a7bd 100644 --- a/Classes/GPXCopyright.swift +++ b/Classes/GPXCopyright.swift @@ -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) { diff --git a/Classes/GPXEmail.swift b/Classes/GPXEmail.swift index 068df3f..fa7502b 100644 --- a/Classes/GPXEmail.swift +++ b/Classes/GPXEmail.swift @@ -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) } } diff --git a/Classes/GPXLink.swift b/Classes/GPXLink.swift index 9518ba5..57c31ff 100644 --- a/Classes/GPXLink.swift +++ b/Classes/GPXLink.swift @@ -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) { diff --git a/Classes/GPXPoint.swift b/Classes/GPXPoint.swift index 704426a..ee8e474 100644 --- a/Classes/GPXPoint.swift +++ b/Classes/GPXPoint.swift @@ -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) { diff --git a/Classes/GPXRoot.swift b/Classes/GPXRoot.swift index f3aab1c..275f6ba 100644 --- a/Classes/GPXRoot.swift +++ b/Classes/GPXRoot.swift @@ -303,7 +303,7 @@ open class GPXRoot: GPXElement { gpx.append("\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) { diff --git a/Classes/GPXWaypoint.swift b/Classes/GPXWaypoint.swift index ebc42bb..5e9f9c7 100644 --- a/Classes/GPXWaypoint.swift +++ b/Classes/GPXWaypoint.swift @@ -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) { diff --git a/Classes/NSMutableString+XML.swift b/Classes/NSMutableString+XML.swift new file mode 100644 index 0000000..a4fcd25 --- /dev/null +++ b/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 \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 \r\n + func appendCloseTag(indentation: NSMutableString, tag: String) { + self.appendFormat("%@\r\n", indentation, tag) + } + +} diff --git a/CoreGPX.podspec b/CoreGPX.podspec index 624b412..bdbb033 100644 --- a/CoreGPX.podspec +++ b/CoreGPX.podspec @@ -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. diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index c3b9334..baa74ea 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -8,6 +8,9 @@ /* Begin PBXBuildFile section */ 07834B15CF0306D2C4DD8E44CEC68C2B /* GPXAuthor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAFE9B5F15EF40449A8A82D34D4C81A6 /* GPXAuthor.swift */; }; + 124A780922A8A52300D51D50 /* NSMutableString+XML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124A780822A8A52300D51D50 /* NSMutableString+XML.swift */; }; + 124A780A22A8A52300D51D50 /* NSMutableString+XML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124A780822A8A52300D51D50 /* NSMutableString+XML.swift */; }; + 124A780B22A8A52300D51D50 /* NSMutableString+XML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124A780822A8A52300D51D50 /* NSMutableString+XML.swift */; }; 18F349D40EE13C89C63260076BFAED43 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5A16F4CFC63FAC439D7A04994F579A03 /* Foundation.framework */; }; 2267759FF0A171F668C7575CBCEBD6D6 /* GPXPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F3F06D38496EE021E5A0F77FE3C9866 /* GPXPoint.swift */; }; 328C594ED09DD9C7F3DDE1A61CB24320 /* GPXPointSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A931BE67E28BADAA46DD76D551372D6 /* GPXPointSegment.swift */; }; @@ -130,6 +133,7 @@ 00F0F353A2A50ADD440CE1D078B16908 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 06E95C5A2842B177852DDE7EF191CCAB /* CoreGPX-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "CoreGPX-umbrella.h"; sourceTree = ""; }; 1235C6DC221C44B1006EE067 /* CoreGPX.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = CoreGPX.xcodeproj; path = ../CoreGPX.xcodeproj; sourceTree = ""; }; + 124A780822A8A52300D51D50 /* NSMutableString+XML.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "NSMutableString+XML.swift"; path = "Classes/NSMutableString+XML.swift"; sourceTree = ""; }; 171B80D4BA423019BBC5DA54E387180A /* GPXTrackSegment.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = GPXTrackSegment.swift; path = Classes/GPXTrackSegment.swift; sourceTree = ""; }; 1D2E30143C1734DE1D811B70D043A405 /* CoreGPX-prefix.pch */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "CoreGPX-prefix.pch"; sourceTree = ""; }; 27D4563E6DE8F7E40ACEB108805D72A7 /* Pods-CoreGPX_Tests-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-CoreGPX_Tests-frameworks.sh"; sourceTree = ""; }; @@ -307,6 +311,7 @@ 5BDA16A124E1CE8C773AAF30C70A8C99 /* GPXWaypoint.swift */, BF75731C224663AD009DB87D /* DateTimeParsers.swift */, BF6BBEF322439E6A007ED5A9 /* Converters.swift */, + 124A780822A8A52300D51D50 /* NSMutableString+XML.swift */, 13E2CBACE1AF75A1A31B6C368F9F5EB1 /* Pod */, DBC58D84A5ED8C67B7F8FCDEA83C9DD6 /* Support Files */, ); @@ -626,6 +631,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 7DB346D0F39D3F0E887471402A8071AB; @@ -713,6 +719,7 @@ 4593377380E79042C9216EFA56EB6577 /* GPXLink.swift in Sources */, AF08350B73D09B7E2F4601E9C8173977 /* GPXMetadata.swift in Sources */, 5CCF68DAA1D98BECBCA6510FFE7E7F70 /* GPXParser.swift in Sources */, + 124A780922A8A52300D51D50 /* NSMutableString+XML.swift in Sources */, A747EE957A27BF62DFD53F20F453081E /* GPXPerson.swift in Sources */, BF75731D224663AD009DB87D /* DateTimeParsers.swift in Sources */, BF6BBEF422439E6A007ED5A9 /* Converters.swift in Sources */, @@ -753,6 +760,7 @@ BF5A9E4D220885F7003A5379 /* GPXBounds.swift in Sources */, BF5A9E4C220885F7003A5379 /* GPXAuthor.swift in Sources */, BF5A9E5B220885F7003A5379 /* GPXTrack.swift in Sources */, + 124A780B22A8A52300D51D50 /* NSMutableString+XML.swift in Sources */, BF5A9E51220885F7003A5379 /* GPXExtensions.swift in Sources */, BF5A9E5A220885F7003A5379 /* GPXRoutePoint.swift in Sources */, ); @@ -790,6 +798,7 @@ BF5A9E39220885F7003A5379 /* GPXBounds.swift in Sources */, BF5A9E38220885F7003A5379 /* GPXAuthor.swift in Sources */, BF5A9E47220885F7003A5379 /* GPXTrack.swift in Sources */, + 124A780A22A8A52300D51D50 /* NSMutableString+XML.swift in Sources */, BF5A9E3D220885F7003A5379 /* GPXExtensions.swift in Sources */, BF5A9E46220885F7003A5379 /* GPXRoutePoint.swift in Sources */, );