Skip to content

Commit f2b64a3

Browse files
committed
Ignore attributes that couldn’t be interpreted as UTF8
1 parent 92c66c2 commit f2b64a3

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/DataStorage.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class DataStorage: NSObject, NSOutlineViewDataSource, NSOutlineViewDelegate {
136136
let firstElementOfIdBuffer = UnsafeRawPointer(cityGMLParser.currentObjectIdentifier(withLength: &idLength))
137137
let idData = Data(bytes: firstElementOfIdBuffer!, count: Int(idLength)*MemoryLayout<Int8>.size)
138138
objects.last!.id = String(data: idData, encoding: .utf8)!
139+
// Swift.print("Object with id \(objects.last!.id)")
139140

140141
var objectTypeLength: UInt = 0
141142
let firstElementOfObjectTypeBuffer = UnsafeRawPointer(cityGMLParser.currentObjectType(withLength: &objectTypeLength))
@@ -148,14 +149,24 @@ class DataStorage: NSObject, NSOutlineViewDataSource, NSOutlineViewDelegate {
148149
var attributeNameLength: UInt = 0
149150
let firstElementOfAttributeNameBuffer = UnsafeRawPointer(cityGMLParser.currentAttributeName(withLength: &attributeNameLength))
150151
let attributeNameData = Data(bytes: firstElementOfAttributeNameBuffer!, count: Int(attributeNameLength)*MemoryLayout<Int8>.size)
151-
let attributeName = String(data: attributeNameData, encoding: .utf8)!
152+
let attributeName = String(data: attributeNameData, encoding: .utf8)
153+
if attributeName == nil {
154+
Swift.print("Couldn't parse attribute name with \(attributeNameData)")
155+
cityGMLParser.advanceAttributeIterator()
156+
continue
157+
}
152158

153159
var attributeValueLength: UInt = 0
154160
let firstElementOfAttributeValueBuffer = UnsafeRawPointer(cityGMLParser.currentAttributeValue(withLength: &attributeValueLength))
155161
let attributeValueData = Data(bytes: firstElementOfAttributeValueBuffer!, count: Int(attributeValueLength)*MemoryLayout<Int8>.size)
156-
let attributeValue = String(data: attributeValueData, encoding: .utf8)!
162+
let attributeValue = String(data: attributeValueData, encoding: .utf8)
163+
if attributeValue == nil {
164+
Swift.print("Couldn't parse attribute value with \(attributeValueData.base64EncodedString())")
165+
cityGMLParser.advanceAttributeIterator()
166+
continue
167+
}
157168

158-
objects.last!.attributes.append(CityGMLObjectAttribute(name: attributeName, value: attributeValue))
169+
objects.last!.attributes.append(CityGMLObjectAttribute(name: attributeName!, value: attributeValue!))
159170
cityGMLParser.advanceAttributeIterator()
160171
}
161172

src/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<key>CFBundlePackageType</key>
3333
<string>APPL</string>
3434
<key>CFBundleShortVersionString</key>
35-
<string>0.5</string>
35+
<string>0.5.1</string>
3636
<key>CFBundleVersion</key>
3737
<string>1</string>
3838
<key>LSApplicationCategoryType</key>

0 commit comments

Comments
 (0)