0001    //
0002    //  CodesParser.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 CodesParser
CodesParser.swift:33
struct ConsoleCodesParser: CodesParser {
CodesParser.swift:57
struct XcodeColorsCodesParser: CodesParser {
{ 0028 typealias SourceType
CodesParser.swift:29
    func parseModeCodes(codes: [SourceType]) ->
0029 func parseModeCodes(codes: [SourceType]) -> 0030 (color: Color?, backgroundColor: BackgroundColor?, styles: [Style]?) 0031 } 0032 0033 struct ConsoleCodesParser
Rainbow.swift:54
            let (color, backgroundColor, styles) = ConsoleCodesParser().parseModeCodes(result.codes)
String+Rainbow.swift:162
        let input = ConsoleCodesParser().parseModeCodes( codes.map{ $0.value } )
: CodesParser { 0034 typealias SourceType = UInt8 0035 func parseModeCodes
Rainbow.swift:54
            let (color, backgroundColor, styles) = ConsoleCodesParser().parseModeCodes(result.codes)
String+Rainbow.swift:162
        let input = ConsoleCodesParser().parseModeCodes( codes.map{ $0.value } )
(codes: [UInt8]) -> (color: Color?, backgroundColor: BackgroundColor?, styles: [Style]?) { 0036 var color: Color? = nil 0037 var backgroundColor: BackgroundColor? = nil 0038 var styles: [Style]? = nil 0039 0040 for code in codes { 0041 if let c = Color(rawValue: code) { 0042 color = c 0043 } else if let bg = BackgroundColor(rawValue: code) { 0044 backgroundColor = bg 0045 } else if let style = Style(rawValue: code) { 0046 if styles == nil { 0047 styles = [] 0048 } 0049 styles!.append(style) 0050 } 0051 } 0052 0053 return (color, backgroundColor, styles) 0054 } 0055 } 0056 0057 struct XcodeColorsCodesParser
Rainbow.swift:58
            let (color, backgroundColor, _) = XcodeColorsCodesParser().parseModeCodes(result.codes)
: CodesParser { 0058 typealias SourceType = String 0059 func parseModeCodes
Rainbow.swift:58
            let (color, backgroundColor, _) = XcodeColorsCodesParser().parseModeCodes(result.codes)
(codes: [String]) -> (color: Color?, backgroundColor: BackgroundColor?, styles: [Style]?) { 0060 var color: Color? = nil 0061 var backgroundColor: BackgroundColor? = nil 0062 0063 for code in codes { 0064 if let c = Color(xcodeColorsDescription: code) { 0065 color = c 0066 } else if let bg = BackgroundColor(xcodeColorsDescription: code) { 0067 backgroundColor = bg 0068 } 0069 } 0070 0071 return (color, backgroundColor, nil) 0072 } 0073 }