Example #1
0
  private boolean parseExtlangs(StringTokenIterator itr, ParseStatus sts) {
    if (itr.isDone() || sts.isError()) {
      return false;
    }

    boolean found = false;

    while (!itr.isDone()) {
      String s = itr.current();
      if (!isExtlang(s)) {
        break;
      }
      found = true;
      if (extlangs.isEmpty()) {
        extlangs = new ArrayList<>(3);
      }
      extlangs.add(s);
      sts.parseLength = itr.currentEnd();
      itr.next();

      if (extlangs.size() == 3) {
        // Maximum 3 extlangs
        break;
      }
    }

    return found;
  }
Example #2
0
  private boolean parseRegion(StringTokenIterator itr, ParseStatus sts) {
    if (itr.isDone() || sts.isError()) {
      return false;
    }

    boolean found = false;

    String s = itr.current();
    if (isRegion(s)) {
      found = true;
      region = s;
      sts.parseLength = itr.currentEnd();
      itr.next();
    }

    return found;
  }
Example #3
0
  private boolean parseExtensions(StringTokenIterator itr, ParseStatus sts) {
    if (itr.isDone() || sts.isError()) {
      return false;
    }

    boolean found = false;

    while (!itr.isDone()) {
      String s = itr.current();
      if (isExtensionSingleton(s)) {
        int start = itr.currentStart();
        String singleton = s;
        StringBuilder sb = new StringBuilder(singleton);

        itr.next();
        while (!itr.isDone()) {
          s = itr.current();
          if (isExtensionSubtag(s)) {
            sb.append(SEP).append(s);
            sts.parseLength = itr.currentEnd();
          } else {
            break;
          }
          itr.next();
        }

        if (sts.parseLength <= start) {
          sts.errorIndex = start;
          sts.errorMsg = "Incomplete extension '" + singleton + "'";
          break;
        }

        if (extensions.isEmpty()) {
          extensions = new ArrayList<>(4);
        }
        extensions.add(sb.toString());
        found = true;
      } else {
        break;
      }
    }
    return found;
  }
Example #4
0
  private boolean parseVariants(StringTokenIterator itr, ParseStatus sts) {
    if (itr.isDone() || sts.isError()) {
      return false;
    }

    boolean found = false;

    while (!itr.isDone()) {
      String s = itr.current();
      if (!isVariant(s)) {
        break;
      }
      found = true;
      if (variants.isEmpty()) {
        variants = new ArrayList<>(3);
      }
      variants.add(s);
      sts.parseLength = itr.currentEnd();
      itr.next();
    }

    return found;
  }
Example #5
0
  private boolean parsePrivateuse(StringTokenIterator itr, ParseStatus sts) {
    if (itr.isDone() || sts.isError()) {
      return false;
    }

    boolean found = false;

    String s = itr.current();
    if (isPrivateusePrefix(s)) {
      int start = itr.currentStart();
      StringBuilder sb = new StringBuilder(s);

      itr.next();
      while (!itr.isDone()) {
        s = itr.current();
        if (!isPrivateuseSubtag(s)) {
          break;
        }
        sb.append(SEP).append(s);
        sts.parseLength = itr.currentEnd();

        itr.next();
      }

      if (sts.parseLength <= start) {
        // need at least 1 private subtag
        sts.errorIndex = start;
        sts.errorMsg = "Incomplete privateuse";
      } else {
        privateuse = sb.toString();
        found = true;
      }
    }

    return found;
  }