diff options
author | wm4 <wm4@nowhere> | 2013-01-13 16:13:13 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-01-13 17:32:39 +0100 |
commit | 20c9dfa61692d9ed741a91177d3fa185d73c02dd (patch) | |
tree | 8931b8f4036bbcc4941c8d372546b08dbd75e53b /core/bstr.c | |
parent | cbdee50f29e2d1c44453f7b5ed5d67296f7a16dc (diff) | |
download | mpv-20c9dfa61692d9ed741a91177d3fa185d73c02dd.tar.bz2 mpv-20c9dfa61692d9ed741a91177d3fa185d73c02dd.tar.xz |
Replace strsep() uses
This function sucks and apparently is not very portable (at least on
mingw, the configure check fails). Also remove the emulation of that
function from osdep/strsep*, and remove the configure check.
Diffstat (limited to 'core/bstr.c')
-rw-r--r-- | core/bstr.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/core/bstr.c b/core/bstr.c index 5d8a47e9ac..a472fbfb02 100644 --- a/core/bstr.c +++ b/core/bstr.c @@ -121,6 +121,19 @@ struct bstr bstr_split(struct bstr str, const char *sep, struct bstr *rest) return bstr_splice(str, 0, end); } +// Unlike with bstr_split(), tok is a string, and not a set of char. +// If tok is in str, return true, and: concat(out_left, tok, out_right) == str +// Otherwise, return false, and set out_left==str, out_right=="" +bool bstr_split_tok(bstr str, const char *tok, bstr *out_left, bstr *out_right) +{ + bstr bsep = bstr0(tok); + int pos = bstr_find(str, bsep); + if (pos < 0) + pos = str.len; + *out_left = bstr_splice(str, 0, pos); + *out_right = bstr_cut(str, pos + bsep.len); + return pos != str.len; +} struct bstr bstr_splice(struct bstr str, int start, int end) { |