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
commite52c3fd7f441b2bd7c1dbf3972de7f672d897745 (patch)
tree5a0729270a5f064ad173fb673e360bea9d594d98 /utils/stringlib.h
parentc8e90b60480f450745d347e2975b0456563e93e3 (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