summaryrefslogtreecommitdiffstats
path: root/bstr.h
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-01-01 17:28:01 +0100
committerwm4 <wm4@mplayer2.org>2012-01-18 04:24:38 +0100
commitf88674509e0a4f90180f26a9b8aa6879df38b056 (patch)
tree6e231b0d533c2b4fc5525b4e3bfaf800097d8cdd /bstr.h
parentbba96eca428711fa16aac0a9af096dc65fe6701f (diff)
downloadmpv-f88674509e0a4f90180f26a9b8aa6879df38b056.tar.bz2
mpv-f88674509e0a4f90180f26a9b8aa6879df38b056.tar.xz
bstr: add some utility functions
bstr_strip_ext and bstr_get_ext were taken from find_subfiles.c. bstr_cut is extended to work like bstr_splice: passing a negative argument will start counting from the end of the string, e.g. bstr_cut("abc", -2) == "bc"
Diffstat (limited to 'bstr.h')
-rw-r--r--bstr.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/bstr.h b/bstr.h
index 8b1644cac0..15ddf314f3 100644
--- a/bstr.h
+++ b/bstr.h
@@ -82,8 +82,25 @@ int bstr_decode_utf8(struct bstr str, struct bstr *out_next);
// On error, -1 is returned. On success, it returns a value in the range [1, 4].
int bstr_parse_utf8_code_length(unsigned char b);
+// Return the text before the next line break, and return it. Change *rest to
+// point to the text following this line break. (rest can be NULL.)
+// Unlike bstr_splitlines, possible \r characters coming from files with CR+LF
+// line breaks are stripped.
+struct bstr bstr_getline(struct bstr str, struct bstr *rest);
+
+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);
+struct bstr bstr_get_ext(struct bstr s);
+
+
static inline struct bstr bstr_cut(struct bstr str, int n)
{
+ if (n < 0) {
+ n += str.len;
+ if (n < 0)
+ n = 0;
+ }
if (n > str.len)
n = str.len;
return (struct bstr){str.start + n, str.len - n};