private static DynamicArray<String> tokenizePathFragment(String pathString, int lastIndex) {
    DynamicArray<String> results = new DynamicArray<String>();
    for (int i = lastIndex; i < pathString.length(); i++) {
      char c = pathString.charAt(i);
      if (c == '/' || c == '\\') {
        results.add(pathString.substring(lastIndex, i));
        lastIndex = i + 1;
      }
    }

    pathString = pathString.substring(lastIndex);
    results.add(pathString);
    return results;
  }
  private static DynamicArray<String> normalizePath(DynamicArray<String> pathElements) {
    DynamicArray<String> results = new DynamicArray<String>(pathElements.size());
    for (int i = 0; i < pathElements.size; i++) {
      String s = (String) pathElements.data[i];
      if (s.equals(".") || s.equals("/") || s.equals("\\") || s.equals("")) {
        // no-op
      } else if (s.equals("..")) {
        // TODO - Throw if no more elements
        results.remove(results.size() - 1);
      } else {
        results.add(s);
      }
    }

    return results;
  }
Beispiel #3
0
  private static String[] split(String fqn) {
    String theRest = fqn;
    DynamicArray<String> parts = new DynamicArray<String>();
    while (theRest != null) {
      int iParam = theRest.indexOf('<');
      int iDot = theRest.indexOf('.');
      int iArray = theRest.indexOf('[');
      String part;
      if (iParam == 0) {
        if (iArray > 0) {
          part = theRest.substring(0, iArray);
          theRest = iArray < theRest.length() ? theRest.substring(iArray) : null;
        } else {
          if (theRest.charAt(theRest.length() - 1) != '>') {
            throw new RuntimeException("\"" + theRest + "\" does not end with '>'");
          }
          part = theRest;
          theRest = null;
        }
      } else if (iArray == 0) {
        part = theRest.substring(0, 2);
        theRest = part.length() == theRest.length() ? null : theRest.substring(2);
      } else if (iParam > 0) {
        if (iDot > 0 && iDot < iParam) {
          part = theRest.substring(0, iDot);
          theRest = iDot + 1 < theRest.length() ? theRest.substring(iDot + 1) : null;
        } else {
          part = theRest.substring(0, iParam);
          theRest = iParam < theRest.length() ? theRest.substring(iParam) : null;
        }
      } else if (iDot > 0) {
        part = theRest.substring(0, iDot);
        theRest = iDot + 1 < theRest.length() ? theRest.substring(iDot + 1) : null;
      } else {
        part = theRest;
        theRest = null;
      }
      parts.add(StringCache.get(part));
    }

    return parts.toArray(new String[parts.size()]);
  }