Skip to content

Commit 56fae94

Browse files
authored
Remove deprecated features (#22)
* Remove deprecated features Remove public constructor to enforce `regex { }` syntax. Remove start/end group methods to enforce `group { }` syntax. Remove logging. * Updated README.md for 3.0
1 parent 9be083b commit 56fae94

File tree

8 files changed

+375
-3992
lines changed

8 files changed

+375
-3992
lines changed

README.md

Lines changed: 13 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -15,63 +15,22 @@ It offers a lot of benefits over using raw regex syntax in strings:
1515

1616
It is fully documented in the [project wiki](https://github.com/markwhitaker/RegexToolbox.kt/wiki).
1717

18-
## New in 2.2
18+
## Breaking changes in 3.0
1919

20-
### Logging
20+
All `RegexBuilder` features that were deprecated in version 2.4 have been removed in 3.0.
2121

22-
Use the new `addLogger()` method to connect a logger of your choice and see how your regex is built, step by step. For example:
23-
24-
```kotlin
25-
val regex = RegexBuilder()
26-
.addLogger {
27-
println(it)
28-
}
29-
.wordBoundary()
30-
.text("Regex")
31-
.anyOf("Builder", "Toolbox")
32-
.wordBoundary()
33-
.buildRegex()
34-
```
35-
36-
or this:
37-
38-
```kotlin
39-
val regex = regex {
40-
addLogger {
41-
println(it)
42-
}
43-
wordBoundary()
44-
text("Regex")
45-
anyOf("Builder", "Toolbox")
46-
wordBoundary()
47-
}
48-
```
49-
50-
will output this to your console:
51-
52-
```text
53-
RegexBuilder: wordBoundary(): \b
54-
RegexBuilder: text("Regex"): Regex
55-
RegexBuilder: anyOf("Builder", "Toolbox"): (?:Builder|Toolbox)
56-
RegexBuilder: wordBoundary(): \b
57-
RegexBuilder: buildRegex(): \bRegex(?:Builder|Toolbox)\b
58-
```
59-
60-
## New in 2.0
61-
62-
### New builder syntax
63-
64-
Version 2.0 introduces a simplified [type-safe builder syntax](https://kotlinlang.org/docs/reference/type-safe-builders.html) for cleaner, less error-prone and more Kotliny code. Go from this:
65-
66-
```kotlin
67-
val regex = RegexBuilder()
68-
.startGroup()
69-
.letter()
70-
.digit()
71-
.buildRegex() // ERROR: forgot to call endGroup()
72-
```
22+
|Removed|Replaced with|
23+
|---|---|
24+
|`RegexBuilder()` public constructor|`regex { ... }`|
25+
|`buildRegex()`|`regex { ... }`|
26+
|`buildPattern()`|`pattern { ... }`|
27+
|`startGroup() ... endGroup()`|`group { ... }`|
28+
|`startNamedGroup() ... endGroup()`|`namedGroup { ... }`|
29+
|`startNonCapturingGroup() ... endGroup()`|`nonCapturingGroup { ... }`|
30+
|`addLogger()`|No replacement: logging has been removed.|
7331

74-
to this:
32+
In a nutshell: the old Java-style is completed removed in 3.0.
33+
RegexToolbox.kt now exclusively uses the new [type-safe builder syntax](https://kotlinlang.org/docs/reference/type-safe-builders.html) introduced in 2.0, for example:
7534

7635
```kotlin
7736
val regex = regex {
@@ -82,23 +41,6 @@ val regex = regex {
8241
} // Yay! No need to call buildRegex()
8342
```
8443

85-
The old syntax is still supported if that's your preference (and for consistency with the sibling projects listed at the bottom of the page).
86-
87-
### Quantifiers
88-
89-
`RegexQuantifier` is now a sealed class and its methods have become objects or classes. The old syntax is still supported but deprecated and will be removed in a future version.
90-
91-
|Old syntax|becomes|
92-
|---|---|
93-
|`RegexQuantifier.zeroOrOne()`|`RegexQuantifier.ZeroOrOne`|
94-
|`RegexQuantifier.zeroOrMore()`|`RegexQuantifier.ZeroOrMore`|
95-
|`RegexQuantifier.oneOrMore()`|`RegexQuantifier.OneOrMore`|
96-
|`RegexQuantifier.exactly(1)`|`RegexQuantifier.Exactly(1)`|
97-
|`RegexQuantifier.atLeast(1)`|`RegexQuantifier.AtLeast(1)`|
98-
|`RegexQuantifier.noMoreThan(1)`|`RegexQuantifier.NoMoreThan(1)`|
99-
|`RegexQuantifier.between(1,2)`|`RegexQuantifier.Between(1,2)`|
100-
|`[quantifier].butAsFewAsPossible()`|`[quantifier].butAsFewAsPossible`|
101-
10244
## Usage (Gradle)
10345

10446
RegexToolbox.kt is [hosted on JitPack](https://jitpack.io/#markwhitaker/RegexToolbox.kt).

0 commit comments

Comments
 (0)