[DEV] add line extractor in UString

This commit is contained in:
Edouard DUPIN 2013-06-30 17:04:15 +02:00
parent 090d2023a0
commit 01cc09e87d
2 changed files with 33 additions and 0 deletions

View File

@ -732,6 +732,38 @@ etk::UString etk::UString::Extract(int32_t _posStart, int32_t _posEnd) const
return out;
}
etk::UString etk::UString::ExtractLine(int32_t _pos) const
{
// search back : '\n'
int32_t startPos = FindBack('\n', _pos);
if (startPos == _pos) {
startPos = 0;
} else {
startPos++;
}
// search forward : '\n'
int32_t stopPos = _pos;
if (m_data[_pos] != '\n') {
stopPos = FindForward('\n', _pos);
if (stopPos == _pos) {
stopPos = Size();
}
}
etk::UString out;
if (startPos < 0) {
startPos = 0;
} else if (startPos >= Size() ) {
return out;
}
if (stopPos < 0) {
return out;
} else if (stopPos >= Size() ) {
stopPos = Size();
}
out.m_data = m_data.Extract(startPos, stopPos);
out.m_data.PushBack('\0');
return out;
}
etk::Vector<etk::UniChar> etk::UString::GetVector(void)
{

View File

@ -173,6 +173,7 @@ namespace etk
// Sting operation :
etk::UString Extract(int32_t _posStart=0, int32_t _posEnd=0x7FFFFFFF) const;
etk::UString ExtractLine(int32_t _pos=0) const;
/**
* @brief Transform the current string in an int64_t
* @return the requested int