@@ -12,6 +12,8 @@ import MapKit
1212extension NSString {
1313 /**
1414 Convenience so `isEmpty` can be performed on an `NSString` instance just as if it were a `String`
15+
16+ - returns: `true` if the string is empty, `false` if not
1517 */
1618 var isEmpty : Bool {
1719 get { return self . length == 0 || self . isEqualToString ( " " ) }
@@ -21,7 +23,7 @@ extension String {
2123 /**
2224 Strip all leading and trailing whitespace from a given `String` instance.
2325
24- : returns: a newly stripped string instance.
26+ - returns: a newly stripped string instance.
2527 */
2628 func stringByStrippingLeadingAndTrailingWhiteSpace( ) -> String {
2729 let mutable = self . mutableCopy ( ) as! NSMutableString
@@ -35,12 +37,12 @@ class Parser {
3537 /**
3638 Parse a given string of Lat/Lng values to return a collection of `CLLocationCoordinate2D` arrays.
3739
38- : note: The preferred way/format of the input string is `Well-Known Text` as the parser supports that for multipolygons and such
40+ - note: The preferred way/format of the input string is `Well-Known Text` as the parser supports that for multipolygons and such
3941
40- :param: input String to parse
41- :param: longitudeFirst Only used if it is determined to not be `Well-Known Text` format.
42+ - parameter input: String to parse
43+ - parameter longitudeFirst: Only used if it is determined to not be `Well-Known Text` format.
4244
43- : returns: An array of `CLLocationCoordinate2D` arrays representing the parsed areas/lines
45+ - returns: An array of `CLLocationCoordinate2D` arrays representing the parsed areas/lines
4446 */
4547 class func parseString( input: NSString , longitudeFirst: Bool ) -> [ [ CLLocationCoordinate2D ] ] {
4648 return Parser ( longitudeFirst: longitudeFirst) . parseInput ( input)
@@ -60,23 +62,23 @@ class Parser {
6062 /**
6163 Parse input string into a collection of `CLLocationCoordinate2D` arrays that can be drawn on a map
6264
63- : note: This method supports (and really works best with/prefers) `Well-Known Text` format
65+ - note: This method supports (and really works best with/prefers) `Well-Known Text` format
6466
65- :param: input `NSString` to parse
67+ - parameter input: `NSString` to parse
6668
67- : returns: Collection of `CLLocationCoordinate2D` arrays
69+ - returns: Collection of `CLLocationCoordinate2D` arrays
6870 */
6971 internal func parseInput( input: NSString ) -> [ [ CLLocationCoordinate2D ] ] {
7072 var array = [ [ NSString] ] ( )
7173
72- let line = input as! String
74+ let line = input as String
7375
7476 if isProbablyGeoString ( line) {
7577 self . longitudeFirst = true
7678 var items = [ NSString] ( )
7779
7880 if isMultiItem ( line) {
79- items = stripExtraneousCharacters ( line) . componentsSeparatedByString ( " ), " ) as! [ NSString ]
81+ items = stripExtraneousCharacters ( line) . componentsSeparatedByString ( " ), " )
8082 } else {
8183 items = [ stripExtraneousCharacters ( line) ]
8284 }
@@ -92,18 +94,19 @@ class Parser {
9294 /**
9395 Convert an array of strings into tuple pairs.
9496
95- : note: the number of values passed in should probably be even, since it creates pairs.
97+ - note: the number of values passed in should probably be even, since it creates pairs.
9698
97- :param: array of `[NSString]` array to create tuples from
99+ - parameter array: of `[NSString]` array to create tuples from
98100
99- : returns: array of collections of tuple pairs where the tuples are lat/lng values as `NSString`s
101+ - returns: array of collections of tuple pairs where the tuples are lat/lng values as `NSString`s
100102 */
101103 internal func convertStringArraysToTuples( array: [ [ NSString ] ] ) -> [ [ ( NSString , NSString ) ] ] {
102104 var tmpResults = [ ( NSString, NSString) ] ( )
103105 var results = [ [ ( NSString, NSString) ] ] ( )
104106 for arr in array {
105107 for var i = 0 ; i < arr. count - 1 ; i += 2 {
106- tmpResults. append ( ( arr [ i] , arr [ i + 1 ] ) )
108+ let elem = ( arr [ i] , arr [ i + 1 ] )
109+ tmpResults. append ( elem)
107110 }
108111
109112 if tmpResults. count == 1 {
@@ -117,13 +120,13 @@ class Parser {
117120 }
118121
119122 /**
120- :abstract : Naively format a `Well-Known Text` string into array of string values, where each string is a single value
123+ _abstract_ : Naively format a `Well-Known Text` string into array of string values, where each string is a single value
121124
122- :discussion : This removes any lingering parens from the given string, breaks on `,` then breaks on ` ` while filtering out any empty strings.
125+ _discussion_ : This removes any lingering parens from the given string, breaks on `,` then breaks on ` ` while filtering out any empty strings.
123126
124- :param: input String to format, assumed `Well-Known Text` format
127+ - parameter input: String to format, assumed `Well-Known Text` format
125128
126- : returns: array of strings where each string is one value from the string with all empty strings filtered out.
129+ - returns: array of strings where each string is one value from the string with all empty strings filtered out.
127130 */
128131 internal func formatStandardGeoDataString( input: NSString ) -> [ NSString ] {
129132 // Remove Extra ()
@@ -150,18 +153,18 @@ class Parser {
150153
151154 private func splitLine( input: NSString , delimiter: NSString ) -> ( NSString , NSString ) {
152155 let array = input. componentsSeparatedByString ( delimiter as String )
153- return ( array. first! as! NSString , array. last! as! NSString )
156+ return ( array. first! as NSString , array. last! as NSString )
154157 }
155158
156159 /**
157160 :abstract: Convert a given array of `(String, String)` tuples to array of `CLLocationCoordinate2D` values
158161
159162 :discussion: This attempts to parse the string's double values but does no safety checks if they can be parsed as `double`s.
160163
161- :param: pairs array of `String` tuples to parse as `Double`s
162- :param: longitudeFirst boolean flag if the first item in the tuple should be the longitude value
164+ - parameter pairs: array of `String` tuples to parse as `Double`s
165+ - parameter longitudeFirst: boolean flag if the first item in the tuple should be the longitude value
163166
164- : returns: array of `CLLocationCoordinate2D` values
167+ - returns: array of `CLLocationCoordinate2D` values
165168 */
166169 internal func convertToCoordinates( pairs: [ ( NSString , NSString ) ] , longitudeFirst: Bool ) -> [ CLLocationCoordinate2D ] {
167170 var coordinates = [ CLLocationCoordinate2D] ( )
@@ -184,18 +187,25 @@ class Parser {
184187 Removes any text before lat long points as well as two outer sets of parens.
185188
186189 Example:
190+ ```
187191 input => "POLYGON(( 15 32 ))"
188192 output => "15 32"
189193
190194 input => "MULTIPOLYGON((( 15 32 )))"
191195 output => "( 15 32 )"
196+ ```
197+
198+ - parameter input: NSString to strip extraneous characters from
192199
193- :param: input NSString to strip extraneous characters from
194-
195- :returns: stripped string instance
200+ - returns: stripped string instance
196201 */
197202 internal func stripExtraneousCharacters( input: NSString ) -> NSString {
198- let regex = NSRegularExpression ( pattern: " \\ w+ \\ s* \\ ((.*) \\ ) " , options: . CaseInsensitive, error: nil )
203+ let regex : NSRegularExpression ?
204+ do {
205+ regex = try NSRegularExpression ( pattern: " \\ w+ \\ s* \\ ((.*) \\ ) " , options: . CaseInsensitive)
206+ } catch _ {
207+ regex = nil
208+ }
199209 let match : AnyObject ? = regex? . matchesInString ( input as String , options: . ReportCompletion, range: NSMakeRange ( 0 , input. length) ) . first
200210 let range = match? . rangeAtIndex ( 1 )
201211
@@ -206,17 +216,17 @@ class Parser {
206216 }
207217
208218 /**
209- :abstract : Attempt to determine if a given string is in `Well-Known Text` format (GeoString as its referred to internally)
219+ _abstract_ : Attempt to determine if a given string is in `Well-Known Text` format (GeoString as its referred to internally)
210220
211- :discussion : This strips any leading & trailing white space before checking for the existance of word characters at the start of the string.
221+ _discussion_ : This strips any leading & trailing white space before checking for the existance of word characters at the start of the string.
212222
213- :param: input String to attempt determine if is in `Well-Known Text` format
223+ - parameter input: String to attempt determine if is in `Well-Known Text` format
214224
215- : returns: `true` if it thinks it is, `false` otherwise
225+ - returns: `true` if it thinks it is, `false` otherwise
216226 */
217227 internal func isProbablyGeoString( input: String ) -> Bool {
218228 let stripped = input. stringByStrippingLeadingAndTrailingWhiteSpace ( )
219- if let geoString = stripped. rangeOfString ( " ^ \\ w+ " , options: . RegularExpressionSearch) {
229+ if stripped. rangeOfString ( " ^ \\ w+ " , options: . RegularExpressionSearch) != nil {
220230 return true
221231 }
222232 return false
@@ -225,12 +235,12 @@ class Parser {
225235 /**
226236 Determine if a given string is a `MULTI*` item.
227237
228- :param: input String to check
238+ - parameter input: String to check
229239
230- : returns: `true` if the string starts with `MULTI`. `false` otherwise
240+ - returns: `true` if the string starts with `MULTI`. `false` otherwise
231241 */
232242 internal func isMultiItem( input: String ) -> Bool {
233- if let isPolygon = input. rangeOfString ( " MULTI " , options: . RegularExpressionSearch) {
243+ if input. rangeOfString ( " MULTI " , options: . RegularExpressionSearch) != nil {
234244 return true
235245 }
236246 return false
@@ -239,11 +249,11 @@ class Parser {
239249 /**
240250 Determines if a the collection is space delimited or not
241251
242- : note: This function should only be passed a single entry or else it will probably have incorrect results
252+ - note: This function should only be passed a single entry or else it will probably have incorrect results
243253
244- :param: input a single entry from the collection as a string
254+ - parameter input: a single entry from the collection as a string
245255
246- : returns: `true` if elements are space delimited, `false` otherwise
256+ - returns: `true` if elements are space delimited, `false` otherwise
247257 */
248258 private func isSpaceDelimited( input: String ) -> Bool {
249259 let array = input. componentsSeparatedByString ( " " )
0 commit comments