From f2b64a38a4d1d8f36636447484b6e0cd4aac18bd Mon Sep 17 00:00:00 2001 From: Ken Arroyo Ohori Date: Fri, 11 Nov 2016 18:10:38 -0600 Subject: [PATCH] =?UTF-8?q?Ignore=20attributes=20that=20couldn=E2=80=99t?= =?UTF-8?q?=20be=20interpreted=20as=20UTF8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DataStorage.swift | 17 ++++++++++++++--- src/Info.plist | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/DataStorage.swift b/src/DataStorage.swift index 1bf50e5..c236863 100644 --- a/src/DataStorage.swift +++ b/src/DataStorage.swift @@ -136,6 +136,7 @@ class DataStorage: NSObject, NSOutlineViewDataSource, NSOutlineViewDelegate { let firstElementOfIdBuffer = UnsafeRawPointer(cityGMLParser.currentObjectIdentifier(withLength: &idLength)) let idData = Data(bytes: firstElementOfIdBuffer!, count: Int(idLength)*MemoryLayout.size) objects.last!.id = String(data: idData, encoding: .utf8)! +// Swift.print("Object with id \(objects.last!.id)") var objectTypeLength: UInt = 0 let firstElementOfObjectTypeBuffer = UnsafeRawPointer(cityGMLParser.currentObjectType(withLength: &objectTypeLength)) @@ -148,14 +149,24 @@ class DataStorage: NSObject, NSOutlineViewDataSource, NSOutlineViewDelegate { var attributeNameLength: UInt = 0 let firstElementOfAttributeNameBuffer = UnsafeRawPointer(cityGMLParser.currentAttributeName(withLength: &attributeNameLength)) let attributeNameData = Data(bytes: firstElementOfAttributeNameBuffer!, count: Int(attributeNameLength)*MemoryLayout.size) - let attributeName = String(data: attributeNameData, encoding: .utf8)! + let attributeName = String(data: attributeNameData, encoding: .utf8) + if attributeName == nil { + Swift.print("Couldn't parse attribute name with \(attributeNameData)") + cityGMLParser.advanceAttributeIterator() + continue + } var attributeValueLength: UInt = 0 let firstElementOfAttributeValueBuffer = UnsafeRawPointer(cityGMLParser.currentAttributeValue(withLength: &attributeValueLength)) let attributeValueData = Data(bytes: firstElementOfAttributeValueBuffer!, count: Int(attributeValueLength)*MemoryLayout.size) - let attributeValue = String(data: attributeValueData, encoding: .utf8)! + let attributeValue = String(data: attributeValueData, encoding: .utf8) + if attributeValue == nil { + Swift.print("Couldn't parse attribute value with \(attributeValueData.base64EncodedString())") + cityGMLParser.advanceAttributeIterator() + continue + } - objects.last!.attributes.append(CityGMLObjectAttribute(name: attributeName, value: attributeValue)) + objects.last!.attributes.append(CityGMLObjectAttribute(name: attributeName!, value: attributeValue!)) cityGMLParser.advanceAttributeIterator() } diff --git a/src/Info.plist b/src/Info.plist index bf4293c..821fd90 100644 --- a/src/Info.plist +++ b/src/Info.plist @@ -32,7 +32,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.5 + 0.5.1 CFBundleVersion 1 LSApplicationCategoryType