merge master

This commit is contained in:
Erik 2015-03-18 13:11:02 -04:00
commit 07f2d7465a
4 changed files with 45 additions and 108 deletions

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "Socket.IO-Client-Swift" s.name = "Socket.IO-Client-Swift"
s.version = "1.2.1" s.version = "1.2.2"
s.summary = "Socket.IO-client for Swift" s.summary = "Socket.IO-client for Swift"
s.description = <<-DESC s.description = <<-DESC
Socket.IO-client for Swift. Socket.IO-client for Swift.
@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.author = { "Erik" => "nuclear.ace@gmail.com" } s.author = { "Erik" => "nuclear.ace@gmail.com" }
s.ios.deployment_target = '8.0' s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10' s.osx.deployment_target = '10.10'
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v1.2.1' } s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v1.2.2' }
s.source_files = "SwiftIO/**/*.swift" s.source_files = "SwiftIO/**/*.swift"
s.requires_arc = true s.requires_arc = true
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files # s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files

View File

@ -407,7 +407,9 @@ public class SocketEngine: NSObject, WebSocketDelegate {
private func parseEngineMessage(var message:String) { private func parseEngineMessage(var message:String) {
// NSLog("Engine got message: \(message)") // NSLog("Engine got message: \(message)")
if self.polling {
fixDoubleUTF8(&message) fixDoubleUTF8(&message)
}
// We should upgrade // We should upgrade
if message == "3probe" { if message == "3probe" {
@ -501,9 +503,11 @@ public class SocketEngine: NSObject, WebSocketDelegate {
} }
} }
private func sendPollMessage(msg:String, withType type:PacketType, private func sendPollMessage(var msg:String, withType type:PacketType,
datas:[NSData]? = nil) { datas:[NSData]? = nil) {
// println("Sending poll: \(msg) as type: \(type.rawValue)") // println("Sending poll: \(msg) as type: \(type.rawValue)")
doubleEncodeUTF8(&msg)
let strMsg = "\(type.rawValue)\(msg)" let strMsg = "\(type.rawValue)\(msg)"
self.postWait.append(strMsg) self.postWait.append(strMsg)

View File

@ -21,84 +21,17 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
// //
// Adapted from: https://github.com/durbrow/fix-double-utf8.swift
import Foundation import Foundation
var memoizer = [String: UnicodeScalar]()
private func lookup(base:UnicodeScalar, combi:UnicodeScalar) -> UnicodeScalar {
let combined = "\(base)\(combi)"
if let y = memoizer[combined] {
return y
}
for i in 0x80...0xFF {
let ch = UnicodeScalar(i)
if String(ch) == combined {
memoizer[combined] = ch
return ch
}
}
let ch = UnicodeScalar(0xFFFD) // Unicode replacement character <EFBFBD>
memoizer[combined] = ch
return ch
}
func fixDoubleUTF8(inout name:String) { func fixDoubleUTF8(inout name:String) {
var isASCII = true let utf8 = name.dataUsingEncoding(NSISOLatin1StringEncoding, allowLossyConversion: false)!
var y = [UInt8]() let latin1 = NSString(data: utf8, encoding: NSUTF8StringEncoding)!
name = latin1 as String
for ch in name.unicodeScalars { }
if ch.value < 0x80 {
y.append(UInt8(ch.value)) func doubleEncodeUTF8(inout str:String) {
continue let latin1 = str.dataUsingEncoding(NSUTF8StringEncoding)!
} let utf8 = NSString(data: latin1, encoding: NSISOLatin1StringEncoding)!
isASCII = false str = utf8 as String
if ch.value < 0x100 {
y.append(UInt8(ch.value))
continue
}
// might be a combining character that when combined with the
// preceeding character maps to a codepoint in the UTF8 range
if y.count == 0 {
return
}
let last = y.removeLast()
let repl = lookup(UnicodeScalar(last), ch)
// the replacement needs to be in the UTF8 range
if repl.value >= 0x100 {
return
}
y.append(UInt8(repl.value))
}
if isASCII {
return
}
y.append(0) // null terminator
return y.withUnsafeBufferPointer {
let cstr = UnsafePointer<CChar>($0.baseAddress) // typecase from uint8_t * to char *
let rslt = String.fromCStringRepairingIllFormedUTF8(cstr) // -> (String, Bool)
if let str = rslt.0 {
if !rslt.hadError {
name = str
} else {
println("error")
}
} else {
println("error")
}
return
}
} }

View File

@ -43,7 +43,7 @@ public class SwiftRegex: NSObject, BooleanType {
} }
final var targetRange: NSRange { final var targetRange: NSRange {
return NSRange(location: 0,length: count(target)) return NSRange(location: 0,length: target.utf16Count)
} }
final func substring(range: NSRange) -> String? { final func substring(range: NSRange) -> String? {