Esempio n. 1
0
  public static void updateCharOffsetManyRegs(
      DynamicObject matchData, ByteList value, Encoding encoding) {
    assert RubyGuards.isRubyMatchData(matchData);
    if (Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated) return;

    final Region regs = Layouts.MATCH_DATA.getFields(matchData).region;
    int numRegs = regs.numRegs;

    if (Layouts.MATCH_DATA.getFields(matchData).charOffsets == null
        || Layouts.MATCH_DATA.getFields(matchData).charOffsets.numRegs < numRegs)
      Layouts.MATCH_DATA.getFields(matchData).charOffsets = new Region(numRegs);

    if (encoding.maxLength() == 1) {
      for (int i = 0; i < numRegs; i++) {
        Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[i] = regs.beg[i];
        Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[i] = regs.end[i];
      }
      Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated = true;
      return;
    }

    Pair[] pairs = new Pair[numRegs * 2];
    for (int i = 0; i < pairs.length; i++) pairs[i] = new Pair();

    int numPos = 0;
    for (int i = 0; i < numRegs; i++) {
      if (regs.beg[i] < 0) continue;
      pairs[numPos++].bytePos = regs.beg[i];
      pairs[numPos++].bytePos = regs.end[i];
    }

    updatePairs(value, encoding, pairs);

    Pair key = new Pair();
    for (int i = 0; i < regs.numRegs; i++) {
      if (regs.beg[i] < 0) {
        Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[i] =
            Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[i] = -1;
        continue;
      }
      key.bytePos = regs.beg[i];
      Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[i] =
          pairs[Arrays.binarySearch(pairs, key)].charPos;
      key.bytePos = regs.end[i];
      Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[i] =
          pairs[Arrays.binarySearch(pairs, key)].charPos;
    }

    Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated = true;
  }
Esempio n. 2
0
  public static void updateCharOffsetOnlyOneReg(
      DynamicObject matchData, ByteList value, Encoding encoding) {
    assert RubyGuards.isRubyMatchData(matchData);
    if (Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated) return;

    if (Layouts.MATCH_DATA.getFields(matchData).charOffsets == null
        || Layouts.MATCH_DATA.getFields(matchData).charOffsets.numRegs < 1)
      Layouts.MATCH_DATA.getFields(matchData).charOffsets = new Region(1);

    if (encoding.maxLength() == 1) {
      Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[0] =
          Layouts.MATCH_DATA.getFields(matchData).begin;
      Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[0] =
          Layouts.MATCH_DATA.getFields(matchData).end;
      Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated = true;
      return;
    }

    Pair[] pairs = new Pair[2];
    if (Layouts.MATCH_DATA.getFields(matchData).begin >= 0) {
      pairs[0] = new Pair();
      pairs[0].bytePos = Layouts.MATCH_DATA.getFields(matchData).begin;
      pairs[1] = new Pair();
      pairs[1].bytePos = Layouts.MATCH_DATA.getFields(matchData).end;
    }

    updatePairs(value, encoding, pairs);

    if (Layouts.MATCH_DATA.getFields(matchData).begin < 0) {
      Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[0] =
          Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[0] = -1;
      return;
    }
    Pair key = new Pair();
    key.bytePos = Layouts.MATCH_DATA.getFields(matchData).begin;
    Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[0] =
        pairs[Arrays.binarySearch(pairs, key)].charPos;
    key.bytePos = Layouts.MATCH_DATA.getFields(matchData).end;
    Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[0] =
        pairs[Arrays.binarySearch(pairs, key)].charPos;

    Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated = true;
  }
Esempio n. 3
0
  private void updateCharOffsetOnlyOneReg(ByteList value, Encoding encoding) {
    if (charOffsets == null || charOffsets.numRegs < 1) charOffsets = new Region(1);

    if (encoding.maxLength() == 1) {
      charOffsets.beg[0] = begin;
      charOffsets.end[0] = end;
      charOffsetUpdated = true;
      return;
    }

    Pair[] pairs = new Pair[2];
    pairs[0] = new Pair();
    pairs[0].bytePos = begin;
    pairs[1] = new Pair();
    pairs[1].bytePos = end;

    updatePairs(value, encoding, pairs);

    charOffsetUpdated = true;
  }
Esempio n. 4
0
  private void updateCharOffset() {
    if (charOffsetUpdated) return;

    ByteList value = str.getByteList();
    Encoding enc = value.getEncoding();

    if (regs == null) {
      updateCharOffsetOnlyOneReg(value, enc);
      return;
    }

    int numRegs = regs.numRegs;

    if (charOffsets == null || charOffsets.numRegs < numRegs) charOffsets = new Region(numRegs);

    if (enc.maxLength() == 1) {
      for (int i = 0; i < numRegs; i++) {
        charOffsets.beg[i] = regs.beg[i];
        charOffsets.end[i] = regs.end[i];
      }

      charOffsetUpdated = true;
      return;
    }

    Pair[] pairs = new Pair[numRegs * 2];
    for (int i = 0; i < pairs.length; i++) pairs[i] = new Pair();

    int numPos = 0;
    for (int i = 0; i < numRegs; i++) {
      if (regs.beg[i] < 0) continue;
      pairs[numPos++].bytePos = regs.beg[i];
      pairs[numPos++].bytePos = regs.end[i];
    }

    updatePairs(value, enc, pairs);

    charOffsetUpdated = true;
  }
Esempio n. 5
0
  private void updateCharOffsetManyRegs(ByteList value, Encoding encoding) {
    int numRegs = regs.numRegs;

    if (charOffsets == null || charOffsets.numRegs < numRegs) charOffsets = new Region(numRegs);

    if (encoding.maxLength() == 1) {
      for (int i = 0; i < numRegs; i++) {
        charOffsets.beg[i] = regs.beg[i];
        charOffsets.end[i] = regs.end[i];
      }
      return;
    }

    Pair[] pairs = new Pair[numRegs * 2];
    for (int i = 0; i < pairs.length; i++) pairs[i] = new Pair();

    int numPos = 0;
    for (int i = 0; i < numRegs; i++) {
      if (regs.beg[i] < 0) continue;
      pairs[numPos++].bytePos = regs.beg[i];
      pairs[numPos++].bytePos = regs.end[i];
    }

    updatePairs(value, encoding, pairs);

    Pair key = new Pair();
    for (int i = 0; i < regs.numRegs; i++) {
      if (regs.beg[i] < 0) {
        charOffsets.beg[i] = charOffsets.end[i] = -1;
        continue;
      }
      key.bytePos = regs.beg[i];
      charOffsets.beg[i] = pairs[Arrays.binarySearch(pairs, key)].charPos;
      key.bytePos = regs.end[i];
      charOffsets.end[i] = pairs[Arrays.binarySearch(pairs, key)].charPos;
    }
  }