Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,27 @@ public Value find( Value request ) {
return response;
}

public Value findAll( Value request ) {
Pattern p = Pattern.compile( request.getFirstChild( "regex" ).strValue() );
Matcher m = p.matcher( request.strValue() );
Value response = Value.create();
ValueVector groups = response.getChildren( "group" );
boolean found = false;
while( m.find() ) {
found = true;
response.setValue( 1 );


groups.add( Value.create( (m.group( 0 ) == null) ? "" : m.group( 0 ) ) );
for( int i = 0; i < m.groupCount(); i++ ) {
groups.add( Value.create( (m.group( i + 1 ) == null) ? "" : m.group( i + 1 ) ) );
}

}
response.setValue( found ? 1 : 0 );
return response;
}

public String leftPad( Value request ) {
String orig = request.strValue();
int length = request.getFirstChild( "length" ).intValue();
Expand Down
1 change: 1 addition & 0 deletions packages/string-utils.ol
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ RequestResponse:
length(string)(int),
match(MatchRequest)(MatchResult),
find(MatchRequest)(MatchResult),
findAll(MatchRequest)(MatchResult),
replaceAll(ReplaceRequest)(string),
replaceFirst(ReplaceRequest)(string),
sort(StringItemList)(StringItemList),
Expand Down
1 change: 1 addition & 0 deletions packages/string_utils.ol
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ RequestResponse:
length(string)(int),
match(MatchRequest)(MatchResult),
find(MatchRequest)(MatchResult),
findAll(MatchRequest)(MatchResult),
replaceAll(ReplaceRequest)(string),
replaceFirst(ReplaceRequest)(string),
sort(StringItemList)(StringItemList),
Expand Down
6 changes: 6 additions & 0 deletions test/library/string-utils.ol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ service Main {

if( fmt@su( { format = "Up to {pct,number,percent}", locale = "en-us", data.pct = 0.6 } ) != "Up to 60%" )
throw( TestFailed, "Up to 60%" )

findAll@su( "Hello1 Hello2 Hello3" {
regex = "Hello\\d+"
})( result )
if ( #result.group != 3 )
throw( TestFailed, "findAll: Expected 3 groups, got " + #result.group )
}
}
}
Loading