Bool ReadLine(BaseFile* pFile, CDynamicArray<char>& arLine) { if (pFile->GetPosition() >= pFile->GetLength()) return false; char ch; Bool bEmpty, bEOF = false; // read line do { arLine.ResetCounter(); while (!bEOF) { if (!pFile->TryReadBytes(&ch, 1)) { if (!arLine.Append('\0')) return false; bEOF = true; } else if (ch == '\r' || ch == '\n') { if (!arLine.Append('\0')) return false; break; } else { if (!arLine.Append(ch)) return false; } } bEmpty = (arLine.GetElementCount() == 0); if (!bEmpty && arLine[0] == '\0') bEmpty = true; } while (bEmpty && !bEOF); return true; }
void WriteLine(CDynamicArray<char>& arLine, BaseFile* pFile) { pFile->WriteBytes(arLine.GetArray(), arLine.GetElementCount()); pFile->WriteBytes((void*)"\r\n", 2); arLine.ResetCounter(); }