summaryrefslogtreecommitdiff
path: root/utils/stringlib.h
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-12 01:19:27 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-12 01:19:27 +0000
commit734d2f82f79c3bfa4ee8d57d0ab6c1eafa6b91cc (patch)
treeb5b7a301e52927ed6bfd3c3e0b056bb4a9af920a /utils/stringlib.h
parentaa306c4142789fc2462dc65d94321e026b722ed8 (diff)
fidget
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@532 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'utils/stringlib.h')
-rw-r--r--utils/stringlib.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/utils/stringlib.h b/utils/stringlib.h
index 84e95d44..4f79eb31 100644
--- a/utils/stringlib.h
+++ b/utils/stringlib.h
@@ -20,22 +20,22 @@
#include <sstream>
#include <algorithm>
-inline std::size_t skip_ws(std::string const& s,std::size_t starting=0,char const* ws=" \t\n\r") {
+namespace {
+const char c_isspace[]=" \t\n\r\f\v"; // somewhat ridiculous, including characters nobody uses.
+const char common_isspace[]=" \t\n\r"; // even \n\r is borderline, but maybe you pass multiline DOS format text.
+}
+
+inline std::size_t skip_ws(std::string const& s,std::size_t starting=0,char const* ws=common_isspace) {
return s.find_first_not_of(ws,starting);
}
// returns position of end of all non-ws chars before ending, i.e. string(s.begin()+skip_ws(s),s.begin()+trailing_ws(s)) strips both ends
-inline std::size_t trailing_ws(std::string const& s,std::size_t ending=std::string::npos,char const* ws=" \t\n\r") {
+inline std::size_t trailing_ws(std::string const& s,std::size_t ending=std::string::npos,char const* ws=common_isspace) {
std::size_t n=s.find_last_not_of(ws,ending);
if (n==std::string::npos) return n;
else return n+1;
}
-//TEST: if string is all whitespace, make sure that string(a+npos,a+npos) can't segfault (i.e. won't access any memory because begin==end)
-inline std::string strip_ws(std::string const& s) {
- return std::string(s.begin()+skip_ws(s),s.begin()+trailing_ws(s));
-}
-
inline bool is_single_line(std::string const& line) {
return std::count(line.begin(),line.end(),'\n')==0; // but we want to allow terminal newlines/blanks