Skip to content

Commit

Permalink
Ignore attributes that couldn’t be interpreted as UTF8
Browse files Browse the repository at this point in the history
  • Loading branch information
kenohori committed Nov 12, 2016
1 parent 92c66c2 commit f2b64a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/DataStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int8>.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))
Expand All @@ -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<Int8>.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<Int8>.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()
}

Expand Down
2 changes: 1 addition & 1 deletion src/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.5</string>
<string>0.5.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
Expand Down

0 comments on commit f2b64a3

Please sign in to comment.