コード例 #1
0
ファイル: ConfigFile.java プロジェクト: jimtoner/grape
  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;
  }