Skip to content

Commit 1b38d12

Browse files
committed
Syntactic sugar for inRegex, toRegex operations
1 parent eb068cc commit 1b38d12

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

ksmt-core/src/main/kotlin/io/ksmt/KContext.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,7 @@ open class KContext(
21522152
/**
21532153
* Check if first string contains second one.
21542154
* */
2155+
@JvmName("strContains")
21552156
infix fun KExpr<KStringSort>.contains(other: KExpr<KStringSort>) = mkStringContains(this, other)
21562157

21572158
private val stringToRegexExprCache = mkAstInterner<KStringToRegexExpr>()
@@ -2170,6 +2171,16 @@ open class KContext(
21702171
KStringToRegexExpr(this, arg)
21712172
}
21722173

2174+
/**
2175+
* Create a regular expression based on a string expression.
2176+
* */
2177+
fun KExpr<KStringSort>.toRegex() = mkStringToRegex(this)
2178+
2179+
/**
2180+
* Create a regular expression based on a string expression.
2181+
* */
2182+
fun String.toRegex() = mkStringToRegex(this.expr)
2183+
21732184
private val stringInRegexExprCache = mkAstInterner<KStringInRegexExpr>()
21742185

21752186
/**
@@ -2187,6 +2198,22 @@ open class KContext(
21872198
KStringInRegexExpr(this, arg0, arg1)
21882199
}
21892200

2201+
/**
2202+
* Check if a string belongs to the language defined by the regular expression.
2203+
* */
2204+
infix fun KExpr<KStringSort>.inRegex(other: KExpr<KRegexSort>) = mkStringInRegex(this, other)
2205+
2206+
/**
2207+
* Check if a string belongs to the language defined by the regular expression.
2208+
* */
2209+
infix fun String.inRegex(other: KExpr<KRegexSort>) = mkStringInRegex(this.expr, other)
2210+
2211+
/**
2212+
* Check if a string belongs to the language defined by the regular expression.
2213+
* */
2214+
@JvmName("regexContains")
2215+
infix fun KExpr<KRegexSort>.contains(other: KExpr<KStringSort>) = mkStringInRegex(other, this)
2216+
21902217
private val regexLiteralCache = mkAstInterner<KRegexLiteralExpr>()
21912218

21922219
/**

0 commit comments

Comments
 (0)