fix feature name splitting to split on last colon

This commit is contained in:
Eva Hasler 2012-03-26 21:17:10 +01:00
parent 6758881357
commit 614c98e682
2 changed files with 17 additions and 1 deletions

View File

@ -71,7 +71,7 @@ void FeatureDataIterator::readNext() {
StringPiece line = m_in->ReadLine(); StringPiece line = m_in->ReadLine();
m_next.push_back(FeatureDataItem()); m_next.push_back(FeatureDataItem());
for (TokenIter<AnyCharacter, true> token(line, AnyCharacter(" \t")); token; ++token) { for (TokenIter<AnyCharacter, true> token(line, AnyCharacter(" \t")); token; ++token) {
TokenIter<AnyCharacter,false> value(*token,AnyCharacter(":")); TokenIter<AnyCharacterLast,false> value(*token,AnyCharacterLast(":"));
if (!value) throw FileFormatException(m_in->FileName(), line.as_string()); if (!value) throw FileFormatException(m_in->FileName(), line.as_string());
StringPiece first = *value; StringPiece first = *value;
++value; ++value;

View File

@ -87,6 +87,22 @@ class AnyCharacter {
return StringPiece(std::find_first_of(in.data(), in.data() + in.size(), chars_.data(), chars_.data() + chars_.size()), 1); return StringPiece(std::find_first_of(in.data(), in.data() + in.size(), chars_.data(), chars_.data() + chars_.size()), 1);
} }
StringPiece FindLast(const StringPiece &in) const {
return StringPiece(std::find_end(in.data(), in.data() + in.size(), chars_.data(), chars_.data() + chars_.size()), 1);
}
private:
StringPiece chars_;
};
class AnyCharacterLast {
public:
explicit AnyCharacterLast(const StringPiece &chars) : chars_(chars) {}
StringPiece Find(const StringPiece &in) const {
return StringPiece(std::find_end(in.data(), in.data() + in.size(), chars_.data(), chars_.data() + chars_.size()), 1);
}
private: private:
StringPiece chars_; StringPiece chars_;
}; };