summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-02-09 12:43:33 +0100
committerwm4 <wm4@mplayer2.org>2012-02-09 12:44:19 +0100
commit70bf6720963b912bceabb9ae691b5f2b79685b19 (patch)
tree8c35d08e3f3a3c10136f7fd09899570e2375f7ce
parent4352f9feca37f1294c75e4bf2326e978f0e659df (diff)
downloadmpv-70bf6720963b912bceabb9ae691b5f2b79685b19.tar.bz2
mpv-70bf6720963b912bceabb9ae691b5f2b79685b19.tar.xz
bstr: add bstr_eatstart()
-rw-r--r--bstr.c8
-rw-r--r--bstr.h3
2 files changed, 11 insertions, 0 deletions
diff --git a/bstr.c b/bstr.c
index 809b02e665..fcf73ca828 100644
--- a/bstr.c
+++ b/bstr.c
@@ -198,6 +198,14 @@ struct bstr bstr_getline(struct bstr str, struct bstr *rest)
return str;
}
+bool bstr_eatstart(struct bstr *s, struct bstr prefix)
+{
+ if (!bstr_startswith(*s, prefix))
+ return false;
+ *s = bstr_cut(*s, prefix.len);
+ return true;
+}
+
void bstr_lower(struct bstr str)
{
for (int i = 0; i < str.len; i++)
diff --git a/bstr.h b/bstr.h
index 15ddf314f3..e8a34b4f2c 100644
--- a/bstr.h
+++ b/bstr.h
@@ -88,6 +88,9 @@ int bstr_parse_utf8_code_length(unsigned char b);
// line breaks are stripped.
struct bstr bstr_getline(struct bstr str, struct bstr *rest);
+// If s starts with prefix, return true and return the rest of the string in s.
+bool bstr_eatstart(struct bstr *s, struct bstr prefix);
+
bool bstr_case_startswith(struct bstr s, struct bstr prefix);
bool bstr_case_endswith(struct bstr s, struct bstr suffix);
struct bstr bstr_strip_ext(struct bstr str);