Skip to content

Commit

Permalink
kie-issues#364: DMN FEEL function split(string, delimiter, flags) sho…
Browse files Browse the repository at this point in the history
…uld be removed

Closes: apache/incubator-kie-issues#364
  • Loading branch information
jomarko committed Aug 16, 2023
1 parent 2219bf3 commit 0be537b
Showing 1 changed file with 1 addition and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,20 @@ public class SplitFunction
}

public FEELFnResult<List<String>> invoke(@ParameterName("string") String string, @ParameterName("delimiter") String delimiter) {
return invoke(string, delimiter, null);
}

public FEELFnResult<List<String>> invoke(@ParameterName("string") String string, @ParameterName("delimiter") String delimiter, @ParameterName("flags") String flags) {
if (string == null) {
return FEELFnResult.ofError( new InvalidParametersEvent( Severity.ERROR, "string", "cannot be null" ) );
}
if ( delimiter == null ) {
return FEELFnResult.ofError( new InvalidParametersEvent( Severity.ERROR, "delimiter", "cannot be null" ) );
}
try {
int f = processFlags( flags );
Pattern p = Pattern.compile( delimiter, f );
Pattern p = Pattern.compile( delimiter );
String[] split = p.split(string, -1);
return FEELFnResult.ofResult( Arrays.asList( split ) );
} catch ( PatternSyntaxException e ) {
return FEELFnResult.ofError( new InvalidParametersEvent( Severity.ERROR, "delimiter", "is invalid and can not be compiled", e ) );
} catch ( IllegalArgumentException t ) {
return FEELFnResult.ofError( new InvalidParametersEvent( Severity.ERROR, "flags", "contains unknown flags", t ) );
} catch ( Throwable t) {
return FEELFnResult.ofError( new InvalidParametersEvent( Severity.ERROR, "delimiter", "is invalid and can not be compiled", t ) );
}
}

private int processFlags(String flags) {
int f = 0;
if( flags != null ) {
if( flags.contains( "s" ) ) {
f |= Pattern.DOTALL;
}
if( flags.contains( "m" ) ) {
f |= Pattern.MULTILINE;
}
if( flags.contains( "i" ) ) {
f |= Pattern.CASE_INSENSITIVE;
}
}
return f;
}

}

0 comments on commit 0be537b

Please sign in to comment.