org.joni.Regex.namedBackrefIterator()方法的使用及代码示例

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

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

Regex.namedBackrefIterator介绍

暂无

代码示例

代码示例来源: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.kill-bill.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

/**
 * returns all names in a regexp pattern as id (8859_1) strings
 * @return array of id strings.
 */
public String[] getNames() {
  int nameLength = pattern.numberOfNames();
  if (nameLength == 0) return EMPTY_STRING_ARRAY;
  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-core

/**
 * returns all names in a regexp pattern as id (8859_1) strings
 * @return array of id strings.
 */
public String[] getNames() {
  int nameLength = pattern.numberOfNames();
  if (nameLength == 0) return EMPTY_STRING_ARRAY;
  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: logzio/sawmill

private String getMatchedValue(byte[] message, Region region) {
  Iterator<NameEntry> iterator = pattern.namedBackrefIterator();
  // Skip the key
  iterator.next();
  // Running all over the value options and take the one that captured
  while (iterator.hasNext()) {
    NameEntry entry = iterator.next();
    for (int number : entry.getBackRefs()) {
      if (region.beg[number] >= 0) {
        return extractString(message, region.beg[number], region.end[number]);
      }
    }
  }
  return null;
}

代码示例来源: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: eiiches/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: 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: org.kill-bill.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: org.jruby/jruby-core

public IRubyObject[] getNamedBackrefValues(Ruby runtime) {
  final Regex pattern = getPattern();
  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: org.jruby/jruby-complete

public IRubyObject[] getNamedBackrefValues(Ruby runtime) {
  final Regex pattern = getPattern();
  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: 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.netbeans.api/org-jruby

/** rb_reg_names
 * 
 */
@JRubyMethod(name = "names", compat = CompatVersion.RUBY1_9)
public IRubyObject names() {
  if (pattern.numberOfNames() == 0) return getRuntime().newEmptyArray();
  RubyArray ary = getRuntime().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.jruby/jruby-core

/** 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: 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

/** 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.jruby/jruby-complete

@JRubyMethod
public RubyHash named_captures(ThreadContext context) {
  check();
  Ruby runtime = context.runtime;
  RubyHash hash = RubyHash.newHash(runtime);
  if (regexp == context.nil) return hash;
  for (Iterator<NameEntry> i = getPattern().namedBackrefIterator(); i.hasNext();) {
    NameEntry entry = i.next();
    RubyString key = RubyString.newStringShared(runtime, new ByteList(entry.name, entry.nameP, entry.nameEnd - entry.nameP, regexp.getEncoding(), false));
    boolean found = false;
    for (int b : entry.getBackRefs()) {
      IRubyObject value = RubyRegexp.nth_match(b, this);
      if (value.isTrue()) {
        hash.op_asetForString(runtime, key, value);
        found = true;
      }
    }
    if (!found) hash.op_asetForString(runtime, key, context.nil);
  }
  return hash;
}

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

/** rb_reg_named_captures
 * 
 */
@JRubyMethod(name = "named_captures", compat = CompatVersion.RUBY1_9)
public IRubyObject named_captures(ThreadContext context) {
  RubyHash hash = RubyHash.newHash(getRuntime());
  if (pattern.numberOfNames() == 0) return hash;
  for (Iterator<NameEntry> i = pattern.namedBackrefIterator(); i.hasNext();) {
    NameEntry e = i.next();
    int[]backrefs = e.getBackRefs();
    RubyArray ary = getRuntime().newArray(backrefs.length);
    for (int backref : backrefs) ary.append(RubyFixnum.newFixnum(getRuntime(), backref));
    hash.fastASet(RubyString.newStringShared(getRuntime(), e.name, e.nameP, e.nameEnd - e.nameP).freeze(context), ary);
  }
  return hash;
}

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

/** rb_reg_named_captures
 * 
 */
@JRubyMethod(name = "named_captures", compat = CompatVersion.RUBY1_9)
public IRubyObject named_captures(ThreadContext context) {
  check();
  RubyHash hash = RubyHash.newHash(getRuntime());
  if (pattern.numberOfNames() == 0) return hash;
  for (Iterator<NameEntry> i = pattern.namedBackrefIterator(); i.hasNext();) {
    NameEntry e = i.next();
    int[]backrefs = e.getBackRefs();
    RubyArray ary = getRuntime().newArray(backrefs.length);
    for (int backref : backrefs) ary.append(RubyFixnum.newFixnum(getRuntime(), backref));
    hash.fastASet(RubyString.newStringShared(getRuntime(), e.name, e.nameP, e.nameEnd - e.nameP).freeze(context), ary);
  }
  return hash;
}

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

/** rb_reg_named_captures
 * 
 */
@JRubyMethod(name = "named_captures", compat = CompatVersion.RUBY1_9)
public IRubyObject named_captures(ThreadContext context) {
  check();
  RubyHash hash = RubyHash.newHash(getRuntime());
  if (pattern.numberOfNames() == 0) return hash;
  for (Iterator<NameEntry> i = pattern.namedBackrefIterator(); i.hasNext();) {
    NameEntry e = i.next();
    int[]backrefs = e.getBackRefs();
    RubyArray ary = getRuntime().newArray(backrefs.length);
    for (int backref : backrefs) ary.append(RubyFixnum.newFixnum(getRuntime(), backref));
    hash.fastASet(RubyString.newStringShared(getRuntime(), e.name, e.nameP, e.nameEnd - e.nameP).freeze(context), ary);
  }
  return hash;
}

相关文章