@@ -9,12 +9,17 @@ object StdRegex {
99 override def evalRhs (pattern : Val , str : Val , ev : EvalScope , pos : Position ): Val = {
1010 val compiledPattern = Platform .getPatternFromCache(pattern.asString)
1111 val matcher = compiledPattern.matcher(str.asString)
12- var returnStr : Val = Val . Null (pos.noOffset)
12+ var returnStr : Val = null
1313 val captures = Array .newBuilder[Val .Str ]
1414 val groupCount = matcher.groupCount()
1515 while (matcher.find()) {
16- if (returnStr.isInstanceOf [Val .Null ]) {
17- returnStr = Val .Str (pos.noOffset, matcher.group(0 ))
16+ if (returnStr == null ) {
17+ val m = matcher.group(0 )
18+ if (m != null ) {
19+ returnStr = Val .Str (pos.noOffset, matcher.group(0 ))
20+ } else {
21+ returnStr = Val .Null (pos.noOffset)
22+ }
1823 }
1924 for (i <- 1 to groupCount) {
2025 val m = matcher.group(i)
@@ -27,7 +32,8 @@ object StdRegex {
2732 }
2833 val result = captures.result()
2934 Val .Obj .mk(pos.noOffset,
30- " string" -> new Obj .ConstMember (true , Visibility .Normal , returnStr),
35+ " string" -> new Obj .ConstMember (true , Visibility .Normal ,
36+ if (returnStr == null ) Val .Null (pos.noOffset) else returnStr),
3137 " captures" -> new Obj .ConstMember (true , Visibility .Normal , new Val .Arr (pos.noOffset, result))
3238 )
3339 }
0 commit comments