File tree Expand file tree Collapse file tree 1 file changed +4
-8
lines changed Expand file tree Collapse file tree 1 file changed +4
-8
lines changed Original file line number Diff line number Diff line change 6
6
//
7
7
//
8
8
9
- import Foundation
10
-
11
9
struct SocketStringReader {
12
10
let message : String
13
11
var currentIndex : String . Index
@@ -37,19 +35,17 @@ struct SocketStringReader {
37
35
38
36
mutating func readUntilStringOccurence( string: String ) -> String {
39
37
let range = Range < String . Index > ( start: currentIndex, end: message. endIndex)
40
- let subString = message. substringWithRange ( range) as NSString
41
- let foundRange = subString. rangeOfString ( string)
42
-
43
- if foundRange. length == 0 {
38
+ let subString = message. substringWithRange ( range)
39
+ guard let foundRange = subString. rangeOfString ( string) else {
44
40
let restOfString = message [ currentIndex... message. endIndex. predecessor ( ) ]
45
41
currentIndex = message. endIndex
46
42
47
43
return restOfString
48
44
}
49
45
50
- advanceIndexBy ( foundRange. location + 1 )
46
+ advanceIndexBy ( message . startIndex . distanceTo ( foundRange. startIndex ) + 1 )
51
47
52
- return subString. substringToIndex ( foundRange. location )
48
+ return subString. substringToIndex ( foundRange. startIndex )
53
49
}
54
50
55
51
mutating func readUntilEnd( ) -> String {
You can’t perform that action at this time.
0 commit comments