@@ -7,67 +7,88 @@ import io.ksmt.expr.KIntNumExpr
77import io.ksmt.expr.KInterpretedValue
88import io.ksmt.expr.KStringLiteralExpr
99import io.ksmt.sort.KBoolSort
10+ import io.ksmt.sort.KStringSort
1011
1112object StringUtils {
1213
14+ const val STRING_FROM_CODE_UPPER_BOUND : Int = 196607
15+
1316 @JvmStatic
14- fun getStringLen (arg : KStringLiteralExpr ): KIntNumExpr = with (arg.ctx) {
17+ fun getStringLen (arg : KStringLiteralExpr ): KIntNumExpr = with (arg.ctx) {
1518 mkIntNum(arg.value.length)
1619 }
1720
1821 @JvmStatic
19- fun concatStrings (lhs : KStringLiteralExpr , rhs : KStringLiteralExpr ): KStringLiteralExpr = with (lhs.ctx) {
22+ fun concatStrings (lhs : KStringLiteralExpr , rhs : KStringLiteralExpr ): KStringLiteralExpr = with (lhs.ctx) {
2023 mkStringLiteral(lhs.value + rhs.value)
2124 }
2225
2326 @JvmStatic
24- fun isStringSuffix (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
27+ fun isStringSuffix (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
2528 mkBool(arg1.value.endsWith(arg0.value)).uncheckedCast()
2629 }
2730
2831 @JvmStatic
29- fun isStringPrefix (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
32+ fun isStringPrefix (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
3033 mkBool(arg1.value.startsWith(arg0.value)).uncheckedCast()
3134 }
3235
3336 @JvmStatic
34- fun stringLt (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
37+ fun stringLt (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
3538 mkBool(arg0.value < arg1.value).uncheckedCast()
3639 }
3740
3841 @JvmStatic
39- fun stringLe (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
42+ fun stringLe (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
4043 mkBool(arg0.value <= arg1.value).uncheckedCast()
4144 }
4245
4346 @JvmStatic
44- fun stringGt (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
47+ fun stringGt (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
4548 mkBool(arg0.value > arg1.value).uncheckedCast()
4649 }
4750
4851 @JvmStatic
49- fun stringGe (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
52+ fun stringGe (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
5053 mkBool(arg0.value >= arg1.value).uncheckedCast()
5154 }
5255
5356 @JvmStatic
54- fun stringContains (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
57+ fun stringContains (arg0 : KStringLiteralExpr , arg1 : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg0.ctx) {
5558 mkBool(arg0.value.contains(arg1.value)).uncheckedCast()
5659 }
5760
5861 @JvmStatic
59- fun stringToLowerCase (arg : KStringLiteralExpr ): KStringLiteralExpr = with (arg.ctx) {
62+ fun stringToLowerCase (arg : KStringLiteralExpr ): KStringLiteralExpr = with (arg.ctx) {
6063 mkStringLiteral(arg.value.lowercase())
6164 }
6265
6366 @JvmStatic
64- fun stringToUpperCase (arg : KStringLiteralExpr ): KStringLiteralExpr = with (arg.ctx) {
67+ fun stringToUpperCase (arg : KStringLiteralExpr ): KStringLiteralExpr = with (arg.ctx) {
6568 mkStringLiteral(arg.value.uppercase())
6669 }
6770
6871 @JvmStatic
69- fun stringReverse (arg : KStringLiteralExpr ): KStringLiteralExpr = with (arg.ctx) {
72+ fun stringReverse (arg : KStringLiteralExpr ): KStringLiteralExpr = with (arg.ctx) {
7073 mkStringLiteral(arg.value.reversed())
7174 }
7275
76+ @JvmStatic
77+ fun stringIsDigit (arg : KStringLiteralExpr ): KInterpretedValue <KBoolSort > = with (arg.ctx) {
78+ mkBool(arg.value.length == 1 && arg.value[0 ].isDigit()).uncheckedCast()
79+ }
80+
81+ @JvmStatic
82+ fun stringToCode (arg : KStringLiteralExpr ): KIntNumExpr = with (arg.ctx) {
83+ mkIntNum(arg.value.singleOrNull()?.code ? : - 1 )
84+ }
85+
86+ @JvmStatic
87+ fun stringToInt (arg : KStringLiteralExpr ): KIntNumExpr = with (arg.ctx) {
88+ return if (arg.value.isNotEmpty() && arg.value.all { it.isDigit() }) {
89+ mkIntNum(arg.value.toLongOrNull() ? : - 1 )
90+ } else {
91+ mkIntNum(- 1 )
92+ }
93+ }
7394}
0 commit comments