Skip to content

Commit ca9a0c4

Browse files
authored
Added deprecations of old RegexQuantifier members
1 parent 453537a commit ca9a0c4

File tree

2 files changed

+92
-10
lines changed

2 files changed

+92
-10
lines changed

src/main/kotlin/RegexQuantifier.kt

Lines changed: 92 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ sealed class RegexQuantifier(
1010

1111
interface Greedy {
1212
val butAsFewAsPossible: RegexQuantifier
13+
14+
@Deprecated(
15+
message = "Replace with butAsFewAsPossible",
16+
replaceWith = ReplaceWith(
17+
"butAsFewAsPossible",
18+
"uk.co.mainwave.regextoolboxkotlin.RegexQuantifier"
19+
)
20+
)
21+
fun butAsFewAsPossible() = butAsFewAsPossible
1322
}
1423

1524
/**
@@ -54,7 +63,7 @@ sealed class RegexQuantifier(
5463
* @param minimum The minimum number of occurrences to match
5564
* @return A greedy quantifier: use [butAsFewAsPossible] to make it lazy
5665
*/
57-
class AtLeast(minimum: Int): RegexQuantifier("{$minimum,}"), Greedy {
66+
class AtLeast(minimum: Int) : RegexQuantifier("{$minimum,}"), Greedy {
5867
override val butAsFewAsPossible: RegexQuantifier = LazyAtLeast(minimum)
5968
}
6069

@@ -64,7 +73,7 @@ sealed class RegexQuantifier(
6473
* @param maximum The maximum number of occurrences to match
6574
* @return A greedy quantifier: use [butAsFewAsPossible] to make it lazy
6675
*/
67-
class NoMoreThan(maximum: Int): RegexQuantifier("{0,$maximum}"), Greedy {
76+
class NoMoreThan(maximum: Int) : RegexQuantifier("{0,$maximum}"), Greedy {
6877
override val butAsFewAsPossible: RegexQuantifier = LazyNoMoreThan(maximum)
6978
}
7079

@@ -75,14 +84,88 @@ sealed class RegexQuantifier(
7584
* @param maximum The maximum number of occurrences to match
7685
* @return A greedy quantifier: use [butAsFewAsPossible] to make it lazy
7786
*/
78-
class Between(minimum: Int, maximum: Int): RegexQuantifier("{$minimum,$maximum}"), Greedy {
87+
class Between(minimum: Int, maximum: Int) : RegexQuantifier("{$minimum,$maximum}"), Greedy {
7988
override val butAsFewAsPossible: RegexQuantifier = LazyBetween(minimum, maximum)
8089
}
8190

82-
private object LazyZeroOrMore: RegexQuantifier("*?")
83-
private object LazyOneOrMore: RegexQuantifier("+?")
84-
private object LazyZeroOrOne: RegexQuantifier("??")
85-
private class LazyAtLeast(minimum: Int): RegexQuantifier("{$minimum,}?")
86-
private class LazyNoMoreThan(maximum: Int): RegexQuantifier("{0,$maximum}?")
87-
private class LazyBetween(minimum: Int, maximum: Int): RegexQuantifier("{$minimum,$maximum}?")
91+
private object LazyZeroOrMore : RegexQuantifier("*?")
92+
private object LazyOneOrMore : RegexQuantifier("+?")
93+
private object LazyZeroOrOne : RegexQuantifier("??")
94+
private class LazyAtLeast(minimum: Int) : RegexQuantifier("{$minimum,}?")
95+
private class LazyNoMoreThan(maximum: Int) : RegexQuantifier("{0,$maximum}?")
96+
private class LazyBetween(minimum: Int, maximum: Int) : RegexQuantifier("{$minimum,$maximum}?")
97+
98+
companion object {
99+
@Deprecated(
100+
message = "Replace with ZeroOrOne",
101+
replaceWith = ReplaceWith(
102+
"ZeroOrOne",
103+
"uk.co.mainwave.regextoolboxkotlin.RegexQuantifier.ZeroOrOne"
104+
)
105+
)
106+
fun oneOrNone() = ZeroOrOne
107+
108+
@Deprecated(
109+
message = "Replace with ZeroOrOne",
110+
replaceWith = ReplaceWith(
111+
"ZeroOrOne",
112+
"uk.co.mainwave.regextoolboxkotlin.RegexQuantifier.ZeroOrOne"
113+
)
114+
)
115+
fun zeroOrOne() = ZeroOrOne
116+
117+
@Deprecated(
118+
message = "Replace with ZeroOrMore",
119+
replaceWith = ReplaceWith(
120+
"ZeroOrMore",
121+
"uk.co.mainwave.regextoolboxkotlin.RegexQuantifier.ZeroOrMore"
122+
)
123+
)
124+
fun zeroOrMore() = ZeroOrMore
125+
126+
@Deprecated(
127+
message = "Replace with OneOrMore",
128+
replaceWith = ReplaceWith(
129+
"OneOrMore",
130+
"uk.co.mainwave.regextoolboxkotlin.RegexQuantifier.OneOrMore"
131+
)
132+
)
133+
fun oneOrMore() = OneOrMore
134+
135+
@Deprecated(
136+
message = "Replace with Exactly",
137+
replaceWith = ReplaceWith(
138+
"Exactly(times)",
139+
"uk.co.mainwave.regextoolboxkotlin.RegexQuantifier.Exactly"
140+
)
141+
)
142+
fun exactly(times: Int) = Exactly(times)
143+
144+
@Deprecated(
145+
message = "Replace with AtLeast",
146+
replaceWith = ReplaceWith(
147+
"AtLeast(minimum)",
148+
"uk.co.mainwave.regextoolboxkotlin.RegexQuantifier.AtLeast"
149+
)
150+
)
151+
fun atLeast(minimum: Int) = AtLeast(minimum)
152+
153+
@Deprecated(
154+
message = "Replace with NoMoreThan",
155+
replaceWith = ReplaceWith(
156+
"NoMoreThan(maximum)",
157+
"uk.co.mainwave.regextoolboxkotlin.RegexQuantifier.NoMoreThan"
158+
)
159+
)
160+
fun noMoreThan(maximum: Int) = NoMoreThan(maximum)
161+
162+
@Deprecated(
163+
message = "Replace with Between",
164+
replaceWith = ReplaceWith(
165+
"Between(minimum, maximum)",
166+
"uk.co.mainwave.regextoolboxkotlin.RegexQuantifier.Between"
167+
)
168+
)
169+
fun between(minimum: Int, maximum: Int) = Between(minimum, maximum)
170+
}
88171
}

src/test/kotlin/RegexBuilderTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import uk.co.mainwave.regextoolboxkotlin.RegexBuilder
88
import uk.co.mainwave.regextoolboxkotlin.RegexBuilderException
99
import uk.co.mainwave.regextoolboxkotlin.RegexOptions.IGNORE_CASE
1010
import uk.co.mainwave.regextoolboxkotlin.RegexOptions.MULTILINE
11-
import uk.co.mainwave.regextoolboxkotlin.RegexQuantifier
1211
import uk.co.mainwave.regextoolboxkotlin.RegexQuantifier.AtLeast
1312
import uk.co.mainwave.regextoolboxkotlin.RegexQuantifier.Between
1413
import uk.co.mainwave.regextoolboxkotlin.RegexQuantifier.Exactly

0 commit comments

Comments
 (0)