org.joni.Regex类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中org.joni.Regex类的一些代码示例,展示了Regex类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Regex类的具体详情如下:
包路径:org.joni.Regex
类名称:Regex

Regex介绍

暂无

代码示例

代码示例来源:origin: apache/hbase

public JoniRegexEngine(String regex, int flags) {
 this.regex = regex;
 byte[] b = Bytes.toBytes(regex);
 this.pattern = new Regex(b, 0, b.length, patternToJoniFlags(flags), encoding, Syntax.Java);
}

代码示例来源:origin: apache/hbase

@Override
public int compareTo(byte[] value, int offset, int length) {
 // Use subsequence match instead of full sequence match to adhere to the
 // principle of least surprise.
 Matcher m = pattern.matcher(value);
 return m.search(offset, length, pattern.getOptions()) < 0 ? 1 : 0;
}

代码示例来源:origin: stackoverflow.com

Regex r = new Regex("YOURREGEX");

// search for a match within a string
r.search("YOUR STRING YOUR STRING");

if(r.didMatch()){
// Prints "true" -- r.didMatch() is a boolean function
// that tells us whether the last search was successful
// in finding a pattern.
// r.left() returns left String , string before the matched pattern 
int index = r.left().length();
}

代码示例来源:origin: stackoverflow.com

Regex r = new Regex(@"^(\1.|^.)+$");

Console.WriteLine(r.IsMatch("aababc"));     // True
Console.WriteLine(r.IsMatch("1121231234")); // True
Console.WriteLine(r.IsMatch("iLoveRegEx")); // False

for (int n = 0; n <= 50; n++) {
  Match m = r.Match("".PadLeft(n));
  if (m.Success) {
    Console.WriteLine("{0} = sum(1..{1})", n, m.Groups[1].Length);
  }
}
// 1 = sum(1..1)
// 3 = sum(1..2)
// 6 = sum(1..3)
// 10 = sum(1..4)
// 15 = sum(1..5)
// 21 = sum(1..6)
// 28 = sum(1..7)
// 36 = sum(1..8)
// 45 = sum(1..9)

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

int begin = value.getBegin();
int range = begin + value.getRealSize();
final Matcher matcher = prepared.matcher(bytes, begin, range);
RubyArray ary = runtime.newArray();
if (pattern.numberOfCaptures() == 0) {
  while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) {
    end = positionEnd(matcher, enc, begin, range);
    RubyString substr = makeShared19(runtime, matcher.getBegin(), matcher.getEnd() - matcher.getBegin());
    substr.infectBy(tuFlags);
    ary.append(substr);
  context.setBackRef(match);
} else {
  context.setBackRef(runtime.getNil());

代码示例来源:origin: apache/phoenix

private boolean substr(byte[] srcBytes, int offset, int range, ImmutableBytesWritable outPtr) {
  Matcher matcher = pattern.matcher(srcBytes, 0, range);
  boolean ret = matcher.search(offset, range, Option.DEFAULT) >= 0;
  if (ret) {
    int len = matcher.getEnd() - matcher.getBegin();
    outPtr.set(srcBytes, matcher.getBegin(), len);
  } else {
    outPtr.set(ByteUtil.EMPTY_BYTE_ARRAY);
  }
  return ret;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public IRubyObject[] getNamedBackrefValues(Ruby runtime) {
  if (pattern.numberOfNames() == 0) return NULL_ARRAY;
  IRubyObject[] values = new IRubyObject[pattern.numberOfNames()];
  int j = 0;
  for (Iterator<NameEntry> i = pattern.namedBackrefIterator(); i.hasNext();) {
    NameEntry e = i.next();
    int nth = pattern.nameToBackrefNumber(e.name, e.nameP, e.nameEnd, regs);
    values[j++] = RubyRegexp.nth_match(nth, this);
  }
  return values;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/** rb_reg_names
 * 
 */
@JRubyMethod(name = "names", compat = CompatVersion.RUBY1_9)
public IRubyObject names(ThreadContext context) {
  check();
  if (pattern.numberOfNames() == 0) return getRuntime().newEmptyArray();
  RubyArray ary = context.runtime.newArray(pattern.numberOfNames());
  for (Iterator<NameEntry> i = pattern.namedBackrefIterator(); i.hasNext();) {
    NameEntry e = i.next();
    ary.append(RubyString.newStringShared(getRuntime(), e.name, e.nameP, e.nameEnd - e.nameP));
  }
  return ary;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

private static Regex getPreprocessedRegexpFromCache(Ruby runtime, ByteList bytes, Encoding enc, RegexpOptions options, ErrorMode mode) {
  Map<ByteList, Regex> cache = preprocessedPatternCache.get();
  Regex regex = cache.get(bytes);
  if (regex != null && regex.getEncoding() == enc && regex.getOptions() == options.toJoniOptions()) return regex;
  ByteList preprocessed = preprocess(runtime, bytes, enc, new Encoding[]{null}, ErrorMode.RAISE);
  regex = makeRegexp(runtime, preprocessed, options, enc);
  regex.setUserObject(preprocessed);
  cache.put(bytes, regex);
  return regex;
}

代码示例来源:origin: apache/phoenix

private boolean matches(byte[] bytes, int offset, int len) {
  int range = offset + len;
  Matcher matcher = pattern.matcher(bytes, offset, range);
  int ret = matcher.match(offset, range, Option.DEFAULT);
  return len == ret;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public String[] getNames() {
  int nameLength = pattern.numberOfNames();
  if (nameLength == 0) return NO_NAMES;
  String[] names = new String[nameLength];
  int j = 0;
  for (Iterator<NameEntry> i = pattern.namedBackrefIterator(); i.hasNext();) {
    NameEntry e = i.next();
    names[j++] = new String(e.name, e.nameP, e.nameEnd - e.nameP).intern();
  }
  return names;
}

代码示例来源:origin: org.jruby/jruby-complete

/** rb_reg_names
 *
 */
@JRubyMethod
public IRubyObject names(ThreadContext context) {
  check();
  final Ruby runtime = context.runtime;
  if (pattern.numberOfNames() == 0) return runtime.newEmptyArray();
  RubyArray ary = RubyArray.newBlankArray(runtime, pattern.numberOfNames());
  int index = 0;
  for (Iterator<NameEntry> i = pattern.namedBackrefIterator(); i.hasNext();) {
    NameEntry e = i.next();
    RubyString name = RubyString.newStringShared(runtime, e.name, e.nameP, e.nameEnd - e.nameP, pattern.getEncoding());
    ary.store(index++, name);
  }
  return ary;
}

代码示例来源:origin: org.dynjs/dynjs

public Region match(String str, int from) {
  byte[] strBytes = str.getBytes();
  Matcher matcher = this.pattern.matcher(strBytes, 0, strBytes.length);
  if (matcher.search(from, strBytes.length, 0) >= 0) {
    return matcher.getEagerRegion();
  }
  return null;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

private IRubyObject subBangNoIter(ThreadContext context, Regex pattern, RubyString repl) {
  int tuFlags = repl.flags;
  int range = value.getBegin() + value.getRealSize();
  Matcher matcher = pattern.matcher(value.getUnsafeBytes(), value.getBegin(), range);
  if (RubyRegexp.matcherSearch(context.runtime, matcher, value.getBegin(), range, Option.NONE) >= 0) {
    repl = RubyRegexp.regsub(repl, this, matcher, context.runtime.getKCode().getEncoding());
    RubyMatchData match = RubyRegexp.createMatchData(context, this, matcher, pattern);
    context.setBackRef(match);
    return subBangCommon(context, pattern, matcher, repl, tuFlags);
  } else {
    return context.setBackRef(context.runtime.getNil());
  }
}

代码示例来源:origin: net.thisptr/jackson-jq

private static String[] names(final Regex regex) {
    final String[] names = new String[regex.numberOfCaptures() + 1];
    if (regex.numberOfNames() == 0)
      return names;
    for (final Iterator<NameEntry> iter = regex.namedBackrefIterator(); iter.hasNext();) {
      final NameEntry backref = iter.next();
      final String name = new String(backref.name, backref.nameP, backref.nameEnd - backref.nameP, StandardCharsets.UTF_8);
      for (final int index : backref.getBackRefs()) {
        names[index] = name;
      }
    }
    return names;
  }
}

代码示例来源:origin: fbacchella/LogHub

@Override
public boolean configure(Properties properties) {
  try {
    // Generate pattern using both ASCII and UTF-8
    byte[] patternSrcBytesAscii = getBytesAscii(patternSrc);
    // the ascii pattern is generated only if the source pattern is pure ASCII
    if (patternSrcBytesAscii != null) {
      patternAscii = new Regex(patternSrcBytesAscii, 0, patternSrcBytesAscii.length, Option.NONE, USASCIIEncoding.INSTANCE);
    } else {
      patternAscii = null;
    }
    byte[] patternSrcBytesUtf8 = patternSrc.getBytes(StandardCharsets.UTF_8);
    patternUtf8 = new Regex(patternSrcBytesUtf8, 0, patternSrcBytesUtf8.length, Option.NONE, UTF8Encoding.INSTANCE);
    if (patternUtf8.numberOfCaptures() != patternUtf8.numberOfNames()) {
      logger.error("Can't have two captures with same name");
      return false;
    } else {
      return super.configure(properties);
    }
  } catch (SyntaxException e) {
    logger.error("Error parsing regex:" + Helpers.resolveThrowableException(e));
    logger.catching(Level.DEBUG, e);
    return false;
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

protected void handleFileEncodingComment(ByteList encodingLine) throws IOException {
  int realSize = encodingLine.getRealSize();
  int begin = encodingLine.getBegin();
  Matcher matcher = encodingRegexp.matcher(encodingLine.getUnsafeBytes(), begin, begin + realSize);
  int result = RubyRegexp.matcherSearch(parserSupport.getConfiguration().getRuntime(), matcher, begin, begin + realSize, Option.IGNORECASE);
  if (result < 0) return;
  int begs[] = matcher.getRegion().beg;
  int ends[] = matcher.getRegion().end;
  setEncoding(new ByteList(encodingLine.getUnsafeBytes(), begs[1], ends[1] - begs[1]));
}

代码示例来源:origin: apache/johnzon

@Override
public boolean test(final CharSequence string) {
  return regex.matcher(string.toString().getBytes(StandardCharsets.UTF_8))
     .search(0, string.length(), Option.NONE) > Matcher.FAILED;
}

代码示例来源:origin: org.jruby/jruby-complete

case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
  if (pattern.noNameGroupIsActive(Syntax.RUBY)) {
    no = c - '0';
    break;
        no = pattern.nameToBackrefNumber(sBytes, name, nameEnd, regs);
      } catch (JOniException je) {
        throw runtime.newIndexError(je.getMessage());
      throw runtime.newRuntimeError("invalid group name reference format");

代码示例来源:origin: org.jruby/jruby-complete

private static Regex makeRegexp(Ruby runtime, ByteList bytes, RegexpOptions options, Encoding enc) {
  try {
    int p = bytes.getBegin();
    return new Regex(bytes.getUnsafeBytes(), p, p + bytes.getRealSize(), options.toJoniOptions(), enc, Syntax.DEFAULT, runtime.getRegexpWarnings());
  } catch (Exception e) {
    RegexpSupport.raiseRegexpError19(runtime, bytes, enc, options, e.getMessage());
    return null; // not reached
  }
}

相关文章