From b4f53143b0e05fd3061cdf2e65e17a6a2904090b Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 24 Jul 2015 00:50:58 -0700 Subject: Migrate source files into src/ directory This change moves source files into a src/ directory, and puts object files into an obj/ directory. The Makefile and xcode project are updated accordingly. Fixes #1866 --- src/wcstringutil.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/wcstringutil.cpp (limited to 'src/wcstringutil.cpp') diff --git a/src/wcstringutil.cpp b/src/wcstringutil.cpp new file mode 100644 index 00000000..51ec1a1c --- /dev/null +++ b/src/wcstringutil.cpp @@ -0,0 +1,40 @@ +/** \file wcstringutil.cpp + +Helper functions for working with wcstring +*/ + +#include "config.h" + +#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); + } +} -- cgit v1.2.3