22//
33// This source file is part of the swift-nio-irc open source project
44//
5- // Copyright (c) 2018 ZeeZide GmbH. and the swift-nio-irc project authors
5+ // Copyright (c) 2018-2020 ZeeZide GmbH. and the swift-nio-irc project authors
66// Licensed under Apache License v2.0
77//
88// See LICENSE.txt for license information
@@ -56,11 +56,7 @@ public struct IRCMessageParser {
5656 if var ob = overflowBuffer {
5757 overflowBuffer = nil
5858 var bb = buffer
59- #if swift(>=5)
60- ob. writeBuffer ( & bb)
61- #else
62- ob. write ( buffer: & bb)
63- #endif
59+ ob. writeBuffer ( & bb)
6460 return feed ( ob, yield: yield)
6561 }
6662
@@ -71,11 +67,7 @@ public struct IRCMessageParser {
7167 var cursor = bp [ bp. startIndex..< bp. endIndex]
7268
7369 while !cursor. isEmpty {
74- #if swift(>=5)
75- guard var idx = cursor. firstIndex ( of: cNewline) else { break }
76- #else
77- guard var idx = cursor. index ( of: cNewline) else { break }
78- #endif
70+ guard var idx = cursor. firstIndex ( of: cNewline) else { break }
7971
8072 let nextCursor = cursor [ idx. advanced ( by: 1 ) ..< cursor. endIndex]
8173 if idx > cursor. startIndex && cursor [ idx - 1 ] == cCarriageReturn {
@@ -99,20 +91,12 @@ public struct IRCMessageParser {
9991
10092 if !cursor. isEmpty {
10193 overflowBuffer = allocator. buffer ( capacity: cursor. count)
102- #if swift(>=5)
103- overflowBuffer!. writeBytes ( cursor)
104- #else
105- overflowBuffer!. write ( bytes: cursor)
106- #endif
94+ overflowBuffer!. writeBytes ( cursor)
10795 }
10896 }
10997 }
11098
111- #if swift(>=4.1)
112- typealias Slice = Swift . Slice < UnsafeRawBufferPointer >
113- #else
114- typealias Slice = RandomAccessSlice < UnsafeRawBufferPointer >
115- #endif
99+ typealias Slice = Swift . Slice < UnsafeRawBufferPointer >
116100
117101 @inline ( __always)
118102 private func processLine( _ line: Slice ) throws -> IRCMessage {
@@ -126,7 +110,7 @@ public struct IRCMessageParser {
126110
127111 var cursor = line
128112
129- func isDigit( _ c: UInt8 ) -> Bool { return c >= 48 && c < 58 }
113+ func isDigit( _ c: UInt8 ) -> Bool { return c >= c0 && c <= c9 }
130114 func isLetter( _ c: UInt8 ) -> Bool {
131115 return ( c >= 0x41 && c <= 0x5A ) || ( c >= 0x61 && c <= 0x7A )
132116 }
@@ -155,12 +139,7 @@ public struct IRCMessageParser {
155139
156140 if cursor [ cursor. startIndex] == cColon {
157141 let startIndex = cursor. startIndex. advanced ( by: 1 )
158-
159- #if swift(>=5)
160- let spaceIdx = line. firstIndex ( of: cSpace)
161- #else
162- let spaceIdx = line. index ( of: cSpace)
163- #endif
142+ let spaceIdx = line. firstIndex ( of: cSpace)
164143
165144 guard let endSourceIdx = spaceIdx, endSourceIdx > startIndex else {
166145 throw Error . invalidPrefix ( Data ( line) )
@@ -203,12 +182,8 @@ public struct IRCMessageParser {
203182 cursor = cursor [ idx2. advanced ( by: 1 ) ..< cursor. endIndex]
204183 }
205184 else {
206- #if swift(>=5)
207- let endIdx = cursor. firstIndex ( where: { !isLetter( $0) } )
208- ?? cursor. endIndex
209- #else
210- let endIdx = cursor. index ( where: { !isLetter( $0) } ) ?? cursor. endIndex
211- #endif
185+ let endIdx = cursor. firstIndex ( where: { !isLetter( $0) } )
186+ ?? cursor. endIndex
212187
213188 let cmdSlice = cursor [ cursor. startIndex..< endIdx]
214189 guard let s = makeString ( from: cmdSlice) else {
@@ -238,13 +213,9 @@ public struct IRCMessageParser {
238213 nextCursor = cursor [ cursor. endIndex..< cursor. endIndex]
239214 }
240215 else if isNoSpaceControlLineFeedColon ( cursor [ cursor. startIndex] ) {
241- #if swift(>=5)
242- let idxO = cursor. firstIndex ( where: {
243- !isNoSpaceControlLineFeedColon( $0)
244- } )
245- #else
246- let idxO = cursor. index ( where: { !isNoSpaceControlLineFeedColon( $0) } )
247- #endif
216+ let idxO = cursor. firstIndex ( where: {
217+ !isNoSpaceControlLineFeedColon( $0)
218+ } )
248219 let idx = idxO ?? cursor. endIndex
249220 argSlice = cursor [ cursor. startIndex..< idx]
250221 nextCursor = cursor [ idx..< cursor. endIndex]
@@ -287,4 +258,3 @@ public struct IRCMessageParser {
287258 }
288259 }
289260}
290-
0 commit comments