AGString is an extension for convenient working with swift String.
AGRegex is Wrapper of NSRegularExpression. It gives an easy and iterative way to use RegularExpression.
-
AGString gives 'String type' to 'Int-Index' based referencing
- ✅ Get Character object with Int index
- ✅ Get substring object with Range
- ✅ String utility methods(zfill, countOccurence, ltrim,rtrim ...)
-
AGRegex
- ✅ Provide NSRange extension for String
- ✅ Get All Match Result as AGMatch structure.
- ✅ Support iterative way to use match result
- ✅ Substitute matched string to other string
The example application is the best way to see AGString
in action. Simply open the AGString.xcodeproj
and run the Example
scheme.
AGString is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'AGString'
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
To integrate AGString into your Xcode project using Carthage, specify it in your Cartfile
:
github "SwiftAlgorithmClub/AGString"
Run carthage update
to build the framework and drag the built AGString.framework
into your Xcode project.
On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase” and add the Framework path as mentioned in Carthage Getting started Step 4, 5 and 6
var str = "Hello, World!"
str[1..<3] // "el"
str[7...9] // "Wor"
str[7...] // "World!"
str[..<5] // "Hello"
str[...5] // "Hello,"
var str = "Hello, World!"
str[1] // "e"
" abcd ".trimLeft()
// "abcd "
" abcd ".trimRight()
// " abcd"
" abcd ".trim()
//"abcd"
let str = "like in like"
str.occurence(of: "like") // 2
let str = "abc"
str.zfill(10) // "0000000abc"
str.zfill(10, with: "1", direction: .right) // "abc1111111"
let r = try! NSRegularExpression(pattern: "ai", options: [])
let regex = AGRegex(r)
regex.findAll("The rain in Spain")
/*
[
AGMatch(start: 5, end: 7, base: str, groups: ["ai"]),
AGMatch(start: 14, end: 16, base: str, groups: ["ai"]),
]
*/
let r = try! NSRegularExpression(pattern: "ai", options: [])
let regex = AGRegex(r)
regex.first("The rain in Spain")
// AGMatch(start: 5, end: 7, base: str, groups: ["ai"])
let r = try! NSRegularExpression(pattern: "ai", options: [])
let regex = AGRegex(r)
regex.last("The rain in Spain")
// AGMatch(start: 14, end: 16, base: str, groups: ["ai"])
let r = try! NSRegularExpression(pattern: "ai", options: [])
let regex = AGRegex(r)
regex.last("The rain in Spain")
// AGMatch(start: 14, end: 16, base: str, groups: ["ai"])
let r = try! NSRegularExpression(pattern: "\\s", options: [])
let regex = AGRegex(r)
regex.sub(str: "The rain in Spain", replace: "9")
// The9rain9in9Spain
regex.sub(str: str, replace: "9", count: 2)
subWithCount == "The9rain9in Spain"
// "The9rain9in Spain"
let r = try! NSRegularExpression(pattern: "([A-Z]+)([0-9]+)", options: [])
let regex = AGRegex(r)
for m in regex.finditer("ABC12DEF3G56HIJ7") {
print("\(m.group(2)) * \(m.group(1))")
}
/*
"12 * ABC",
"3 * DEF",
"56 * G",
"7 * HIJ"
*/
Contributions are very welcome 🙌
AGString is released under the MIT license. See LICENSE for details.