Skip to content

Commit 9be083b

Browse files
authored
Deprecate outgoing features (#21)
* Deprecate logging * Deprecate old syntax and exception
1 parent 50fbc77 commit 9be083b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/kotlin/RegexBuilder.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import java.util.regex.Pattern
1515
* }
1616
* </pre>
1717
*/
18-
class RegexBuilder {
18+
class RegexBuilder @Deprecated("The old syntax will be removed in version 3.0: please use the new syntax") constructor() {
1919
private val stringBuilder = StringBuilder()
2020
private var openGroupCount = 0
2121
private var logFunction: (s: String) -> Unit = {}
@@ -24,10 +24,12 @@ class RegexBuilder {
2424
/**
2525
* Interface to a logger attached by the client code which will receive log messages as the regex is built.
2626
*/
27+
@Deprecated("Logging will be removed in version 3.0")
2728
interface Logger {
2829
/**
2930
* Log a [message] to a debugger or logging framework
3031
*/
32+
@Deprecated("Logging will be removed in version 3.0")
3133
fun log(message: String)
3234
}
3335

@@ -40,6 +42,7 @@ class RegexBuilder {
4042
* @throws RegexBuilderException An error occurred when building the regex
4143
*/
4244
@Throws(RegexBuilderException::class)
45+
@Deprecated("The old syntax will be removed in version 3.0: please use regex")
4346
fun buildRegex(vararg options: RegexOptions): Regex =
4447
when (openGroupCount) {
4548
0 -> {
@@ -70,12 +73,14 @@ class RegexBuilder {
7073
* @throws RegexBuilderException An error occurred when building the regex
7174
*/
7275
@Throws(RegexBuilderException::class)
76+
@Deprecated("The old syntax will be removed in version 3.0: please use pattern")
7377
fun buildPattern(vararg options: RegexOptions): Pattern = buildRegex(*options).toPattern()
7478

7579
/**
7680
* Attach a [logger] to this builder using this [Logger] interface. The builder will emit logging messages to it as
7781
* the regex is built with the prefix "RegexBuilder".
7882
*/
83+
@Deprecated("Logging will be removed in version 3.0")
7984
fun addLogger(logger: Logger): RegexBuilder {
8085
return addLogger{
8186
logger.log(it)
@@ -86,6 +91,7 @@ class RegexBuilder {
8691
* Attach a [logger] to this builder using this [Logger] interface. The builder will emit logging messages to it as
8792
* the regex is built with the provided [prefix].
8893
*/
94+
@Deprecated("Logging will be removed in version 3.0")
8995
fun addLogger(prefix: String, logger: Logger): RegexBuilder {
9096
return addLogger(prefix) {
9197
logger.log(it)
@@ -96,6 +102,7 @@ class RegexBuilder {
96102
* Attach a logger to this builder using the provided log function. The builder will emit logging messages to it
97103
* as the regex is built with the prefix "RegexBuilder".
98104
*/
105+
@Deprecated("Logging will be removed in version 3.0")
99106
fun addLogger(logFunction: (s: String) -> Unit): RegexBuilder {
100107
this.logFunction = logFunction
101108
return this
@@ -105,6 +112,7 @@ class RegexBuilder {
105112
* Attach a logger to this builder using the provided log function. The builder will emit logging messages to it
106113
* as the regex is built with the provided [prefix].
107114
*/
115+
@Deprecated("Logging will be removed in version 3.0")
108116
fun addLogger(prefix: String, logFunction: (s: String) -> Unit): RegexBuilder {
109117
this.logFunction = logFunction
110118
this.prefix = prefix
@@ -467,6 +475,7 @@ class RegexBuilder {
467475
*
468476
* @return The current [RegexBuilder] object, for method chaining
469477
*/
478+
@Deprecated("The old syntax will be removed in version 3.0: please use group")
470479
fun startGroup(): RegexBuilder {
471480
openGroupCount++
472481
return addPart("startGroup()", "(")
@@ -483,6 +492,7 @@ class RegexBuilder {
483492
*
484493
* @return The current [RegexBuilder] object, for method chaining
485494
*/
495+
@Deprecated("The old syntax will be removed in version 3.0: please use nonCapturingGroup")
486496
fun startNonCapturingGroup(): RegexBuilder {
487497
openGroupCount++
488498
return addPart("startNonCapturingGroup()", "(?:")
@@ -501,6 +511,7 @@ class RegexBuilder {
501511
* @param name Name used to identify the group
502512
* @return The current [RegexBuilder] object, for method chaining
503513
*/
514+
@Deprecated("The old syntax will be removed in version 3.0: please use namedGroup")
504515
fun startNamedGroup(name: String): RegexBuilder {
505516
openGroupCount++
506517
return addPart("startNamedGroup(\"$name\")", "(?<$name>")
@@ -515,6 +526,7 @@ class RegexBuilder {
515526
* @throws RegexBuilderException A group has not been started
516527
*/
517528
@Throws(RegexBuilderException::class)
529+
@Deprecated("The old syntax will be removed in version 3.0: please use new group syntax")
518530
fun endGroup(quantifier: RegexQuantifier? = null): RegexBuilder {
519531
if (openGroupCount == 0) {
520532
throw RegexBuilderException(

src/main/kotlin/RegexBuilderException.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package uk.co.mainwave.regextoolboxkotlin
33
/**
44
* Exception thrown by [RegexBuilder] methods
55
*/
6+
@Deprecated("RegexBuilderException will be removed in version 3.0")
67
class RegexBuilderException(
78
message: String,
89
stringBuilder: StringBuilder

0 commit comments

Comments
 (0)