Skip to content

Commit a6039d0

Browse files
committed
Merge branch 'develop' into main
2 parents 0578949 + a156127 commit a6039d0

File tree

9 files changed

+50
-145
lines changed

9 files changed

+50
-145
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ fastlane/test_output
7070
.build-linux*
7171
Package.resolved
7272
dump*.json
73+
.swiftpm
7374

.travis.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ matrix:
77
include:
88
- os: Linux
99
dist: trusty
10-
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-4.2.3-release/ubuntu1404/swift-4.2.3-RELEASE/swift-4.2.3-RELEASE-ubuntu14.04.tar.gz"
10+
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.0.2-release/ubuntu1404/swift-5.0.2-RELEASE/swift-5.0.2-RELEASE-ubuntu14.04.tar.gz"
1111
sudo: required
1212
- os: Linux
1313
dist: trusty
14-
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.0-release/ubuntu1404/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu14.04.tar.gz"
14+
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.1.3-release/ubuntu1404/swift-5.1.3-RELEASE/swift-5.1.3-RELEASE-ubuntu14.04.tar.gz"
15+
sudo: required
16+
- os: Linux
17+
dist: xenial
18+
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.2-release/ubuntu1604/swift-5.2-RELEASE/swift-5.2-RELEASE-ubuntu16.04.tar.gz"
1519
sudo: required
1620
- os: osx
17-
osx_image: xcode10.1
18-
- os: osx
19-
osx_image: xcode10.2
21+
osx_image: xcode11
2022

2123

2224
before_install:

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:4.2
1+
// swift-tools-version:5.0
22

33
import PackageDescription
44

@@ -9,7 +9,7 @@ let package = Package(
99
],
1010
dependencies: [
1111
.package(url: "https://github.com/apple/swift-nio.git",
12-
from: "1.13.2")
12+
from: "2.18.0")
1313
],
1414
targets: [
1515
.target(name: "NIOIRC", dependencies: [ "NIO" ])

Package@swift-5.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

Sources/NIOIRC/IRCChannelHandler.swift

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the swift-nio-irc open source project
44
//
5-
// Copyright (c) 2018-2019 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
@@ -247,40 +247,6 @@ open class IRCChannelHandler : ChannelDuplexHandler {
247247
buffer.writeInteger(cCR)
248248
buffer.writeInteger(cLF)
249249
}
250-
251-
#if swift(>=5) // NIO 2 API - default
252-
#else // NIO 1 API shims
253-
open func channelActive(ctx context: ChannelHandlerContext) {
254-
channelActive(context: context)
255-
}
256-
open func channelInactive(ctx context: ChannelHandlerContext) {
257-
channelInactive(context: context)
258-
}
259-
open func channelRead(ctx context: ChannelHandlerContext, data: NIOAny) {
260-
channelRead(context: context, data: data)
261-
}
262-
open func channelRead(ctx context: ChannelHandlerContext,
263-
value: InboundOut)
264-
{
265-
channelRead(context: context, value: value)
266-
}
267-
open func errorCaught(ctx context: ChannelHandlerContext,
268-
error: Swift.Error)
269-
{
270-
errorCaught(context: context, error: error)
271-
}
272-
public func write(ctx context: ChannelHandlerContext, data: NIOAny,
273-
promise: EventLoopPromise<Void>?)
274-
{
275-
write(context: context, data: data, promise: promise)
276-
}
277-
public final func write(ctx context: ChannelHandlerContext,
278-
value: IRCMessage,
279-
promise: EventLoopPromise<Void>?)
280-
{
281-
write(context: context, value: value, promise: promise)
282-
}
283-
#endif
284250
}
285251

286252
extension ByteBuffer {
@@ -336,21 +302,3 @@ extension ByteBuffer {
336302
}
337303

338304
}
339-
340-
#if swift(>=5)
341-
// NIO 2
342-
#else
343-
fileprivate extension ByteBuffer {
344-
// NIO 2 API for NIO 1
345-
346-
@inline(__always) @discardableResult
347-
mutating func writeString(_ string: String) -> Int {
348-
return self.write(string: string) ?? -1337 // never fails
349-
}
350-
351-
@inline(__always) @discardableResult
352-
mutating func writeInteger<T: FixedWidthInteger>(_ integer: T) -> Int {
353-
return self.write(integer: integer)
354-
}
355-
}
356-
#endif // swift(<5)

Sources/NIOIRC/IRCMessageParser.swift

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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-

Sources/NIOIRC/Model/IRCCommand.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,13 @@ extension IRCCommand : CustomStringConvertible {
193193

194194
public var description : String {
195195
switch self {
196-
case .PING(let v), .PONG(let v):
197-
return "\(commandAsString) '\(v)'"
196+
case .PING(let server, let server2), .PONG(let server, let server2):
197+
if let server2 = server2 {
198+
return "\(commandAsString) '\(server)' '\(server2)'"
199+
}
200+
else {
201+
return "\(commandAsString) '\(server)'"
202+
}
198203

199204
case .QUIT(.some(let v)): return "QUIT '\(v)'"
200205
case .QUIT(.none): return "QUIT"

Sources/NIOIRC/Model/IRCUserID.swift

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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
@@ -26,22 +26,12 @@ public struct IRCUserID : Hashable, CustomStringConvertible {
2626
}
2727

2828
public init?(_ s: String) {
29-
#if swift(>=5)
30-
let atIdx = s.firstIndex(of: "@")
31-
#else
32-
let atIdx = s.index(of: "@")
33-
#endif
34-
if let atIdx = atIdx {
29+
if let atIdx = s.firstIndex(of: "@") {
3530
let hs = s.index(after: atIdx)
3631
self.host = String(s[hs..<s.endIndex])
3732

3833
let nickString : String
39-
#if swift(>=5)
40-
let exIdx = s.firstIndex(of: "!")
41-
#else
42-
let exIdx = s.index(of: "!")
43-
#endif
44-
if let exIdx = exIdx {
34+
if let exIdx = s.firstIndex(of: "!") {
4535
let hs = s.index(after: exIdx)
4636
self.user = String(s[hs..<atIdx])
4737

Sources/NIOIRC/Model/IRCUserMode.swift

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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
@@ -34,6 +34,9 @@ public struct IRCUserMode : OptionSet {
3434
public static let disableForwarding = IRCUserMode(rawValue: 1 << 10)
3535
public static let blockUnidentified = IRCUserMode(rawValue: 1 << 11)
3636
public static let connectedSecurely = IRCUserMode(rawValue: 1 << 12)
37+
38+
// UnrealIRCd https://www.unrealircd.org/docs/User_Modes "x"
39+
public static let hideHostname = IRCUserMode(rawValue: 1 << 13)
3740

3841
public var maskValue : UInt16 {
3942
return rawValue
@@ -43,17 +46,18 @@ public struct IRCUserMode : OptionSet {
4346
var mask : UInt16 = 0
4447
for c in string {
4548
switch c {
46-
case "w": mask += IRCUserMode.receivesWallOps.rawValue
47-
case "i": mask += IRCUserMode.invisible.rawValue
48-
case "a": mask += IRCUserMode.away.rawValue
49-
case "r": mask += IRCUserMode.restrictedConnection.rawValue
50-
case "o": mask += IRCUserMode.operator.rawValue
51-
case "O": mask += IRCUserMode.localOperator.rawValue
49+
case "w": mask += IRCUserMode.receivesWallOps .rawValue
50+
case "i": mask += IRCUserMode.invisible .rawValue
51+
case "a": mask += IRCUserMode.away .rawValue
52+
case "r": mask += IRCUserMode.restrictedConnection .rawValue
53+
case "o": mask += IRCUserMode.operator .rawValue
54+
case "O": mask += IRCUserMode.localOperator .rawValue
5255
case "s": mask += IRCUserMode.receivesServerNotices.rawValue
53-
case "g": mask += IRCUserMode.ignoreUnknown.rawValue
54-
case "Q": mask += IRCUserMode.disableForwarding.rawValue
55-
case "R": mask += IRCUserMode.blockUnidentified.rawValue
56-
case "Z": mask += IRCUserMode.connectedSecurely.rawValue
56+
case "g": mask += IRCUserMode.ignoreUnknown .rawValue
57+
case "Q": mask += IRCUserMode.disableForwarding .rawValue
58+
case "R": mask += IRCUserMode.blockUnidentified .rawValue
59+
case "Z": mask += IRCUserMode.connectedSecurely .rawValue
60+
case "x": mask += IRCUserMode.hideHostname .rawValue
5761
default: return nil
5862
}
5963
}
@@ -63,6 +67,7 @@ public struct IRCUserMode : OptionSet {
6367

6468
public var stringValue : String {
6569
var mode = ""
70+
mode.reserveCapacity(8)
6671
if contains(.receivesWallOps) { mode += "w" }
6772
if contains(.invisible) { mode += "i" }
6873
if contains(.away) { mode += "a" }
@@ -74,6 +79,7 @@ public struct IRCUserMode : OptionSet {
7479
if contains(.disableForwarding) { mode += "Q" }
7580
if contains(.blockUnidentified) { mode += "R" }
7681
if contains(.connectedSecurely) { mode += "Z" }
82+
if contains(.hideHostname) { mode += "x" }
7783
return mode
7884
}
7985
}

0 commit comments

Comments
 (0)