Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6742 for trunk


Ignore:
Timestamp:
09/12/11 16:19:31 (13 years ago)
Author:
gkronber
Message:

#1597 improved handling of empty rows.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/TableFileParser.cs

    r6740 r6742  
    334334    private void ParseValues() {
    335335      while (tokenizer.HasNext()) {
    336         List<object> row = new List<object>();
    337         object value = NextValue(tokenizer);
    338         if (value == null) { tokenizer.Next(); continue; }
    339         row.Add(value);
    340         while (tokenizer.HasNext() && tokenizer.Peek() == tokenizer.SeparatorToken) {
    341           Expect(tokenizer.SeparatorToken);
    342           row.Add(NextValue(tokenizer));
    343         }
    344         Expect(tokenizer.NewlineToken);
    345         // all rows have to have the same number of values           
    346         // the first row defines how many samples are needed
    347         if (rowValues.Count > 0 && rowValues[0].Count != row.Count) {
    348           Error("The first row of the dataset has " + rowValues[0].Count + " columns." +
    349             "\nLine " + tokenizer.CurrentLineNumber + " has " + row.Count + " columns.", "", tokenizer.CurrentLineNumber);
    350         }
    351         rowValues.Add(row);
    352         row = new List<object>();
     336        if (tokenizer.Peek() == tokenizer.NewlineToken) {
     337          tokenizer.Next();
     338        } else {
     339          List<object> row = new List<object>();
     340          object value = NextValue(tokenizer);
     341          row.Add(value);
     342          while (tokenizer.HasNext() && tokenizer.Peek() == tokenizer.SeparatorToken) {
     343            Expect(tokenizer.SeparatorToken);
     344            row.Add(NextValue(tokenizer));
     345          }
     346          Expect(tokenizer.NewlineToken);
     347          // all rows have to have the same number of values           
     348          // the first row defines how many samples are needed
     349          if (rowValues.Count > 0 && rowValues[0].Count != row.Count) {
     350            Error("The first row of the dataset has " + rowValues[0].Count + " columns." +
     351                  "\nLine " + tokenizer.CurrentLineNumber + " has " + row.Count + " columns.", "",
     352                  tokenizer.CurrentLineNumber);
     353          }
     354          rowValues.Add(row);
     355        }
    353356      }
    354357    }
    355358
    356359    private object NextValue(Tokenizer tokenizer) {
    357       if (tokenizer.Peek() == tokenizer.SeparatorToken) return string.Empty;
    358       if (tokenizer.Peek() == tokenizer.NewlineToken) return null;
     360      if (tokenizer.Peek() == tokenizer.SeparatorToken || tokenizer.Peek() == tokenizer.NewlineToken) return string.Empty;
    359361      Token current = tokenizer.Next();
    360362      if (current.type == TokenTypeEnum.Separator) {
Note: See TracChangeset for help on using the changeset viewer.