0001 // 0002 // ModesExtractor.swift 0003 // Rainbow 0004 // 0005 // Created by Wei Wang on 15/12/23. 0006 // 0007 // Copyright (c) 2015 Wei Wang <onevcat@gmail.com> 0008 // 0009 // Permission is hereby granted, free of charge, to any person obtaining a copy 0010 // of this software and associated documentation files (the "Software"), to deal 0011 // in the Software without restriction, including without limitation the rights 0012 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0013 // copies of the Software, and to permit persons to whom the Software is 0014 // furnished to do so, subject to the following conditions: 0015 // 0016 // The above copyright notice and this permission notice shall be included in 0017 // all copies or substantial portions of the Software. 0018 // 0019 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0020 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0021 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0022 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0023 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0024 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 0025 // THE SOFTWARE. 0026 0027 protocol ModesExtractor{ 0028 typealias ResultType
ModesExtractor.swift:32 struct ConsoleModesExtractor: ModesExtractor {ModesExtractor.swift:53 struct XcodeColorsModesExtractor: ModesExtractor {0029 func extractModeCodes(string: String) -> (codes: [ResultType], text: String) 0030 } 0031 0032 struct ConsoleModesExtractor
ModesExtractor.swift:29 func extractModeCodes(string: String) -> (codes: [ResultType], text: String): ModesExtractor { 0033 typealias ResultType = UInt8 0034 func extractModeCodes
Rainbow.swift:53 let result = ConsoleModesExtractor().extractModeCodes(string)(string: String) -> (codes: [UInt8], text: String) { 0035 let token = ControlCode.CSI 0036 var index = string.startIndex.advancedBy(token.characters.count) 0037 var codesString = "" 0038 while string.characters[index] != "m" { 0039 codesString.append(string.characters[index]) 0040 index = index.successor() 0041 } 0042 0043 let codes = codesString.characters.split(";").flatMap { UInt8(String($0)) } 0044 0045 let startIndex = index.successor() 0046 let endIndex = string.endIndex.advancedBy(-"\(token)0m".characters.count) 0047 let text = String(string.characters[startIndex ..< endIndex]) 0048 0049 return (codes, text) 0050 } 0051 } 0052 0053 struct XcodeColorsModesExtractor
Rainbow.swift:53 let result = ConsoleModesExtractor().extractModeCodes(string): ModesExtractor { 0054 typealias ResultType = String 0055 func extractModeCodes
Rainbow.swift:57 let result = XcodeColorsModesExtractor().extractModeCodes(string)(string: String) -> (codes: [String], text: String) { 0056 let token = ControlCode.CSI 0057 var index = string.startIndex 0058 0059 var codes = [String]() 0060 0061 var outer = String(string.characters[index]) //Start index should be the ESC control code 0062 while outer == ControlCode.ESC { 0063 var codesString = "" 0064 index = index.advancedBy(token.characters.count) 0065 0066 while string.characters[index] != ";" { 0067 codesString.append(string.characters[index]) 0068 index = index.successor() 0069 } 0070 0071 codes.append(codesString) 0072 index = index.successor() 0073 outer = String(string.characters[index]) 0074 } 0075 0076 let startIndex = index 0077 let endIndex = string.endIndex.advancedBy(-"\(token);".characters.count) 0078 let text = String(string.characters[startIndex ..< endIndex]) 0079 0080 return (codes, text) 0081 } 0082 }
Rainbow.swift:57 let result = XcodeColorsModesExtractor().extractModeCodes(string)