Exemple #1
0
  private static Sector parseSectorName(String line) {

    int index1 = line.indexOf('[');
    int index2 = line.indexOf(']');
    if (index1 < 0 || index2 < 0 || index1 > index2) return null;
    int index3 = StringUtil.find_first_of(line, COMMENT_STARTERS, index2);

    // 检查 space0
    int index = StringUtil.find_first_not_of(line, SPACES);
    if (index < 0 || index < index1) return null;

    // 检查 space3
    index = StringUtil.find_first_not_of(line, SPACES, index2 + 1);
    if ((index3 < 0 && index >= 0) || (index < index3)) return null;

    Sector ret = new Sector();
    ret.space0 = line.substring(0, index1);

    if (index3 >= 0) ret.space3 = line.substring(index2 + 1, index3);
    else ret.space3 = line.substring(index2 + 1);

    if (index3 >= 0) ret.comment = line.substring(index3);
    else ret.comment = null;

    ret.name = line.substring(index1 + 1, index2);
    index = StringUtil.find_first_not_of(ret.name, SPACES);
    if (index >= 0) {
      ret.space1 = ret.name.substring(0, index);
      ret.name = ret.name.substring(index);
      index = StringUtil.find_last_not_of(ret.name, SPACES);
      if (index >= 0) {
        ret.space2 = ret.name.substring(index + 1);
        ret.name = ret.name.substring(0, index + 1);
      } else {
        ret.space2 = null;
      }
    } else {
      ret.space1 = ret.name;
      ret.name = null;
      ret.space2 = null;
    }
    return ret;
  }
Exemple #2
0
  private static Line parseLine(String line) {
    Line ret = new Line();
    String s = line;

    // 注释
    int index = StringUtil.find_first_of(s, COMMENT_STARTERS);
    if (index >= 0) {
      ret.comment = s.substring(index);
      s = s.substring(0, index);
    } else {
      ret.comment = null;
    }

    // space0
    index = StringUtil.find_first_not_of(s, SPACES);
    if (index >= 0) {
      ret.space0 = s.substring(0, index);
      s = s.substring(index);
    } else {
      ret.space0 = s;
      s = "";
    }

    // space3
    index = StringUtil.find_last_not_of(s, SPACES);
    if (index >= 0) {
      ret.space3 = s.substring(index + 1);
      s = s.substring(0, index + 1);
    } else {
      ret.space3 = s;
      s = "";
    }

    // '='
    index = s.indexOf('=');
    String strKey, strValue;
    if (index >= 0) {
      ret.equalSign = true;
      strKey = s.substring(0, index);
      strValue = s.substring(index + 1);
    } else {
      ret.equalSign = false;
      strKey = s;
      strValue = "";
    }

    // key, space1
    index = StringUtil.find_last_not_of(strKey, SPACES);
    if (index >= 0) {
      ret.space1 = strKey.substring(index + 1);
      ret.key = strKey.substring(0, index + 1);
    } else {
      ret.space1 = strKey;
      ret.key = "";
    }

    // space2, value
    index = StringUtil.find_first_not_of(strValue, " \t");
    if (index >= 0) {
      ret.space2 = strValue.substring(0, index);
      ret.value = strValue.substring(index);
    } else {
      ret.space2 = strValue;
      ret.value = null;
    }
    return ret;
  }