2016-05-04 06:18:24 +08:00
|
|
|
// Helper functions for working with wcstring.
|
2016-05-19 06:30:21 +08:00
|
|
|
#include "config.h" // IWYU pragma: keep
|
|
|
|
|
2014-09-22 10:18:56 +08:00
|
|
|
#include "wcstringutil.h"
|
2016-05-04 06:18:24 +08:00
|
|
|
#include "common.h"
|
2014-09-22 10:18:56 +08:00
|
|
|
|
|
|
|
typedef wcstring::size_type size_type;
|
|
|
|
|
2016-05-04 06:18:24 +08:00
|
|
|
wcstring_range wcstring_tok(wcstring& str, const wcstring& needle, wcstring_range last) {
|
2014-09-22 10:18:56 +08:00
|
|
|
size_type pos = last.second == wcstring::npos ? wcstring::npos : last.first;
|
|
|
|
if (pos != wcstring::npos && last.second != wcstring::npos) pos += last.second;
|
|
|
|
if (pos != wcstring::npos && pos != 0) ++pos;
|
2016-05-04 06:18:24 +08:00
|
|
|
if (pos == wcstring::npos || pos >= str.size()) {
|
2014-09-22 10:18:56 +08:00
|
|
|
return std::make_pair(wcstring::npos, wcstring::npos);
|
|
|
|
}
|
|
|
|
|
2016-05-04 06:18:24 +08:00
|
|
|
if (needle.empty()) {
|
2014-09-22 10:18:56 +08:00
|
|
|
return std::make_pair(pos, wcstring::npos);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = str.find_first_not_of(needle, pos);
|
|
|
|
if (pos == wcstring::npos) return std::make_pair(wcstring::npos, wcstring::npos);
|
|
|
|
|
|
|
|
size_type next_pos = str.find_first_of(needle, pos);
|
2016-05-04 06:18:24 +08:00
|
|
|
if (next_pos == wcstring::npos) {
|
2014-09-22 10:18:56 +08:00
|
|
|
return std::make_pair(pos, wcstring::npos);
|
|
|
|
}
|
2016-05-05 06:19:47 +08:00
|
|
|
|
|
|
|
str[next_pos] = L'\0';
|
|
|
|
return std::make_pair(pos, next_pos - pos);
|
2014-09-22 10:18:56 +08:00
|
|
|
}
|