aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/wcstringutil.cpp
diff options
context:
space:
mode:
authorGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2015-07-26 10:20:13 +0800
committerGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2015-07-26 10:20:13 +0800
commit3929e9de0e69666b37df87347d5ce15663e81347 (patch)
treeb2701c439c0260840ce1c68beaebf7de1178cc53 /src/wcstringutil.cpp
parent793e1afa084982dac92c4fe19e50c25e326a79c2 (diff)
parentf4d1657c22c81a7720a91026f915b80d2d6aa6e8 (diff)
Merge branch 'master' into iwyu
Diffstat (limited to 'src/wcstringutil.cpp')
-rw-r--r--src/wcstringutil.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/wcstringutil.cpp b/src/wcstringutil.cpp
new file mode 100644
index 00000000..e61e331b
--- /dev/null
+++ b/src/wcstringutil.cpp
@@ -0,0 +1,40 @@
+/** \file wcstringutil.cpp
+
+Helper functions for working with wcstring
+*/
+
+#include "config.h" // IWYU pragma: keep
+
+#include "wcstringutil.h"
+
+typedef wcstring::size_type size_type;
+
+wcstring_range wcstring_tok(wcstring& str, const wcstring &needle, wcstring_range last)
+{
+ 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;
+ if (pos == wcstring::npos || pos >= str.size())
+ {
+ return std::make_pair(wcstring::npos, wcstring::npos);
+ }
+
+ if (needle.empty())
+ {
+ 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);
+ if (next_pos == wcstring::npos)
+ {
+ return std::make_pair(pos, wcstring::npos);
+ }
+ else
+ {
+ str[next_pos] = L'\0';
+ return std::make_pair(pos, next_pos - pos);
+ }
+}