|
1 | 1 | <p align="center"> |
2 | 2 | <img width="300" src="https://github.com/SwiftAlgorithmClub/AGResources/blob/master/Banner.png" alt="AGString Logo"></p> |
3 | | - |
4 | 3 | <p align="center"> |
5 | 4 | <a href="https://developer.apple.com/swift/"> |
6 | 5 | <img src="https://img.shields.io/badge/Swift-5.0-orange.svg?style=flat" alt="Swift 5.0"> |
|
20 | 19 | </p> |
21 | 20 |
|
22 | 21 | # AGString |
23 | | - |
24 | 22 | <p align="center"> |
25 | | -ℹ️ Short description of AGString |
| 23 | +AGString is an extension for convenient working with swift String. |
26 | 24 | </p> |
27 | | - |
| 25 | +<p align="center"> |
| 26 | +AGRegex is Wrapper of NSRegularExpression. It gives an easy and iterative way to use RegularExpression. |
| 27 | + </p> |
| 28 | + |
28 | 29 | ## Features |
29 | | - |
30 | | -- [x] ℹ️ Add AGString features |
31 | | - |
| 30 | +- AGString gives 'String type' to 'Int-Index' based referencing |
| 31 | + |
| 32 | + * ❎ Get Character object with Int index |
| 33 | + * ❎ Get substring object with Range<Int> |
| 34 | + * ❎ String utility methods(zfill, countOccurence, ltrim,rtrim ...) |
| 35 | + |
| 36 | +- AGRegex |
| 37 | + |
| 38 | + * ❎ Provide NSRange extension for String |
| 39 | + * ❎ Get All Match Result as AGMatch structure. |
| 40 | + * ❎ Support iterative way to use match result |
| 41 | + * ❎ Substitute matched string to other string |
| 42 | + |
32 | 43 | ## Example |
33 | | - |
34 | 44 | The example application is the best way to see `AGString` in action. Simply open the `AGString.xcodeproj` and run the `Example` scheme. |
35 | | - |
36 | 45 | ## Installation |
37 | | - |
38 | 46 | ### CocoaPods |
39 | | - |
40 | 47 | AGString is available through [CocoaPods](http://cocoapods.org). To install |
41 | 48 | it, simply add the following line to your Podfile: |
42 | | - |
43 | 49 | ```bash |
44 | 50 | pod 'AGString' |
45 | 51 | ``` |
46 | | - |
47 | 52 | ### Carthage |
48 | | - |
49 | 53 | [Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. |
50 | | - |
51 | 54 | To integrate AGString into your Xcode project using Carthage, specify it in your `Cartfile`: |
52 | | - |
53 | 55 | ```ogdl |
54 | | -github "KITGITHUBHANDLE/AGString" |
| 56 | +github "SwiftAlgorithmClub/AGString" |
55 | 57 | ``` |
56 | | - |
57 | 58 | Run `carthage update` to build the framework and drag the built `AGString.framework` into your Xcode project. |
58 | | - |
59 | 59 | 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](https://github.com/Carthage/Carthage/blob/master/README.md#if-youre-building-for-ios-tvos-or-watchos) |
60 | | - |
61 | | -### Swift Package Manager |
62 | | - |
63 | | -To integrate using Apple's [Swift Package Manager](https://swift.org/package-manager/), add the following as a dependency to your `Package.swift`: |
64 | | - |
| 60 | +## AGString Usage |
| 61 | +### Slicing |
| 62 | +```swift |
| 63 | +var str = "Hello, World!" |
| 64 | +str[1..<3] // "el" |
| 65 | +str[7...9] // "Wor" |
| 66 | +str[7...] // "World!" |
| 67 | +str[..<5] // "Hello" |
| 68 | +str[...5] // "Hello," |
| 69 | +``` |
| 70 | +### CharAt |
| 71 | +```swift |
| 72 | +var str = "Hello, World!" |
| 73 | +str[1] // "e" |
| 74 | +``` |
| 75 | +### Trim |
| 76 | +```swift |
| 77 | +" abcd ".trimLeft() |
| 78 | +// "abcd " |
| 79 | +" abcd ".trimRight() |
| 80 | +// " abcd" |
| 81 | +" abcd ".trim() |
| 82 | +//"abcd" |
| 83 | +``` |
| 84 | +### WordCount |
65 | 85 | ```swift |
66 | | -dependencies: [ |
67 | | - .package(url: "https://github.com/SwiftAlgorithmClub/AGString.git.git", from: "1.0.0") |
| 86 | +let str = "like in like" |
| 87 | +str.occurence(of: "like") // 2 |
| 88 | +``` |
| 89 | +### Zfill |
| 90 | +```swift |
| 91 | +let str = "abc" |
| 92 | +str.zfill(10) // "0000000abc" |
| 93 | +str.zfill(10, with: "1", direction: .right) // "abc1111111" |
| 94 | +``` |
| 95 | +## AGRegex Usage |
| 96 | +### FindAll |
| 97 | +```swift |
| 98 | +let r = try! NSRegularExpression(pattern: "ai", options: []) |
| 99 | +let regex = AGRegex(r) |
| 100 | +regex.findAll("The rain in Spain") |
| 101 | +/* |
| 102 | +[ |
| 103 | + AGMatch(start: 5, end: 7, base: str, groups: ["ai"]), |
| 104 | + AGMatch(start: 14, end: 16, base: str, groups: ["ai"]), |
68 | 105 | ] |
| 106 | +*/ |
| 107 | +``` |
| 108 | +### First |
| 109 | +```swift |
| 110 | +let r = try! NSRegularExpression(pattern: "ai", options: []) |
| 111 | +let regex = AGRegex(r) |
| 112 | +regex.first("The rain in Spain") |
| 113 | +// AGMatch(start: 5, end: 7, base: str, groups: ["ai"]) |
| 114 | +``` |
| 115 | +### Last |
| 116 | +```swift |
| 117 | +let r = try! NSRegularExpression(pattern: "ai", options: []) |
| 118 | +let regex = AGRegex(r) |
| 119 | +regex.last("The rain in Spain") |
| 120 | +// AGMatch(start: 14, end: 16, base: str, groups: ["ai"]) |
| 121 | +``` |
| 122 | +### Sub |
| 123 | +```swift |
| 124 | +let r = try! NSRegularExpression(pattern: "ai", options: []) |
| 125 | +let regex = AGRegex(r) |
| 126 | +regex.last("The rain in Spain") |
| 127 | +// AGMatch(start: 14, end: 16, base: str, groups: ["ai"]) |
| 128 | +let r = try! NSRegularExpression(pattern: "\\s", options: []) |
| 129 | +let regex = AGRegex(r) |
| 130 | +regex.sub(str: "The rain in Spain", replace: "9") |
| 131 | +// The9rain9in9Spain |
| 132 | +regex.sub(str: str, replace: "9", count: 2) |
| 133 | +subWithCount == "The9rain9in Spain" |
| 134 | +// "The9rain9in Spain" |
| 135 | +``` |
| 136 | +### FindIter |
| 137 | +```swift |
| 138 | +let r = try! NSRegularExpression(pattern: "([A-Z]+)([0-9]+)", options: []) |
| 139 | +let regex = AGRegex(r) |
| 140 | +for m in regex.finditer("ABC12DEF3G56HIJ7") { |
| 141 | + print("\(m.group(2)) * \(m.group(1))") |
| 142 | +} |
| 143 | +/* |
| 144 | + "12 * ABC", |
| 145 | + "3 * DEF", |
| 146 | + "56 * G", |
| 147 | + "7 * HIJ" |
| 148 | + */ |
69 | 149 | ``` |
70 | | - |
71 | | -Alternatively navigate to your Xcode project, select `Swift Packages` and click the `+` icon to search for `AGString`. |
72 | | - |
73 | | -### Manually |
74 | | - |
75 | | -If you prefer not to use any of the aforementioned dependency managers, you can integrate AGString into your project manually. Simply drag the `Sources` Folder into your Xcode project. |
76 | | - |
77 | | -## Usage |
78 | | - |
79 | | -ℹ️ Describe the usage of your Kit |
80 | | - |
81 | 150 | ## Contributing |
82 | 151 | Contributions are very welcome 🙌 |
83 | | - |
84 | 152 | ## License |
85 | | - |
86 | | -``` |
87 | | -AGString |
88 | | -Copyright (c) 2019 AGString [email protected] |
89 | | -
|
90 | | -Permission is hereby granted, free of charge, to any person obtaining a copy |
91 | | -of this software and associated documentation files (the "Software"), to deal |
92 | | -in the Software without restriction, including without limitation the rights |
93 | | -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
94 | | -copies of the Software, and to permit persons to whom the Software is |
95 | | -furnished to do so, subject to the following conditions: |
96 | | -
|
97 | | -The above copyright notice and this permission notice shall be included in |
98 | | -all copies or substantial portions of the Software. |
99 | | -
|
100 | | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
101 | | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
102 | | -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
103 | | -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
104 | | -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
105 | | -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
106 | | -THE SOFTWARE. |
107 | | -``` |
108 | | -# AGString |
| 153 | +AGString is released under the MIT license. See LICENSE for details. |
0 commit comments