END_TEST START_TEST(test_strTrimLeft) { char *string; string = strCreate(); strCopy(string, " \n\r\tfoobar"); strTrimLeft(string); fail_unless(strEquals(string, "foobar"), NULL); strCopy(string, "foobar \n\r\t"); strTrimLeft(string); fail_unless(strEquals(string, "foobar \n\r\t"), NULL); strCopy(string, "foobar"); strTrimLeft(string); fail_unless(strEquals(string, "foobar"), NULL); strCopy(string, " \n\r\tfoobar \r\t\n"); strTrimLeft(string); fail_unless(strEquals(string, "foobar \r\t\n"), NULL); strCopy(string, " \n\r\tfoo\t \n\rbar \r\t\n"); strTrimLeft(string); fail_unless(strEquals(string, "foo\t \n\rbar \r\t\n"), NULL); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // PBook::ReadEcoFile(): // Read an ECO (not EPD) format file. errorT PBook::ReadEcoFile () { MFile fp; if (fp.Open (FileName, FMODE_ReadOnly) != OK) { return ERROR_FileOpen; } ReadOnly = true; LineCount = 1; Position std_start; std_start.StdStart(); DString text; DString moves; ecoStringT ecoStr; ecoT ecoCode; int ch; errorT err = OK; bool done = false; // Loop to read in and add all positions: while (!done) { // Find the next ECO code: while (true) { ch = fp.ReadOneByte(); if (ch == EOF) { done = true; break; } if (ch == '\n') { LineCount++; } if (ch >= 'A' && ch <= 'E') { break; } if (ch == '#') { while (ch != '\n' && ch != EOF) { ch = fp.ReadOneByte(); } if (ch == EOF) { done = true; } LineCount++; } } if (done) { break; } // Read in the rest of the ECO code: ecoStr[0] = ch; ch = fp.ReadOneByte(); if (ch < '0' || ch > '9') { goto corrupt; } ecoStr[1] = ch; ch = fp.ReadOneByte(); if (ch < '0' || ch > '9') { goto corrupt; } ecoStr[2] = ch; ecoStr[3] = 0; // Now check for optional extra part of code, e.g. "A00a1": ch = fp.ReadOneByte(); if (ch >= 'a' && ch <= 'z') { ecoStr[3] = ch; ecoStr[4] = 0; ch = fp.ReadOneByte(); if (ch >= '1' && ch <= '4') { ecoStr[4] = ch; ecoStr[5] = 0; } } // Now put ecoCode in the text string and read the text in quotes: ecoCode = eco_FromString (ecoStr); eco_ToExtendedString (ecoCode, ecoStr); text.Clear(); text.Append ("eco ", ecoStr, " ["); // Find the start of the text: while ((ch = fp.ReadOneByte()) != '"') { if (ch == EOF) { goto corrupt; } } while ((ch = fp.ReadOneByte()) != '"') { if (ch == EOF) { goto corrupt; } text.AddChar ((char) ch); } text.Append ("]\n"); // Now read the position: moves.Clear(); char prev = 0; while ((ch = fp.ReadOneByte()) != '*') { if (ch == EOF) { goto corrupt; } if (ch == '\n') { ch = ' '; LineCount++; } if (ch != ' ' || prev != ' ') { moves.AddChar ((char) ch); } prev = ch; } Position pos (std_start); err = pos.ReadLine (moves.Data()); if (err != OK) { goto corrupt; } text.Append ("moves ", strTrimLeft (moves.Data()), "\n"); if (Insert (&pos, text.Data()) != OK) { // Position already exists: just ignore it. } } return OK; corrupt: return ERROR_Corrupt; }