aboutsummaryrefslogtreecommitdiff
path: root/strutil.cc
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2017-02-22 14:31:16 -0800
committerDan Willemsen <dwillemsen@google.com>2017-02-22 22:41:57 -0800
commite41c7556c22bda359c2b97cd98d59082110add95 (patch)
treef839deb8477c133f430ad142bbbdb4cabec661df /strutil.cc
parentf8e155865652181a504d7400afd25f35cf158472 (diff)
downloadkati-e41c7556c22bda359c2b97cd98d59082110add95.tar.gz
Add --color_warnings to make warnings/errors like clang
This adds new (WARN|KATI_WARN|ERROR)_LOC log macro variants that take a location as the first argument, and will prefix that location information to the warning/error lines. When --color_warnings is enabled, it reformats them to have a standard warning:/error: infix, and adds colors in order to match the warnings/errors produced by clang.
Diffstat (limited to 'strutil.cc')
-rw-r--r--strutil.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/strutil.cc b/strutil.cc
index b094198..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)