Created
May 16, 2016 23:11
-
-
Save FredLoh/027de95609741226ce7ac5efca7f3a00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ConsoleModesExtractor: ModesExtractor { | |
typealias ResultType = UInt8 | |
func extractModeCodes(string: String) -> (codes: [UInt8], text: String) { | |
let token = ControlCode.CSI | |
var index = string.startIndex.advancedBy(token.characters.count) | |
var codesString = "" | |
while string.characters[index] != "m" { | |
codesString.append(string.characters[index]) | |
index = index.successor() | |
} | |
let codes = codesString.characters.split(separator: ";", maxSplits: Int.max, omittingEmptySubsequences: false) | |
let startIndex = index.successor() | |
string.endIndex | |
let endIndex = string.endIndex.advancedBy(-"\(token)0m".characters.count) | |
let text = String(string.characters[startIndex ..< endIndex]) | |
return (codes, text) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment