aboutsummaryrefslogtreecommitdiff
path: root/strutil.cc
diff options
context:
space:
mode:
Diffstat (limited to 'strutil.cc')
-rw-r--r--strutil.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/strutil.cc b/strutil.cc
index 1b99dff..632d151 100644
--- a/strutil.cc
+++ b/strutil.cc
@@ -174,6 +174,13 @@ bool HasWord(StringPiece str, StringPiece w) {
return true;
}
+StringPiece TrimPrefix(StringPiece str, StringPiece prefix) {
+ ssize_t size_diff = str.size() - prefix.size();
+ if (size_diff < 0 || str.substr(0, prefix.size()) != prefix)
+ return str;
+ return str.substr(prefix.size());
+}
+
StringPiece TrimSuffix(StringPiece str, StringPiece suffix) {
ssize_t size_diff = str.size() - suffix.size();
if (size_diff < 0 || str.substr(size_diff) != suffix)
@@ -500,7 +507,7 @@ string ConcatDir(StringPiece b, StringPiece n) {
return r;
}
-string EchoEscape(const string str) {
+string EchoEscape(const string &str) {
const char *in = str.c_str();
string buf;
for (; *in; in++) {