15,8 → 15,6 |
*/ |
package net.brutex.xservices.ws.impl; |
|
|
|
import java.util.regex.Matcher; |
import java.util.regex.Pattern; |
|
35,27 → 33,31 |
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.StringService", serviceName = StringService.SERVICE_NAME) |
public class StringServiceImpl implements StringService { |
|
public StringReplaceType replaceRegEx(String res, String search, String replace, |
String flags) throws XServicesFault { |
|
int allflags = 0; |
if(flags.contains("i")) { |
allflags = allflags + Pattern.CASE_INSENSITIVE; |
public StringReplaceType replaceRegEx(String res, String search, |
String replace, String flags) throws XServicesFault { |
try { |
int allflags = 0; |
if (flags.contains("i")) { |
allflags = allflags + Pattern.CASE_INSENSITIVE; |
} |
Pattern pattern = Pattern.compile(search, allflags); |
Matcher matcher = pattern.matcher(res); |
int count = 0; |
while (matcher.find()) { |
count++; |
} |
if (flags.contains("g")) { |
return new StringReplaceType(matcher.replaceAll(replace), count); |
} else { |
if (count > 1) |
count = 1; |
return new StringReplaceType(matcher.replaceFirst(replace), |
count); |
} |
} catch (Exception e) { |
throw new XServicesFault(e); |
} |
Pattern pattern = Pattern.compile(search, allflags); |
Matcher matcher = pattern.matcher(res); |
int count = 0; |
while( matcher.find()) { |
count++; |
} |
if(flags.contains("g")) { |
return new StringReplaceType(matcher.replaceAll(replace), count); |
} else { |
if(count>1) count = 1; |
return new StringReplaceType(matcher.replaceFirst(replace), count); |
} |
|
|
} |
|
|
} |