本文整理汇总了Java中org.apache.oro.text.regex.Util类的典型用法代码示例。如果您正苦于以下问题:Java Util类的具体用法?Java Util怎么用?Java Util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Util类属于org.apache.oro.text.regex包,在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getFilesAndTrackNumbers
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
public static HashMap<AudioFile, Integer> getFilesAndTrackNumbers(ArrayList<AudioFile> files) {
HashMap filesToSet = new HashMap();
for (int j = 0; j < files.size(); j++) {
// Try to get a number from file name
String fileName = files.get(j).getNameWithoutExtension();
ArrayList<String> aux = new ArrayList<String>();
Util.split(aux, matcher, numberSeparatorPattern, fileName);
int trackNumber = 0;
int i = 0;
try {
while (trackNumber == 0 && i < aux.size()) {
trackNumber = Integer.parseInt(aux.get(i));
i++;
}
} catch (NumberFormatException e) {
}
if (trackNumber != 0)
filesToSet.put(files.get(j), trackNumber);
}
return filesToSet;
}
开发者ID:michellemulkey,项目名称:aTunes,代码行数:27,代码来源:RegexpUtils.java
示例2: doRereplace
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
protected String doRereplace( String _theString, String _theRE, String _theSubstr, boolean _casesensitive, boolean _replaceAll ) throws cfmRunTimeException{
int replaceCount = _replaceAll ? Util.SUBSTITUTE_ALL : 1;
PatternMatcher matcher = new Perl5Matcher();
Pattern pattern = null;
PatternCompiler compiler = new Perl5Compiler();
try {
if ( _casesensitive ){
pattern = compiler.compile( _theRE, Perl5Compiler.SINGLELINE_MASK );
}else{
pattern = compiler.compile( _theRE, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK );
}
} catch(MalformedPatternException e){ // definitely should happen since regexp is hardcoded
cfCatchData catchD = new cfCatchData();
catchD.setType( "Function" );
catchD.setMessage( "Internal Error" );
catchD.setDetail( "Invalid regular expression ( " + _theRE + " )" );
throw new cfmRunTimeException( catchD );
}
// Perform substitution and print result.
return Util.substitute(matcher, pattern, new Perl5Substitution( processSubstr( _theSubstr ) ), _theString, replaceCount );
}
开发者ID:OpenBD,项目名称:openbd-core,代码行数:25,代码来源:reReplace.java
示例3: realizeTemplate
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
/**
* Convert a template query by replacing the template areas with
* the given replacement string, which is generally a column name.
*/
private static String realizeTemplate( String template, String replacement ) {
String output = "";
PatternCompiler compiler = new Perl5Compiler();
PatternMatcher matcher = new Perl5Matcher();
try {
Pattern pattern = compiler.compile( kTemplateVariable );
output = Util.substitute( matcher, pattern, new StringSubstitution(replacement), template, Util.SUBSTITUTE_ALL );
}
catch( MalformedPatternException mpe ) {
System.err.println( "TextConverter.realizeTemplate(): " + mpe );
}
return( output );
}
开发者ID:tair,项目名称:tairwebapp,代码行数:20,代码来源:TextConverter.java
示例4: parseParts
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
/**
* @return Collection of strings extracted from input 'term', respecting quoted regions.
* Thus input = "foo 'bar baz' zip" will return "foo", "bar baz", "zip".
*/
private static Collection<String> parseParts( String term )
{
// first, get all the quoted strings.
Collection<String> searchParts = new ArrayList<String>();
String reducedTerm = extractPattern( "'([^']*)'", term, searchParts );
reducedTerm = extractPattern( "\"([^\"]*)\"", reducedTerm, searchParts );
// second, get all remaining non-empty terms.
if( false == reducedTerm.trim().equals( "" ) )
{
PatternCompiler compiler = new Perl5Compiler();
PatternMatcher matcher = new Perl5Matcher();
try {
Pattern pattern = compiler.compile( "\\s+" );
Util.split( searchParts, matcher, pattern, reducedTerm );
}
catch( MalformedPatternException mpe ) {
System.err.println( "TextConverter.parseParts(): " + mpe );
}
}
return( searchParts );
}
开发者ID:tair,项目名称:tairwebapp,代码行数:28,代码来源:TextConverter.java
示例5: extractPattern
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
/**
* Given a regular expression, remove matches from the input string and
* store them in the given Collection. Note: it is assumed that the
* regular expression has one parenthasized matching group which
* is the text to be placed in the Collection. Text outside of that
* group which still matches the regexp is deleted.
* @return String that is 'input' with all 'regex' matches deleted.
*/
private static String extractPattern(String regex, String input, Collection<String> found) {
String output = "";
PatternCompiler compiler = new Perl5Compiler();
PatternMatcher matcher = new Perl5Matcher();
try {
Pattern pattern = compiler.compile(regex);
PatternMatcherInput matcherInput = new PatternMatcherInput( input );
while( matcher.contains( matcherInput, pattern ) ) {
MatchResult result = matcher.getMatch();
if( result.groups() > 0 ) {
String sub = result.group( 1 );
found.add( sub );
}
}
output = Util.substitute( matcher, pattern, new StringSubstitution(), input, Util.SUBSTITUTE_ALL );
}
catch( MalformedPatternException mpe ) {
System.err.println( "TextConverter.extractPattern(): " + mpe );
}
return (output);
}
开发者ID:tair,项目名称:tairwebapp,代码行数:34,代码来源:TextConverter.java
示例6: filterString
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
private String filterString(String content) {
if (stringsToSkip == null || stringsToSkip.size() == 0) {
return content;
} else {
for (SubstitutionElement regex : stringsToSkip) {
emptySub.setSubstitution(regex.getSubstitute());
content = Util.substitute(JMeterUtils.getMatcher(), JMeterUtils.getPatternCache().getPattern(regex.getRegex()),
emptySub, content, Util.SUBSTITUTE_ALL);
}
}
return content;
}
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:13,代码来源:CompareAssertion.java
示例7: transformValue
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
@Override
public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException {
PatternMatcher pm = JMeterUtils.getMatcher();
Pattern pattern = null;
PatternCompiler compiler = new Perl5Compiler();
String input = prop.getStringValue();
if(input == null) {
return prop;
}
for(Entry<String, String> entry : getVariables().entrySet()){
String key = entry.getKey();
String value = entry.getValue();
if (regexMatch) {
try {
pattern = compiler.compile(constructPattern(value));
input = Util.substitute(pm, pattern,
new StringSubstitution(FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX),
input, Util.SUBSTITUTE_ALL);
} catch (MalformedPatternException e) {
log.warn("Malformed pattern " + value);
}
} else {
input = StringUtilities.substitute(input, value, FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX);
}
}
return new StringProperty(prop.getName(), input);
}
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:28,代码来源:ReplaceFunctionsWithStrings.java
示例8: generateTemplate
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
private Object[] generateTemplate(String rawTemplate) {
List<String> pieces = new ArrayList<>();
// String or Integer
List<Object> combined = new LinkedList<>();
PatternMatcher matcher = JMeterUtils.getMatcher();
Util.split(pieces, matcher, templatePattern, rawTemplate);
PatternMatcherInput input = new PatternMatcherInput(rawTemplate);
boolean startsWith = isFirstElementGroup(rawTemplate);
if (startsWith) {
pieces.remove(0);// Remove initial empty entry
}
Iterator<String> iter = pieces.iterator();
while (iter.hasNext()) {
boolean matchExists = matcher.contains(input, templatePattern);
if (startsWith) {
if (matchExists) {
combined.add(Integer.valueOf(matcher.getMatch().group(1)));
}
combined.add(iter.next());
} else {
combined.add(iter.next());
if (matchExists) {
combined.add(Integer.valueOf(matcher.getMatch().group(1)));
}
}
}
if (matcher.contains(input, templatePattern)) {
combined.add(Integer.valueOf(matcher.getMatch().group(1)));
}
return combined.toArray();
}
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:32,代码来源:RegexFunction.java
示例9: escapeHtml
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
public static String escapeHtml(String str) {
try {
PatternMatcher matcher = new Perl5Matcher();
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = compiler.compile("&(([a-z][a-zA-Z0-9]*)|(#\\d{2,6});)", Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK);
String tmp = Util.substitute(matcher, pattern, new Perl5Substitution("&$1"), str, Util.SUBSTITUTE_ALL);
return replaceChars(tmp, new char[] { '<', '>', '\"' }, new String[] { "<", ">", """ });
} catch (Exception e) {
return str;
}// won't happen
}
开发者ID:OpenBD,项目名称:openbd-core,代码行数:16,代码来源:string.java
示例10: escapeExpireUrl
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
private static String escapeExpireUrl(String expireURL){
Perl5Compiler compiler = new Perl5Compiler();
Perl5Matcher matcher = new Perl5Matcher();
Pattern pattern = null;
try{
pattern = compiler.compile( "([+?.])" );
expireURL = Util.substitute(matcher, pattern, new Perl5Substitution( "\\\\$1" ), expireURL, Util.SUBSTITUTE_ALL );
return com.nary.util.string.replaceString(expireURL,"*",".*");
}catch(Exception E){
return null;
}
}
开发者ID:OpenBD,项目名称:openbd-core,代码行数:14,代码来源:cfCACHE.java
示例11: substitute
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
/**
* Perform a substitution on the regular expression.
* @param input The string to substitute on
* @param argument The string which defines the substitution
* @param options The list of options for the match and replace.
* @return the result of the operation
* @throws BuildException on error
*/
public String substitute(final String input, final String argument, final int options)
throws BuildException {
// translate \1 to $1 so that the Perl5Substitution will work
final StringBuilder subst = new StringBuilder();
for (int i = 0; i < argument.length(); i++) {
char c = argument.charAt(i);
if (c == '$') {
subst.append('\\');
subst.append('$');
} else if (c == '\\') {
if (++i < argument.length()) {
c = argument.charAt(i);
final int value = Character.digit(c, DECIMAL);
if (value > -1) {
subst.append('$').append(value);
} else {
subst.append(c);
}
} else {
// TODO - should throw an exception instead?
subst.append('\\');
}
} else {
subst.append(c);
}
}
// Do the substitution
final Substitution s =
new Perl5Substitution(subst.toString(),
Perl5Substitution.INTERPOLATE_ALL);
return Util.substitute(matcher,
getCompiledPattern(options),
s,
input,
getSubsOptions(options));
}
开发者ID:apache,项目名称:ant,代码行数:46,代码来源:JakartaOroRegexp.java
示例12: generateTemplate
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
private Object[] generateTemplate(String rawTemplate) {
List<String> pieces = new ArrayList<String>();
// String or Integer
List<Object> combined = new LinkedList<Object>();
PatternMatcher matcher = JMeterUtils.getMatcher();
Util.split(pieces, matcher, templatePattern, rawTemplate);
PatternMatcherInput input = new PatternMatcherInput(rawTemplate);
boolean startsWith = isFirstElementGroup(rawTemplate);
if (startsWith) {
pieces.remove(0);// Remove initial empty entry
}
Iterator<String> iter = pieces.iterator();
while (iter.hasNext()) {
boolean matchExists = matcher.contains(input, templatePattern);
if (startsWith) {
if (matchExists) {
combined.add(Integer.valueOf(matcher.getMatch().group(1)));
}
combined.add(iter.next());
} else {
combined.add(iter.next());
if (matchExists) {
combined.add(Integer.valueOf(matcher.getMatch().group(1)));
}
}
}
if (matcher.contains(input, templatePattern)) {
combined.add(Integer.valueOf(matcher.getMatch().group(1)));
}
return combined.toArray();
}
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:32,代码来源:RegexFunction.java
示例13: transformValue
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
@Override
public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException {
PatternMatcher pm = JMeterUtils.getMatcher();
Pattern pattern = null;
PatternCompiler compiler = new Perl5Compiler();
String input = prop.getStringValue();
if(input == null) {
return prop;
}
for(Entry<String, String> entry : getVariables().entrySet()){
String key = entry.getKey();
String value = entry.getValue();
if (regexMatch) {
try {
pattern = compiler.compile("\\b("+value+")\\b");
input = Util.substitute(pm, pattern,
new StringSubstitution(FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX),
input, Util.SUBSTITUTE_ALL);
} catch (MalformedPatternException e) {
log.warn("Malformed pattern " + value);
}
} else {
input = StringUtilities.substitute(input, value, FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX);
}
}
return new StringProperty(prop.getName(), input);
}
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:28,代码来源:ReplaceFunctionsWithStrings.java
示例14: _replace
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
private static String _replace(String strInput, String strPattern, String replacement, boolean caseSensitive, boolean replaceAll) throws MalformedPatternException {
Pattern pattern = getPattern(strPattern, caseSensitive?16:17);
return Util.substitute(new Perl5Matcher(), pattern, new Perl5Substitution(replacement), strInput, replaceAll ? -1 : 1);
}
开发者ID:lucee,项目名称:Lucee4,代码行数:5,代码来源:Perl5Util.java
示例15: getSubsOptions
import org.apache.oro.text.regex.Util; //导入依赖的package包/类
/**
* Convert ant regexp substitution option to oro options.
*
* @param options the ant regexp options
* @return the oro substitution options
*/
protected int getSubsOptions(final int options) {
return RegexpUtil.hasFlag(options, REPLACE_ALL) ? Util.SUBSTITUTE_ALL
: 1;
}
开发者ID:apache,项目名称:ant,代码行数:11,代码来源:JakartaOroRegexp.java
注:本文中的org.apache.oro.text.regex.Util类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论