Skip to content

Commit d0ce828

Browse files
committed
Merge branch 'release/1.1.1'
2 parents 3e5ccb8 + 54df82f commit d0ce828

File tree

12 files changed

+300
-105
lines changed

12 files changed

+300
-105
lines changed

.travis.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ language: swift
99
osx_image: xcode11.2
1010
sudo: false
1111

12-
xcode_project: AGString.xcodeproj
12+
xcode_project: AGString.xcodeproj
1313

1414
xcode_scheme:
15-
- AGString
15+
- AGString
1616

1717

1818
env:
@@ -21,6 +21,10 @@ env:
2121
- CACHE_NAME=tvOS PLATFORM=tvOS
2222
- CACHE_NAME=watchOS PLATFORM=watchOS
2323

24+
install:
25+
- pip install codecov
26+
27+
2428
before_script:
2529
- export RUN_TESTS="YES"
2630
- export SCHEME="${TRAVIS_XCODE_SCHEME}-${PLATFORM}"
@@ -46,7 +50,7 @@ before_script:
4650
;;
4751
esac
4852
script:
49-
- set -o pipefail
53+
- set -o pipefail
5054
- xcodebuild -version
5155
- xcodebuild -showsdks
5256

@@ -58,7 +62,7 @@ script:
5862

5963
- echo "BUILD FOR DEBUG"
6064
- if [ ${RUN_TESTS} == "YES" ]; then
61-
xcodebuild -project "${TRAVIS_XCODE_PROJECT}" -scheme "${SCHEME}" -sdk "${SDK}" -destination "${DESTINATION}" -configuration Debug ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test | xcpretty;
65+
xcodebuild -project "${TRAVIS_XCODE_PROJECT}" -derivedDataPath Build/ -scheme "${SCHEME}" -sdk "${SDK}" -destination "${DESTINATION}" -configuration Debug ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test | xcpretty;
6266
else
6367
xcodebuild -project "${TRAVIS_XCODE_PROJECT}" -scheme "${SCHEME}" -sdk "${SDK}" -destination "${DESTINATION}" -configuration Debug ONLY_ACTIVE_ARCH=NO build | xcpretty;
6468
fi
@@ -72,9 +76,9 @@ script:
7276
# fi
7377

7478
after_success:
75-
- bash <(curl -s https://codecov.io/bash) -t "$CODE_COV_TOKEN"
79+
- codecov
7680

7781
notifications:
7882
slack:
7983
rooms:
80-
- swiftalgorithmclub:rJxmAKJgpZNBKR2ogwcHbtGu#agstring
84+
- swiftalgorithmclub:rJxmAKJgpZNBKR2ogwcHbtGu#agstring

AGString.xcodeproj/project.pbxproj

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
/* Begin PBXBuildFile section */
1010
2FBE39ED2377C7B700D65251 /* AGRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDB3A5A1236EF1B30041D167 /* AGRegex.swift */; };
1111
2FBE39EE2377C7B700D65251 /* AGMatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD02777323701C86007DCFB6 /* AGMatch.swift */; };
12-
2FBE39EF2377C7B700D65251 /* AGMatchIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA016123703F820001AF7C /* AGMatchIterator.swift */; };
12+
2FBE39EF2377C7B700D65251 /* AGMatchListIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA016123703F820001AF7C /* AGMatchListIterator.swift */; };
1313
2FBE39F02377C7B700D65251 /* String+NSRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF6C86D12372D77B004C83A0 /* String+NSRange.swift */; };
1414
2FBE39F12377C7B700D65251 /* StringIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5EFC82236EF301005134D1 /* StringIndex.swift */; };
1515
2FBE39F22377C7B700D65251 /* Utility.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF4F190B236F126000A0CD30 /* Utility.swift */; };
1616
2FBE39F32377C7C000D65251 /* AGRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDB3A5A1236EF1B30041D167 /* AGRegex.swift */; };
1717
2FBE39F42377C7C000D65251 /* AGMatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD02777323701C86007DCFB6 /* AGMatch.swift */; };
18-
2FBE39F52377C7C000D65251 /* AGMatchIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA016123703F820001AF7C /* AGMatchIterator.swift */; };
18+
2FBE39F52377C7C000D65251 /* AGMatchListIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA016123703F820001AF7C /* AGMatchListIterator.swift */; };
1919
2FBE39F62377C7C000D65251 /* String+NSRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF6C86D12372D77B004C83A0 /* String+NSRange.swift */; };
2020
2FBE39F72377C7C000D65251 /* StringIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5EFC82236EF301005134D1 /* StringIndex.swift */; };
2121
2FBE39F82377C7C000D65251 /* Utility.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF4F190B236F126000A0CD30 /* Utility.swift */; };
2222
2FBE39F92377C7C600D65251 /* AGRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDB3A5A1236EF1B30041D167 /* AGRegex.swift */; };
2323
2FBE39FA2377C7C600D65251 /* AGMatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD02777323701C86007DCFB6 /* AGMatch.swift */; };
24-
2FBE39FB2377C7C600D65251 /* AGMatchIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA016123703F820001AF7C /* AGMatchIterator.swift */; };
24+
2FBE39FB2377C7C600D65251 /* AGMatchListIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA016123703F820001AF7C /* AGMatchListIterator.swift */; };
2525
2FBE39FC2377C7C600D65251 /* String+NSRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF6C86D12372D77B004C83A0 /* String+NSRange.swift */; };
2626
2FBE39FD2377C7C600D65251 /* StringIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5EFC82236EF301005134D1 /* StringIndex.swift */; };
2727
2FBE39FE2377C7C600D65251 /* Utility.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF4F190B236F126000A0CD30 /* Utility.swift */; };
@@ -45,10 +45,22 @@
4545
BD02777823701DB4007DCFB6 /* AGRegexTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD02777523701DA2007DCFB6 /* AGRegexTest.swift */; };
4646
BD02777923701DB7007DCFB6 /* AGRegexTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD02777523701DA2007DCFB6 /* AGRegexTest.swift */; };
4747
BDB3A5A2236EF1B30041D167 /* AGRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDB3A5A1236EF1B30041D167 /* AGRegex.swift */; };
48-
BDDA016223703F820001AF7C /* AGMatchIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA016123703F820001AF7C /* AGMatchIterator.swift */; };
48+
BDDA016223703F820001AF7C /* AGMatchListIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA016123703F820001AF7C /* AGMatchListIterator.swift */; };
49+
FF2593DA237827DE003C3B1F /* AGMatchList.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF2593D9237827DE003C3B1F /* AGMatchList.swift */; };
50+
FF2593DB237827E5003C3B1F /* AGMatchList.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF2593D9237827DE003C3B1F /* AGMatchList.swift */; };
51+
FF2593DC237827E5003C3B1F /* AGMatchList.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF2593D9237827DE003C3B1F /* AGMatchList.swift */; };
52+
FF2593DD237827E5003C3B1F /* AGMatchList.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF2593D9237827DE003C3B1F /* AGMatchList.swift */; };
4953
FF4F190C236F126000A0CD30 /* Utility.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF4F190B236F126000A0CD30 /* Utility.swift */; };
5054
FF5EFC83236EF301005134D1 /* StringIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5EFC82236EF301005134D1 /* StringIndex.swift */; };
5155
FF6C86D22372D77B004C83A0 /* String+NSRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF6C86D12372D77B004C83A0 /* String+NSRange.swift */; };
56+
FFEFD6A023796E4200B17B4A /* AGMatchLazyList.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEFD69F23796E4200B17B4A /* AGMatchLazyList.swift */; };
57+
FFEFD6A223796EDE00B17B4A /* AGMatchLazyListIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEFD6A123796EDE00B17B4A /* AGMatchLazyListIterator.swift */; };
58+
FFEFD6A5237984DE00B17B4A /* AGMatchLazyListIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEFD6A123796EDE00B17B4A /* AGMatchLazyListIterator.swift */; };
59+
FFEFD6A6237984DE00B17B4A /* AGMatchLazyListIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEFD6A123796EDE00B17B4A /* AGMatchLazyListIterator.swift */; };
60+
FFEFD6A7237984DE00B17B4A /* AGMatchLazyListIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEFD6A123796EDE00B17B4A /* AGMatchLazyListIterator.swift */; };
61+
FFEFD6A8237984E000B17B4A /* AGMatchLazyList.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEFD69F23796E4200B17B4A /* AGMatchLazyList.swift */; };
62+
FFEFD6A9237984E000B17B4A /* AGMatchLazyList.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEFD69F23796E4200B17B4A /* AGMatchLazyList.swift */; };
63+
FFEFD6AA237984E100B17B4A /* AGMatchLazyList.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEFD69F23796E4200B17B4A /* AGMatchLazyList.swift */; };
5264
/* End PBXBuildFile section */
5365

5466
/* Begin PBXContainerItemProxy section */
@@ -129,10 +141,13 @@
129141
BD02777323701C86007DCFB6 /* AGMatch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AGMatch.swift; sourceTree = "<group>"; };
130142
BD02777523701DA2007DCFB6 /* AGRegexTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AGRegexTest.swift; sourceTree = "<group>"; };
131143
BDB3A5A1236EF1B30041D167 /* AGRegex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AGRegex.swift; sourceTree = "<group>"; };
132-
BDDA016123703F820001AF7C /* AGMatchIterator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AGMatchIterator.swift; sourceTree = "<group>"; };
144+
BDDA016123703F820001AF7C /* AGMatchListIterator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AGMatchListIterator.swift; sourceTree = "<group>"; };
145+
FF2593D9237827DE003C3B1F /* AGMatchList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AGMatchList.swift; sourceTree = "<group>"; };
133146
FF4F190B236F126000A0CD30 /* Utility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utility.swift; sourceTree = "<group>"; };
134147
FF5EFC82236EF301005134D1 /* StringIndex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringIndex.swift; sourceTree = "<group>"; };
135148
FF6C86D12372D77B004C83A0 /* String+NSRange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+NSRange.swift"; sourceTree = "<group>"; };
149+
FFEFD69F23796E4200B17B4A /* AGMatchLazyList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AGMatchLazyList.swift; sourceTree = "<group>"; };
150+
FFEFD6A123796EDE00B17B4A /* AGMatchLazyListIterator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AGMatchLazyListIterator.swift; sourceTree = "<group>"; };
136151
/* End PBXFileReference section */
137152

138153
/* Begin PBXFrameworksBuildPhase section */
@@ -299,8 +314,11 @@
299314
children = (
300315
BDB3A5A1236EF1B30041D167 /* AGRegex.swift */,
301316
BD02777323701C86007DCFB6 /* AGMatch.swift */,
302-
BDDA016123703F820001AF7C /* AGMatchIterator.swift */,
317+
BDDA016123703F820001AF7C /* AGMatchListIterator.swift */,
303318
FF6C86D12372D77B004C83A0 /* String+NSRange.swift */,
319+
FF2593D9237827DE003C3B1F /* AGMatchList.swift */,
320+
FFEFD69F23796E4200B17B4A /* AGMatchLazyList.swift */,
321+
FFEFD6A123796EDE00B17B4A /* AGMatchLazyListIterator.swift */,
304322
);
305323
path = Regex;
306324
sourceTree = "<group>";
@@ -692,12 +710,15 @@
692710
buildActionMask = 2147483647;
693711
files = (
694712
FF4F190C236F126000A0CD30 /* Utility.swift in Sources */,
695-
BDDA016223703F820001AF7C /* AGMatchIterator.swift in Sources */,
713+
BDDA016223703F820001AF7C /* AGMatchListIterator.swift in Sources */,
696714
FF5EFC83236EF301005134D1 /* StringIndex.swift in Sources */,
697715
BD02777423701C86007DCFB6 /* AGMatch.swift in Sources */,
716+
FFEFD6A223796EDE00B17B4A /* AGMatchLazyListIterator.swift in Sources */,
698717
3D9C42A222745900000A6585 /* AGString.swift in Sources */,
718+
FF2593DA237827DE003C3B1F /* AGMatchList.swift in Sources */,
699719
FF6C86D22372D77B004C83A0 /* String+NSRange.swift in Sources */,
700720
BDB3A5A2236EF1B30041D167 /* AGRegex.swift in Sources */,
721+
FFEFD6A023796E4200B17B4A /* AGMatchLazyList.swift in Sources */,
701722
);
702723
runOnlyForDeploymentPostprocessing = 0;
703724
};
@@ -706,12 +727,15 @@
706727
buildActionMask = 2147483647;
707728
files = (
708729
2FBE39ED2377C7B700D65251 /* AGRegex.swift in Sources */,
730+
FFEFD6A5237984DE00B17B4A /* AGMatchLazyListIterator.swift in Sources */,
709731
2FBE39EE2377C7B700D65251 /* AGMatch.swift in Sources */,
710-
2FBE39EF2377C7B700D65251 /* AGMatchIterator.swift in Sources */,
732+
2FBE39EF2377C7B700D65251 /* AGMatchListIterator.swift in Sources */,
711733
2FBE39F02377C7B700D65251 /* String+NSRange.swift in Sources */,
712734
2FBE39F12377C7B700D65251 /* StringIndex.swift in Sources */,
735+
FF2593DB237827E5003C3B1F /* AGMatchList.swift in Sources */,
713736
2FBE39F22377C7B700D65251 /* Utility.swift in Sources */,
714737
3D9C42B1227459C1000A6585 /* AGString.swift in Sources */,
738+
FFEFD6A8237984E000B17B4A /* AGMatchLazyList.swift in Sources */,
715739
);
716740
runOnlyForDeploymentPostprocessing = 0;
717741
};
@@ -720,12 +744,15 @@
720744
buildActionMask = 2147483647;
721745
files = (
722746
2FBE39F32377C7C000D65251 /* AGRegex.swift in Sources */,
747+
FFEFD6A6237984DE00B17B4A /* AGMatchLazyListIterator.swift in Sources */,
723748
2FBE39F42377C7C000D65251 /* AGMatch.swift in Sources */,
724-
2FBE39F52377C7C000D65251 /* AGMatchIterator.swift in Sources */,
749+
2FBE39F52377C7C000D65251 /* AGMatchListIterator.swift in Sources */,
725750
2FBE39F62377C7C000D65251 /* String+NSRange.swift in Sources */,
726751
2FBE39F72377C7C000D65251 /* StringIndex.swift in Sources */,
752+
FF2593DC237827E5003C3B1F /* AGMatchList.swift in Sources */,
727753
2FBE39F82377C7C000D65251 /* Utility.swift in Sources */,
728754
3D9C42BF227459F6000A6585 /* AGString.swift in Sources */,
755+
FFEFD6A9237984E000B17B4A /* AGMatchLazyList.swift in Sources */,
729756
);
730757
runOnlyForDeploymentPostprocessing = 0;
731758
};
@@ -734,12 +761,15 @@
734761
buildActionMask = 2147483647;
735762
files = (
736763
2FBE39F92377C7C600D65251 /* AGRegex.swift in Sources */,
764+
FFEFD6A7237984DE00B17B4A /* AGMatchLazyListIterator.swift in Sources */,
737765
2FBE39FA2377C7C600D65251 /* AGMatch.swift in Sources */,
738-
2FBE39FB2377C7C600D65251 /* AGMatchIterator.swift in Sources */,
766+
2FBE39FB2377C7C600D65251 /* AGMatchListIterator.swift in Sources */,
739767
2FBE39FC2377C7C600D65251 /* String+NSRange.swift in Sources */,
740768
2FBE39FD2377C7C600D65251 /* StringIndex.swift in Sources */,
769+
FF2593DD237827E5003C3B1F /* AGMatchList.swift in Sources */,
741770
2FBE39FE2377C7C600D65251 /* Utility.swift in Sources */,
742771
3D9C42CD22745A28000A6585 /* AGString.swift in Sources */,
772+
FFEFD6AA237984E100B17B4A /* AGMatchLazyList.swift in Sources */,
743773
);
744774
runOnlyForDeploymentPostprocessing = 0;
745775
};

Sources/Regex/AGMatch.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@
88

99
import Foundation
1010

11-
public typealias AGSpan = (Int, Int)
11+
public typealias AGSpan = NSRange
1212

13-
public struct AGMatch {
13+
public struct AGMatch: Equatable {
1414
let start: Int
1515
let end: Int
16-
let base: String
1716
private let groups: [String]
1817

1918
public init(start: Int, end: Int, base: String, groups: [String]) {
2019
self.start = start
2120
self.end = end
22-
self.base = base
2321
self.groups = groups
2422
}
2523
}
@@ -28,22 +26,16 @@ extension AGMatch {
2826
public var groupCount: Int {
2927
return groups.count
3028
}
31-
public func group(_ index: Int) -> String {
29+
30+
public func group(_ index: Int = 0) -> String {
3231
guard index < groups.count else {
3332
return ""
3433
}
3534

3635
return groups[index]
3736
}
3837

39-
public func group() -> String {
40-
guard let result = groups.first else {
41-
return ""
42-
}
43-
44-
return result
45-
}
4638
public var span: AGSpan {
47-
return (start, end)
39+
return NSRange(location: start, length: start + end)
4840
}
4941
}

Sources/Regex/AGMatchIterator.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// AGMatchLazyList.swift
3+
// AGString-iOS
4+
//
5+
// Created by 조수환 on 2019/11/11.
6+
// Copyright © 2019 AGString. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct AGMatchLazyList: Equatable, Sequence {
12+
public typealias Iterator = AGMatchLazyListIterator
13+
public typealias Element = AGMatch
14+
15+
public let baseString: String
16+
private let regex: NSRegularExpression
17+
18+
init(base: String, regex: NSRegularExpression) {
19+
self.baseString = base
20+
self.regex = regex
21+
}
22+
23+
public __consuming func makeIterator() -> AGMatchLazyList.Iterator {
24+
return AGMatchLazyListIterator(base: baseString,
25+
regex: self.regex)
26+
}
27+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// AGMatchLazyListIterator.swift
3+
// AGString-iOS
4+
//
5+
// Created by 조수환 on 2019/11/11.
6+
// Copyright © 2019 AGString. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct AGMatchLazyListIterator: IteratorProtocol {
12+
public typealias Element = AGMatch
13+
14+
private let baseString: String
15+
private let regex: NSRegularExpression
16+
private var offset: Int = 0
17+
18+
public mutating func next() -> AGMatch? {
19+
guard let matched = regex.firstMatch(
20+
in: baseString,
21+
options: [],
22+
range: NSRange(location: offset, length: baseString.count - offset))
23+
else { return nil }
24+
25+
var group: [String] = []
26+
27+
for index in 0 ..< matched.numberOfRanges {
28+
let interpolated = NSRange(
29+
location: matched.range(at: index).lowerBound,
30+
length: matched.range(at: index).length)
31+
32+
group.append(baseString[interpolated])
33+
}
34+
35+
let result = AGMatch(
36+
start: matched.range.lowerBound,
37+
end: matched.range.upperBound,
38+
base: baseString,
39+
groups: group)
40+
41+
self.offset = matched.range.upperBound
42+
43+
return result
44+
}
45+
46+
init(base: String, regex: NSRegularExpression) {
47+
self.baseString = base
48+
self.regex = regex
49+
}
50+
}

Sources/Regex/AGMatchList.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// AGMatchList.swift
3+
// AGString-iOS
4+
//
5+
// Created by 조수환 on 2019/11/10.
6+
// Copyright © 2019 AGString. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct AGMatchList: Equatable, Sequence {
12+
public typealias Iterator = AGMatchListIterator
13+
public typealias Element = AGMatch
14+
15+
public let baseString: String
16+
private let list: [Element]
17+
18+
init(base: String, matching matchList: [Element]) {
19+
baseString = base
20+
list = matchList
21+
}
22+
23+
public var first: AGMatch? {
24+
return list.first
25+
}
26+
27+
public var last: AGMatch? {
28+
return list.last
29+
}
30+
31+
public __consuming func makeIterator() -> AGMatchList.Iterator {
32+
return AGMatchListIterator(list.makeIterator())
33+
}
34+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// AGMatchIterator.swift
3+
// AGString-iOS
4+
//
5+
// Created by tskim on 2019/11/04.
6+
// Copyright © 2019 AGString. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct AGMatchListIterator: IteratorProtocol {
12+
public typealias Element = AGMatch
13+
14+
var iterator: IndexingIterator<[AGMatch]>
15+
public mutating func next() -> AGMatch? {
16+
return iterator.next()
17+
}
18+
19+
init(_ iterator: IndexingIterator<[AGMatch]>) {
20+
self.iterator = iterator
21+
}
22+
}

0 commit comments

Comments
 (0)