Example #1
0
  /**
   * Splits the string and returns an array.
   *
   * @param str string to be split
   * @return array
   */
  private static String[] split(final String str) {
    final int l = str.length();
    final String[] split = new String[l];

    int s = 0;
    char delim = 0;
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < l; ++i) {
      final char c = str.charAt(i);
      if (delim == 0) {
        if (c == '\'' || c == '"') {
          delim = c;
        } else if (!XMLToken.isChar(c)
            && c != '@'
            && c != '='
            && c != '<'
            && c != '>'
            && c != '~') {
          if (sb.length() != 0) {
            split[s++] = sb.toString();
            sb.setLength(0);
          }
        } else {
          sb.append(c);
        }
      } else {
        if (c == delim) {
          delim = 0;
          if (sb.length() != 0) {
            split[s++] = sb.toString();
            sb.setLength(0);
          }
        } else {
          if (c != '\'' && c != '"') sb.append(c);
        }
      }
    }
    if (sb.length() != 0) split[s++] = sb.toString();
    return Array.copyOf(split, s);
  }