0001 /* 0002 The MIT License (MIT) 0003 0004 Copyright (c) 2015 Shun Takebayashi 0005 0006 Permission is hereby granted, free of charge, to any person obtaining a copy 0007 of this software and associated documentation files (the "Software"), to deal 0008 in the Software without restriction, including without limitation the rights 0009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0010 copies of the Software, and to permit persons to whom the Software is 0011 furnished to do so, subject to the following conditions: 0012 0013 The above copyright notice and this permission notice shall be included in all 0014 copies or substantial portions of the Software. 0015 0016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0019 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0021 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0022 SOFTWARE. 0023 */ 0024 0025 extension String { 0026 0027 func trimLeft(char: Character, maxCount: Int = -1) -> String { 0028 if self.isEmpty { 0029 return "" 0030 } 0031 if self[self.startIndex] == char { 0032 let sub = self[self.startIndex.advancedBy(1)..<self.endIndex] 0033 if maxCount == 1 { 0034 return sub 0035 } 0036 let nextCount = maxCount > 1 ? maxCount - 1 : self.characters.count 0037 return sub.trimLeft(char, maxCount: nextCount) 0038 } 0039 return self 0040 } 0041 0042 func trimRight
HTTPRequestParser.swift:76 let value = String(field[1]).trimLeft(" ", maxCount: 1)String.swift:37 return sub.trimLeft(char, maxCount: nextCount)(char: Character, maxCount: Int = -1) -> String { 0043 if self.isEmpty { 0044 return "" 0045 } 0046 if self[self.endIndex.predecessor()] == char { 0047 let sub = self[self.startIndex..<self.endIndex.predecessor()] 0048 if maxCount == 1 { 0049 return sub 0050 } 0051 let nextCount = maxCount > 1 ? maxCount - 1 : self.characters.count 0052 return sub.trimRight(char, maxCount: nextCount) 0053 } 0054 return self 0055 } 0056 0057 func bytes() -> [Int8] { 0058 var buffer = [Int8]() 0059 withCString { raw in 0060 var bytes = raw 0061 while true { 0062 let byte = bytes.memory 0063 buffer.append(byte) 0064 if byte == 0 { 0065 break 0066 } 0067 bytes = bytes.advancedBy(1) 0068 } 0069 } 0070 return buffer 0071 } 0072 0073 } 0074
HTTPRequestParser.swift:61 let str = (String.fromCString(bytes) ?? "").trimRight(DefaultHTTPRequestParser.CRLF)String.swift:52 return sub.trimRight(char, maxCount: nextCount)