瀏覽代碼

Ready for swift-DEVELOPMENT-SNAPSHOT-2016-04-12-a-osx.pkg.

Damian Kołakowski 10 年之前
父節點
當前提交
f6b94a2e1b

+ 2 - 2
Sources/DemoServer.swift

@@ -7,7 +7,7 @@
 
 import Foundation
 
-public func demoServer(publicDir: String) -> HttpServer {
+public func demoServer(_ publicDir: String) -> HttpServer {
     
     print(publicDir)
     
@@ -88,7 +88,7 @@ public func demoServer(publicDir: String) -> HttpServer {
     }
     
     server["/json"] = { r in
-        let jsonObject: NSDictionary = [NSString(string: "foo"): NSNumber(int: 3), NSString(string: "bar"): NSString(string: "baz")] 
+        let jsonObject: NSDictionary = [NSString(string: "foo"): NSNumber(value: 3), NSString(string: "bar"): NSString(string: "baz")]
         return .OK(.Json(jsonObject))
     }
     

+ 8 - 8
Sources/File.swift

@@ -22,19 +22,19 @@ public enum FileError: ErrorProtocol {
 
 public class File {
     
-    public static func openNewForWriting(path: String) throws -> File {
+    public static func openNewForWriting(_ path: String) throws -> File {
         return try openFileForMode(path, "wb")
     }
     
-    public static func openForReading(path: String) throws -> File {
+    public static func openForReading(_ path: String) throws -> File {
         return try openFileForMode(path, "rb")
     }
     
-    public static func openForWritingAndReading(path: String) throws -> File {
+    public static func openForWritingAndReading(_ path: String) throws -> File {
         return try openFileForMode(path, "r+b")
     }
     
-    public static func openFileForMode(path: String, _ mode: String) throws -> File {
+    public static func openFileForMode(_ path: String, _ mode: String) throws -> File {
         let file = fopen(path.withCString({ $0 }), mode.withCString({ $0 }))
         guard file != nil else {
             throw FileError.OpenFailed(descriptionOfLastError())
@@ -42,7 +42,7 @@ public class File {
         return File(file)
     }
     
-    public static func isDirectory(path: String) throws -> Bool {
+    public static func isDirectory(_ path: String) throws -> Bool {
         var s = stat()
         guard stat(path, &s) == 0 else {
             throw FileError.IsDirectoryFailed(descriptionOfLastError())
@@ -68,7 +68,7 @@ public class File {
         fclose(pointer)
     }
     
-    public func read(data: inout [UInt8]) throws -> Int {
+    public func read(_ data: inout [UInt8]) throws -> Int {
         if data.count <= 0 {
             return data.count
         }
@@ -85,7 +85,7 @@ public class File {
         throw FileError.ReadFailed("Unknown file read error occured.")
     }
 
-    public func write(data: [UInt8]) throws -> Void {
+    public func write(_ data: [UInt8]) throws -> Void {
         if data.count <= 0 {
             return
         }
@@ -121,7 +121,7 @@ extension File {
         return try withFileOpenedForMode(path, mode: "r+b", f)
     }
     
-    public static func withFileOpenedForMode<Result>(path: String, mode: String, _ f: File throws -> Result) throws -> Result {
+    public static func withFileOpenedForMode<Result>(_ path: String, mode: String, _ f: File throws -> Result) throws -> Result {
         let file = try File.openFileForMode(path, mode)
         defer {
             file.close()

+ 3 - 3
Sources/HttpHandlers+Files.swift

@@ -9,7 +9,7 @@ import Foundation
 
 extension HttpHandlers {
     
-    public class func shareFilesFromDirectory(directoryPath: String) -> (HttpRequest -> HttpResponse) {
+    public class func shareFilesFromDirectory(_ directoryPath: String) -> (HttpRequest -> HttpResponse) {
         return { r in
             guard let fileRelativePath = r.params.first else {
                 return .NotFound
@@ -30,7 +30,7 @@ extension HttpHandlers {
     
     private static let rangePrefix = "bytes="
     
-    public class func directory(dir: String) -> (HttpRequest -> HttpResponse) {
+    public class func directory(_ dir: String) -> (HttpRequest -> HttpResponse) {
         return { r in
             
             guard let localPath = r.params.first else {
@@ -92,7 +92,7 @@ extension HttpHandlers {
         }
     }
     
-    public class func directoryBrowser(dir: String) -> (HttpRequest -> HttpResponse) {
+    public class func directoryBrowser(_ dir: String) -> (HttpRequest -> HttpResponse) {
         return { r in
             guard let (_, value) = r.params.first else {
                 return HttpResponse.NotFound

+ 6 - 6
Sources/HttpHandlers+WebSockets.swift

@@ -10,7 +10,7 @@ import Foundation
 extension HttpHandlers {
     
     public class func websocket(
-            text: ((WebSocketSession, String) -> Void)?,
+          _ text: ((WebSocketSession, String) -> Void)?,
         _ binary: ((WebSocketSession, [UInt8]) -> Void)?) -> (HttpRequest -> HttpResponse) {
         return { r in
             guard r.hasTokenForHeader("upgrade", token: "websocket") else {
@@ -61,19 +61,19 @@ extension HttpHandlers {
             self.socket = socket
         }
         
-        public func writeText(text: String) -> Void {
+        public func writeText(_ text: String) -> Void {
             self.writeFrame(ArraySlice(text.utf8), OpCode.Text)
         }
     
-        public func writeBinary(binary: [UInt8]) -> Void {
+        public func writeBinary(_ binary: [UInt8]) -> Void {
             self.writeBinary(ArraySlice(binary))
         }
         
-        public func writeBinary(binary: ArraySlice<UInt8>) -> Void {
+        public func writeBinary(_ binary: ArraySlice<UInt8>) -> Void {
             self.writeFrame(binary, OpCode.Binary)
         }
         
-        private func writeFrame(data: ArraySlice<UInt8>, _ op: OpCode, _ fin: Bool = true) {
+        private func writeFrame(_ data: ArraySlice<UInt8>, _ op: OpCode, _ fin: Bool = true) {
             let finAndOpCode = UInt8(fin ? 0x80 : 0x00) | op.rawValue
             let maskAndLngth = encodeLengthAndMaskFlag(UInt64(data.count), false)
             do {
@@ -85,7 +85,7 @@ extension HttpHandlers {
             }
         }
         
-        private func encodeLengthAndMaskFlag(len: UInt64, _ masked: Bool) -> [UInt8] {
+        private func encodeLengthAndMaskFlag(_ len: UInt64, _ masked: Bool) -> [UInt8] {
             let encodedLngth = UInt8(masked ? 0x80 : 0x00)
             var encodedBytes = [UInt8]()
             switch len {

+ 5 - 5
Sources/HttpParser.swift

@@ -19,7 +19,7 @@ public class HttpParser {
     
     public init() { }
     
-    public func readHttpRequest(socket: Socket) throws -> HttpRequest {
+    public func readHttpRequest(_ socket: Socket) throws -> HttpRequest {
         let statusLine = try socket.readLine()
         let statusLineTokens = statusLine.split(" ")
         if statusLineTokens.count < 3 {
@@ -36,7 +36,7 @@ public class HttpParser {
         return request
     }
     
-    private func extractQueryParams(url: String) -> [(String, String)] {
+    private func extractQueryParams(_ url: String) -> [(String, String)] {
         guard let query = url.split("?").last else {
             return []
         }
@@ -49,13 +49,13 @@ public class HttpParser {
         }
     }
     
-    private func readBody(socket: Socket, size: Int) throws -> [UInt8] {
+    private func readBody(_ socket: Socket, size: Int) throws -> [UInt8] {
         var body = [UInt8]()
         for _ in 0..<size { body.append(try socket.read()) }
         return body
     }
     
-    private func readHeaders(socket: Socket) throws -> [String: String] {
+    private func readHeaders(_ socket: Socket) throws -> [String: String] {
         var headers = [String: String]()
         repeat {
             let headerLine = try socket.readLine()
@@ -69,7 +69,7 @@ public class HttpParser {
         } while true
     }
     
-    func supportsKeepAlive(headers: [String: String]) -> Bool {
+    func supportsKeepAlive(_ headers: [String: String]) -> Bool {
         if let value = headers["connection"] {
             return "keep-alive" == value.trim()
         }

+ 6 - 6
Sources/HttpRequest.swift

@@ -17,7 +17,7 @@ public class HttpRequest {
     public var address: String? = ""
     public var params: [String: String] = [:]
     
-    public func hasTokenForHeader(headerName: String, token: String) -> Bool {
+    public func hasTokenForHeader(_ headerName: String, token: String) -> Bool {
         guard let headerValue = headers[headerName] else {
             return false
         }
@@ -55,7 +55,7 @@ public class HttpRequest {
             return valueFor("content-disposition", parameter: "filename")?.unquote()
         }
         
-        private func valueFor(headerName: String, parameter: String) -> String? {
+        private func valueFor(_ headerName: String, parameter: String) -> String? {
             return headers.reduce([String]()) { (combined, header: (key: String, value: String)) -> [String] in
                 guard header.key == headerName else {
                     return combined
@@ -93,7 +93,7 @@ public class HttpRequest {
         return []
     }
     
-    private func parseMultiPartFormData(data: [UInt8], boundary: String) -> [MultiPart] {
+    private func parseMultiPartFormData(_ data: [UInt8], boundary: String) -> [MultiPart] {
         var generator = data.makeIterator()
         var result = [MultiPart]()
         while let part = nextMultiPart(&generator, boundary: boundary, isFirst: result.isEmpty) {
@@ -102,7 +102,7 @@ public class HttpRequest {
         return result
     }
     
-    private func nextMultiPart(generator: inout IndexingIterator<[UInt8]>, boundary: String, isFirst: Bool) -> MultiPart? {
+    private func nextMultiPart(_ generator: inout IndexingIterator<[UInt8]>, boundary: String, isFirst: Bool) -> MultiPart? {
         if isFirst {
             guard nextMultiPartLine(&generator) == boundary else {
                 return nil
@@ -123,7 +123,7 @@ public class HttpRequest {
         return MultiPart(headers: headers, body: body)
     }
     
-    private func nextMultiPartLine(generator: inout IndexingIterator<[UInt8]>) -> String? {
+    private func nextMultiPartLine(_ generator: inout IndexingIterator<[UInt8]>) -> String? {
         var result = String()
         while let value = generator.next() {
             if value > HttpRequest.CR {
@@ -139,7 +139,7 @@ public class HttpRequest {
     static let CR = UInt8(13)
     static let NL = UInt8(10)
     
-    private func nextMultiPartBody(generator: inout IndexingIterator<[UInt8]>, boundary: String) -> [UInt8]? {
+    private func nextMultiPartBody(_ generator: inout IndexingIterator<[UInt8]>, boundary: String) -> [UInt8]? {
         var body = [UInt8]()
         let boundaryArray = [UInt8](boundary.utf8)
         var matchOffset = 0;

+ 2 - 2
Sources/HttpResponse.swift

@@ -13,8 +13,8 @@ public enum SerializationError: ErrorProtocol {
 }
 
 public protocol HttpResponseBodyWriter {
-    func write(data: [UInt8])
-    func write(data: ArraySlice<UInt8>)
+    func write(_ data: [UInt8])
+    func write(_ data: ArraySlice<UInt8>)
 }
 
 public enum HttpResponseBody {

+ 6 - 6
Sources/HttpRouter.swift

@@ -26,7 +26,7 @@ public class HttpRouter {
         return routes
     }
     
-    private func routesForNode(node: Node, prefix: String = "") -> [String] {
+    private func routesForNode(_ node: Node, prefix: String = "") -> [String] {
         var result = [String]()
         if let _ = node.handler {
             result.append(prefix)
@@ -37,7 +37,7 @@ public class HttpRouter {
         return result
     }
     
-    public func register(method: String?, path: String, handler: (HttpRequest -> HttpResponse)?) {
+    public func register(_ method: String?, path: String, handler: (HttpRequest -> HttpResponse)?) {
         var pathSegments = stripQuery(path).split("/")
         if let method = method {
             pathSegments.insert(method, at: 0)
@@ -48,7 +48,7 @@ public class HttpRouter {
         inflate(&rootNode, generator: &pathSegmentsGenerator).handler = handler
     }
     
-    public func route(method: String?, path: String) -> ([String: String], HttpRequest -> HttpResponse)? {
+    public func route(_ method: String?, path: String) -> ([String: String], HttpRequest -> HttpResponse)? {
         if let method = method {
             let pathSegments = (method + "/" + stripQuery(path)).split("/")
             var pathSegmentsGenerator = pathSegments.makeIterator()
@@ -66,7 +66,7 @@ public class HttpRouter {
         return nil
     }
     
-    private func inflate(node: inout Node, generator: inout IndexingIterator<[String]>) -> Node {
+    private func inflate(_ node: inout Node, generator: inout IndexingIterator<[String]>) -> Node {
         if let pathSegment = generator.next() {
             if let _ = node.nodes[pathSegment] {
                 return inflate(&node.nodes[pathSegment]!, generator: &generator)
@@ -78,7 +78,7 @@ public class HttpRouter {
         return node
     }
     
-    private func findHandler(node: inout Node, params: inout [String: String], generator: inout IndexingIterator<[String]>) -> (HttpRequest -> HttpResponse)? {
+    private func findHandler(_ node: inout Node, params: inout [String: String], generator: inout IndexingIterator<[String]>) -> (HttpRequest -> HttpResponse)? {
         guard let pathToken = generator.next() else {
             return node.handler
         }
@@ -115,7 +115,7 @@ public class HttpRouter {
         return nil
     }
     
-    private func stripQuery(path: String) -> String {
+    private func stripQuery(_ path: String) -> String {
         if let path = path.split("?").first {
             return path
         }

+ 7 - 7
Sources/HttpServer.swift

@@ -24,27 +24,27 @@ public class HttpServer: HttpServerIO {
     
     public var DELETE, UPDATE, HEAD, POST, GET, PUT : MethodRoute
     
-    public func get(path: String, _ handler: (HttpRequest -> HttpResponse)) {
+    public func get(_ path: String, _ handler: (HttpRequest -> HttpResponse)) {
         router.register("GET", path: path, handler: handler)
     }
     
-    public func post(path: String, _ handler: (HttpRequest -> HttpResponse)) {
+    public func post(_ path: String, _ handler: (HttpRequest -> HttpResponse)) {
         router.register("POST", path: path, handler: handler)
     }
     
-    public func put(path: String, _ handler: (HttpRequest -> HttpResponse)) {
+    public func put(_ path: String, _ handler: (HttpRequest -> HttpResponse)) {
         router.register("PUT", path: path, handler: handler)
     }
     
-    public func head(path: String, _ handler: (HttpRequest -> HttpResponse)) {
+    public func head(_ path: String, _ handler: (HttpRequest -> HttpResponse)) {
         router.register("HEAD", path: path, handler: handler)
     }
     
-    public func delete(path: String, _ handler: (HttpRequest -> HttpResponse)) {
+    public func delete(_ path: String, _ handler: (HttpRequest -> HttpResponse)) {
         router.register("DELETE", path: path, handler: handler)
     }
     
-    public func update(path: String, _ handler: (HttpRequest -> HttpResponse)) {
+    public func update(_ path: String, _ handler: (HttpRequest -> HttpResponse)) {
         router.register("UPDATE", path: path, handler: handler)
     }
 
@@ -59,7 +59,7 @@ public class HttpServer: HttpServerIO {
         return router.routes();
     }
 
-    override public func dispatch(method: String, path: String) -> ([String:String], HttpRequest -> HttpResponse) {
+    override public func dispatch(_ method: String, path: String) -> ([String:String], HttpRequest -> HttpResponse) {
         if let result = router.route(method, path: path) {
             return result
         }

+ 8 - 8
Sources/HttpServerIO.swift

@@ -22,7 +22,7 @@ public class HttpServerIO {
     
     public var middleware = [MiddlewareCallback]()
     
-    public func start(listenPort: in_port_t = 8080) throws {
+    public func start(_ listenPort: in_port_t = 8080) throws {
         stop()
         listenSocket = try Socket.tcpSocketForListen(listenPort)
         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) {
@@ -51,11 +51,11 @@ public class HttpServerIO {
         }
     }
     
-    public func dispatch(method: String, path: String) -> ([String: String], HttpRequest -> HttpResponse) {
+    public func dispatch(_ method: String, path: String) -> ([String: String], HttpRequest -> HttpResponse) {
         return ([:], { _ in HttpResponse.NotFound })
     }
     
-    private func handleConnection(socket: Socket) {
+    private func handleConnection(_ socket: Socket) {
         let address = try? socket.peername()
         let parser = HttpParser()
         while let request = try? parser.readHttpRequest(socket) {
@@ -82,7 +82,7 @@ public class HttpServerIO {
         socket.release()
     }
 
-    private func askMiddlewareForResponse(request: HttpRequest) -> HttpResponse? {
+    private func askMiddlewareForResponse(_ request: HttpRequest) -> HttpResponse? {
         for layer in middleware {
             if let response = layer(request) {
                 return response
@@ -91,7 +91,7 @@ public class HttpServerIO {
         return nil
     }
     
-    private func lock(handle: NSLock, closure: () -> ()) {
+    private func lock(_ handle: NSLock, closure: () -> ()) {
         handle.lock()
         closure()
         handle.unlock();
@@ -99,10 +99,10 @@ public class HttpServerIO {
     
     private struct InnerWriteContext: HttpResponseBodyWriter {
         let socket: Socket
-        func write(data: [UInt8]) {
+        func write(_ data: [UInt8]) {
             write(ArraySlice(data))
         }
-        func write(data: ArraySlice<UInt8>) {
+        func write(_ data: ArraySlice<UInt8>) {
             do {
                 try socket.writeUInt8(data)
             } catch {
@@ -111,7 +111,7 @@ public class HttpServerIO {
         }
     }
     
-    private func respond(socket: Socket, response: HttpResponse, keepAlive: Bool) throws -> Bool {
+    private func respond(_ socket: Socket, response: HttpResponse, keepAlive: Bool) throws -> Bool {
         try socket.writeUTF8("HTTP/1.1 \(response.statusCode()) \(response.reasonPhrase())\r\n")
         
         let content = response.content()

+ 1 - 1
Sources/Process.swift

@@ -16,7 +16,7 @@ public class Process {
     private static var signalsWatchers = [SignalCallback]()
     private static var signalsObserved = false
     
-    public static func watchSignals(callback: SignalCallback) {
+    public static func watchSignals(_ callback: SignalCallback) {
         if !signalsObserved {
             [SIGTERM, SIGHUP, SIGSTOP, SIGINFO, SIGINT].forEach { item in
                 signal(item) {

+ 19 - 10
Sources/SQLite.swift

@@ -17,9 +17,12 @@ public class SQLite {
     
     private let databaseConnection: OpaquePointer
     
-    public static func open(path: String) throws -> SQLite {
-        var databaseConnection: OpaquePointer = nil
-        let openResult = path.withCString { sqlite3_open($0, &databaseConnection) }
+    public static func open(_ path: String) throws -> SQLite {
+        var databaseConnectionPointer: OpaquePointer? = nil
+        let openResult = path.withCString { sqlite3_open($0, &databaseConnectionPointer) }
+        guard let databaseConnection = databaseConnectionPointer else {
+            throw SQLiteError.ExecFailed("Invalid pointer.")
+        }
         guard openResult == SQLITE_OK else {
             throw SQLiteError.OpenFailed(String(cString: sqlite3_errmsg(databaseConnection)))
         }
@@ -32,16 +35,19 @@ public class SQLite {
     
     private struct ExecCContext { var callback: ([String: String] -> Void)? }
 
-    public func exec(sql: String) throws {
+    public func exec(_ sql: String) throws {
         try exec(sql, nil)
     }
     
-    public func exec(sql: String, _ params: [String?]? = nil, _ step: ([String: String?] -> Void)? = nil) throws {
-        var statement: OpaquePointer = nil
-        let prepareResult = sql.withCString { sqlite3_prepare_v2(databaseConnection, $0, Int32(sql.utf8.count), &statement, nil) }
+    public func exec(_ sql: String, _ params: [String?]? = nil, _ step: ([String: String?] -> Void)? = nil) throws {
+        var statementPointer: OpaquePointer? = nil
+        let prepareResult = sql.withCString { sqlite3_prepare_v2(databaseConnection, $0, Int32(sql.utf8.count), &statementPointer, nil) }
         guard prepareResult == SQLITE_OK else {
             throw SQLiteError.ExecFailed(String(cString: sqlite3_errmsg(databaseConnection)))
         }
+        guard let statement = statementPointer else {
+            throw SQLiteError.ExecFailed("Invalid pointer.")
+        }
         for (index, value) in (params ?? [String?]()).enumerated() {
             let bindResult = value?.withCString({ sqlite3_bind_text(statement, index + 1, $0, -1 /* take zero terminator. */) { _ in } })
                     ?? sqlite3_bind_null(statement, index + 1)
@@ -75,13 +81,16 @@ public class SQLite {
     }
     
     
-    public func enumerate(sql: String) throws -> StatmentSequence {
-        var statement: OpaquePointer = nil
+    public func enumerate(_ sql: String) throws -> StatmentSequence {
+        var statement: OpaquePointer? = nil
         let prepareResult = sql.withCString { sqlite3_prepare_v2(databaseConnection, $0, Int32(sql.utf8.count), &statement, nil) }
         guard prepareResult == SQLITE_OK else {
             throw SQLiteError.ExecFailed(String(cString: sqlite3_errmsg(databaseConnection)))
         }
-        return StatmentSequence(statement: statement)
+        guard let readyStatement = statement else {
+            throw SQLiteError.ExecFailed("Invalid pointer.")
+        }
+        return StatmentSequence(statement: readyStatement)
     }
     
     public struct StatmentGenerator: IteratorProtocol {

+ 13 - 10
Sources/Socket.swift

@@ -28,7 +28,7 @@ public enum SocketError: ErrorProtocol {
 
 public class Socket: Hashable, Equatable {
     
-    public class func tcpSocketForListen(port: in_port_t, maxPendingConnection: Int32 = SOMAXCONN) throws -> Socket {
+    public class func tcpSocketForListen(_ port: in_port_t, maxPendingConnection: Int32 = SOMAXCONN) throws -> Socket {
         
         #if os(Linux)
             let socketFileDescriptor = socket(AF_INET, Int32(SOCK_STREAM.rawValue), 0)
@@ -107,22 +107,25 @@ public class Socket: Hashable, Equatable {
         return Socket(socketFileDescriptor: clientSocket)
     }
     
-    public func writeUTF8(string: String) throws {
+    public func writeUTF8(_ string: String) throws {
         try writeUInt8(ArraySlice(string.utf8))
     }
     
-    public func writeUInt8(data: [UInt8]) throws {
+    public func writeUInt8(_ data: [UInt8]) throws {
         try writeUInt8(ArraySlice(data))
     }
     
-    public func writeUInt8(data: ArraySlice<UInt8>) throws {
+    public func writeUInt8(_ data: ArraySlice<UInt8>) throws {
         try data.withUnsafeBufferPointer {
+            guard let baseAddress = $0.baseAddress else {
+                throw SocketError.WriteFailed("The base address of data slice is nil.")
+            }
             var sent = 0
             while sent < data.count {
                 #if os(Linux)
-                    let s = send(self.socketFileDescriptor, $0.baseAddress + sent, Int(data.count - sent), Int32(MSG_NOSIGNAL))
+                    let s = send(self.socketFileDescriptor, baseAddress + sent, Int(data.count - sent), Int32(MSG_NOSIGNAL))
                 #else
-                    let s = write(self.socketFileDescriptor, $0.baseAddress + sent, Int(data.count - sent))
+                    let s = write(self.socketFileDescriptor, baseAddress + sent, Int(data.count - sent))
                 #endif
                 if s <= 0 {
                     throw SocketError.WriteFailed(Socket.descriptionOfLastError())
@@ -170,7 +173,7 @@ public class Socket: Hashable, Equatable {
         return String(cString: UnsafePointer(strerror(errno))) ?? "Error: \(errno)"
     }
     
-    private class func setNoSigPipe(socket: Int32) {
+    private class func setNoSigPipe(_ socket: Int32) {
         #if os(Linux)
             // There is no SO_NOSIGPIPE in Linux (nor some other systems). You can instead use the MSG_NOSIGNAL flag when calling send(),
             // or use signal(SIGPIPE, SIG_IGN) to make your entire application ignore SIGPIPE.
@@ -181,7 +184,7 @@ public class Socket: Hashable, Equatable {
         #endif
     }
     
-    private class func shutdwn(socket: Int32) {
+    private class func shutdwn(_ socket: Int32) {
         #if os(Linux)
             shutdown(socket, Int32(SHUT_RDWR))
         #else
@@ -189,7 +192,7 @@ public class Socket: Hashable, Equatable {
         #endif
     }
     
-    private class func release(socket: Int32) {
+    private class func release(_ socket: Int32) {
         #if os(Linux)
             shutdown(socket, Int32(SHUT_RDWR))
         #else
@@ -198,7 +201,7 @@ public class Socket: Hashable, Equatable {
         close(socket)
     }
     
-    private class func htonsPort(port: in_port_t) -> in_port_t {
+    private class func htonsPort(_ port: in_port_t) -> in_port_t {
         #if os(Linux)
             return htons(port)
         #else

+ 1 - 1
Sources/String+BASE64.swift

@@ -16,7 +16,7 @@ extension String {
     
     private static let CODES = [UInt8]("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".utf8)
     
-    public static func toBase64(data: [UInt8]) -> String {
+    public static func toBase64(_ data: [UInt8]) -> String {
         
         // Based on: https://en.wikipedia.org/wiki/Base64#Sample_Implementation_in_Java
         

+ 4 - 4
Sources/String+Misc.swift

@@ -13,15 +13,15 @@
 
 extension String {
 
-    public func split(separator: Character) -> [String] {
+    public func split(_ separator: Character) -> [String] {
         return self.characters.split { $0 == separator }.map(String.init)
     }
     
-    public func split(maxSplit: Int = Int.max, separator: Character) -> [String] {
+    public func split(_ maxSplit: Int = Int.max, separator: Character) -> [String] {
         return self.characters.split(maxSplits: maxSplit, omittingEmptySubsequences: true) { $0 == separator }.map(String.init)
     }
     
-    public func replace(old: Character, _ new: Character) -> String {
+    public func replace(_ old: Character, _ new: Character) -> String {
         var buffer = [Character]()
         self.characters.forEach { buffer.append($0 == old ? new : $0) }
         return String(buffer)
@@ -44,7 +44,7 @@ extension String {
         return String(scalars)
     }
     
-    public static func fromUInt8(array: [UInt8]) -> String {
+    public static func fromUInt8(_ array: [UInt8]) -> String {
         // Apple changes the definition of String(data: .... ) every release so let's stay with 'fromUInt8(...)' wrapper.
         return array.reduce("", combine: { $0.0 + String(UnicodeScalar($0.1)) })
     }

+ 2 - 2
Sources/String+SHA1.swift

@@ -60,7 +60,7 @@ extension String {
             // break chunk into sixteen 32-bit big-endian words w[i], 0 ≤ i ≤ 15
             
             for i in 0...15 {
-                let value = chunk.withUnsafeBufferPointer({ UnsafePointer<UInt32>($0.baseAddress + (i*4)).pointee})
+                let value = chunk.withUnsafeBufferPointer({ UnsafePointer<UInt32>($0.baseAddress! + (i*4)).pointee})
                 words.append(value.bigEndian)
             }
             
@@ -133,7 +133,7 @@ extension String {
         return result;
     }
     
-    func rotateLeft(v: UInt32, _ n: UInt32) -> UInt32 {
+    func rotateLeft(_ v: UInt32, _ n: UInt32) -> UInt32 {
         return ((v << n) & 0xFFFFFFFF) | (v >> (32 - n))
     }
 }