diff options
author | Kenneth Heafield <kheafiel@cluster10.lti.ece.cmu.local> | 2011-03-09 13:40:23 -0500 |
---|---|---|
committer | Kenneth Heafield <kheafiel@cluster10.lti.ece.cmu.local> | 2011-03-09 13:40:23 -0500 |
commit | 75310799a6ee82b742ba69abab951a74fd0d19fc (patch) | |
tree | 7be29bf130d75b478ef1f2449ca67a7eddfe0781 /klm/util/file_piece.cc | |
parent | b2a018f6a5fc34dc799aa41a05a16eb79aa95de1 (diff) |
kenlm sync
Diffstat (limited to 'klm/util/file_piece.cc')
-rw-r--r-- | klm/util/file_piece.cc | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/klm/util/file_piece.cc b/klm/util/file_piece.cc index 81eb9bb9..67681f7e 100644 --- a/klm/util/file_piece.cc +++ b/klm/util/file_piece.cc @@ -79,22 +79,22 @@ FilePiece::~FilePiece() { } StringPiece FilePiece::ReadLine(char delim) throw (GZException, EndOfFileException) { - const char *start = position_; - do { - for (const char *i = start; i < position_end_; ++i) { + size_t skip = 0; + while (true) { + for (const char *i = position_ + skip; i < position_end_; ++i) { if (*i == delim) { StringPiece ret(position_, i - position_); position_ = i + 1; return ret; } } - size_t skip = position_end_ - position_; + if (at_end_) { + if (position_ == position_end_) Shift(); + return Consume(position_end_); + } + skip = position_end_ - position_; Shift(); - start = position_ + skip; - } while (!at_end_); - StringPiece ret(position_, position_end_ - position_); - position_ = position_end_; - return ret; + } } float FilePiece::ReadFloat() throw(GZException, EndOfFileException, ParseNumberException) { @@ -186,6 +186,21 @@ template <class T> T FilePiece::ReadNumber() throw(GZException, EndOfFileExcepti return ret; } +const char *FilePiece::FindDelimiterOrEOF(const bool *delim) throw (GZException, EndOfFileException) { + size_t skip = 0; + while (true) { + for (const char *i = position_ + skip; i < position_end_; ++i) { + if (delim[static_cast<unsigned char>(*i)]) return i; + } + if (at_end_) { + if (position_ == position_end_) Shift(); + return position_end_; + } + skip = position_end_ - position_; + Shift(); + } +} + void FilePiece::Shift() throw(GZException, EndOfFileException) { if (at_end_) { progress_.Finished(); |