Support giving color values as percentage

This commit is contained in:
Sven Weidauer 2021-01-01 12:52:20 +01:00
parent 911db304ae
commit e65f684654
2 changed files with 42 additions and 1 deletions

View file

@ -119,13 +119,25 @@ extension Scanner {
func commaSeparated() -> [UInt8]? {
var result: [UInt8] = []
repeat {
guard let int = scanInt(), let component = UInt8(exactly: int) else {
guard let component = self.component() else {
return nil
}
result.append(component)
} while string(",")
return result
}
func component() -> UInt8? {
guard var int = scanInt() else {
return nil
}
if string("%") {
int = int * 0xFF / 100
}
return UInt8(exactly: int)
}
}
private extension Scanner {