Skip to content

Releases: RougeWare/Swift-String-Integer-Access

2.1 - Introduced mutation! 🎉

11 Jun 17:10
595374e
Compare
Choose a tag to compare

This even introduces some functionality that Swift Strings don't have!

var someString = "Hello, World!"

someString[1...4]           // "ello"
someString[7..<12] = "Mars" // "Hello, Mars!"


someString[orNil: ...4]   = "Howdy"      // "Howdy, Mars!"
someString[orNil: 999...] = "Boundaries" // "Howdy, Mars!"

Licensing

This also changes the license so it's explicitly BH-1-PS.

2.0.0 - SafeStringIntegerAccess

22 May 19:42
57b379e
Compare
Choose a tag to compare

More integer accessors, these without crashes! Drawing from Swift Safe Collection Access, you can now access strings with Ints, and if you pass an invalid value to these new orNil subscripts and functions, they will return nil instead of crashing!

import SafeStringIntegerAccess

let someString = "Hello, World!"

someString[orNil: 3..<5] == "lo"
someString[orNil: 3..<5] == someString[3..<5]
someString[orNil: 42..<99] == nil 
someString[orNil: -10 ..< -5] == nil 

To take advantage of this new behavior, import SafeStringIntegerAccess. This will give the old behavior as well. If you just want the old behavior, import StringIntegerAccess instead.


Additionally, the NSRange subscript introduced in 1.2.0 now returns a Substring rather than an Optional<Substring>, crashing if the given range is invalid. For the non-crashing, optional-return behavior, pass your NSRange to the [orNil:] subscript.

In doing this update, the NSRange subscripts were updated to fix a bug with the way it processes strings with higher-plane Unicode characters and grapheme clusters.

1.2.0 - Added `NSRange` subscript

20 May 18:33
3bd0d7e
Compare
Choose a tag to compare

Allows you to just pass a NSRange to a String's subscript. Great for working with things like NSRegularExpression!

1.1.0 - Expanded support

03 Mar 03:39
c2abe76
Compare
Choose a tag to compare

Now supports all types conforming to StringProtocol, and all range subscripts

1.0.1 - MVP

29 Feb 00:50
Compare
Choose a tag to compare

Some basic integer-based string subscripts. If I continue to hit similar frustrating barriers, I'll add more to address those.