diff options
author | Martin Herkt <lachs0r@srsfckn.biz> | 2016-06-25 02:25:44 +0200 |
---|---|---|
committer | Martin Herkt <lachs0r@srsfckn.biz> | 2016-06-25 02:25:44 +0200 |
commit | ad56f2c46ac6deec86870ec10f2a11a644df07d4 (patch) | |
tree | 89f2d90c5586560911e67c872b530c77f151168d /misc/bstr.h | |
parent | 0536841647ef7931bffb4386d8ffbb5b2b568e8a (diff) | |
parent | 393bb2a565dc1e27812e1dd20747814892f80da2 (diff) | |
download | mpv-ad56f2c46ac6deec86870ec10f2a11a644df07d4.tar.bz2 mpv-ad56f2c46ac6deec86870ec10f2a11a644df07d4.tar.xz |
Merge branch 'master' into release/current
Diffstat (limited to 'misc/bstr.h')
-rw-r--r-- | misc/bstr.h | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/misc/bstr.h b/misc/bstr.h index f56516663c..2785520b87 100644 --- a/misc/bstr.h +++ b/misc/bstr.h @@ -116,10 +116,15 @@ int bstr_validate_utf8(struct bstr s); // talloc, with talloc_ctx as parent. struct bstr bstr_sanitize_utf8_latin1(void *talloc_ctx, struct bstr s); -// 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.) -// Line break characters are not stripped. -struct bstr bstr_getline(struct bstr str, struct bstr *rest); +// Return the text before the occurance of a character, and return it. Change +// *rest to point to the text following this character. (rest can be NULL.) +struct bstr bstr_splitchar(struct bstr str, struct bstr *rest, const char c); + +// Like bstr_splitchar. Trailing newlines are not stripped. +static inline struct bstr bstr_getline(struct bstr str, struct bstr *rest) +{ + return bstr_splitchar(str, rest, '\n'); +} // Strip one trailing line break. This is intended for use with bstr_getline, // and will remove the trailing \n or \r\n sequence. @@ -131,8 +136,10 @@ void bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...) void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list va) PRINTF_ATTRIBUTE(3, 0); -// If s starts with prefix, return true and return the rest of the string in s. +// If s starts/ends with prefix, return true and return the rest of the string +// in s. bool bstr_eatstart(struct bstr *s, struct bstr prefix); +bool bstr_eatend(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); @@ -200,11 +207,16 @@ static inline int bstr_find0(struct bstr haystack, const char *needle) return bstr_find(haystack, bstr0(needle)); } -static inline int bstr_eatstart0(struct bstr *s, const char *prefix) +static inline bool bstr_eatstart0(struct bstr *s, const char *prefix) { return bstr_eatstart(s, bstr0(prefix)); } +static inline bool bstr_eatend0(struct bstr *s, const char *prefix) +{ + return bstr_eatend(s, bstr0(prefix)); +} + // create a pair (not single value!) for "%.*s" printf syntax #define BSTR_P(bstr) (int)((bstr).len), ((bstr).start ? (char*)(bstr).start : "") |