コード例 #1
0
ファイル: ConfigFile.java プロジェクト: jimtoner/grape
  public void setString(String sector, String key, String value) {
    dirty = true;

    Collection<Line> lines = getSectorLines(sector);
    if (lines == null) {
      Sector s = new Sector();
      s.name = sector;
      sectors.add(s);
      lines = s.lines;
    }

    for (Line l : lines) {
      if (l.key.equals(key)) {
        l.value = value;
        return;
      }
    }

    Line l = new Line();
    l.key = key;
    l.equalSign = true;
    l.value = value;
    lines.add(l);
  }
コード例 #2
0
ファイル: ConfigFile.java プロジェクト: jimtoner/grape
  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;
  }