Skip to content

Commit

Permalink
Bugfix: sometimes string values are parsed as floats
Browse files Browse the repository at this point in the history
workaround. if there is string value from catana, use it, otherwise interpolate as float
  • Loading branch information
LeoSchleicher committed Oct 9, 2017
1 parent 9cb1371 commit 6c79313
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions Sources/StyleSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -446,19 +446,22 @@ public struct StyleSheet: Equatable {
private func makeDeclaration(_ declaration: KatanaDeclaration) -> StyleDeclaration {
return StyleDeclaration(name: String(cString: declaration.property), value: makeValue(declaration.values.pointee), important: declaration.important)
}

private func makeValue(_ values: KatanaArray) -> String {
let values: [KatanaValue] = fromKatanaArray(array: values)
return values.map { value in
if value.isInt {
return String(cString: value.raw)
} else if value.value.fValue >= Double.leastNormalMagnitude {
return "\(value.value.fValue)"
} else {
return String(cString: value.value.string)
}
}.joined(separator: " ")
}
let values: [KatanaValue] = fromKatanaArray(array: values)
return values.map { value in
if value.isInt {
return String(cString: value.raw)
/*} else if value.value.fValue >= Double.leastNormalMagnitude {
print("is double: \(value.value.fValue)")
return "\(value.value.fValue)"*/
} else if (value.value.string != nil) {
return String(cString: value.value.string)
} else { // float!
return "\(value.value.fValue)"
}
}.joined(separator: " ")
}

private func fromKatanaArray<T>(array: KatanaArray) -> [T] {
var data = array.data
Expand Down

2 comments on commit 6c79313

@mcudich
Copy link

@mcudich mcudich commented on 6c79313 Oct 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a test case or two would help here. Can you add a failing test so I can get a better idea of what you're fixing?

@LeoSchleicher
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/LeoSchleicher/csstest

But test fails not each time!

Please sign in to comment.