summaryrefslogtreecommitdiffstats
path: root/bstr.h
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-07-28 17:07:49 +0200
committerwm4 <wm4@mplayer2.org>2012-07-28 17:24:05 +0200
commit51e198c2a1e43b74ad35ef358628dcd8791158d9 (patch)
tree60f6c2255ed912a7a4866b71728104a2cb2442f1 /bstr.h
parent2793e7eb70a342b346788f83e1ed660c8e0d491e (diff)
parent7dfaaa95104a8e6dc024fddaf1b49c71768f1be7 (diff)
downloadmpv-51e198c2a1e43b74ad35ef358628dcd8791158d9.tar.bz2
mpv-51e198c2a1e43b74ad35ef358628dcd8791158d9.tar.xz
Merge remote-tracking branch 'origin/master'
Conflicts: .gitignore bstr.c cfg-mplayer.h defaultopts.c libvo/video_out.c The conflict in bstr.c is due to uau adding a bstr_getline function in commit 2ba8b91a97e7e8. This function already existed in this branch. While uau's function is obviously derived from mine, it's incompatible. His function preserves line breaks, while mine strips them. Add a bstr_strip_linebreaks function, fix all other uses of bstr_getline, and pick uau's implementation. In .gitignore, change vo_gl3_shaders.h to use an absolute path additional to resolving the merge conflict.
Diffstat (limited to 'bstr.h')
-rw-r--r--bstr.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/bstr.h b/bstr.h
index 688ed41771..d3434cfa13 100644
--- a/bstr.h
+++ b/bstr.h
@@ -36,14 +36,18 @@ struct bstr {
// demux_rtp.cpp (live555) C++ compilation workaround
#ifndef __cplusplus
+// If str.start is NULL, return NULL.
static inline char *bstrdup0(void *talloc_ctx, struct bstr str)
{
return talloc_strndup(talloc_ctx, (char *)str.start, str.len);
}
+// Return start = NULL iff that is true for the original.
static inline struct bstr bstrdup(void *talloc_ctx, struct bstr str)
{
- struct bstr r = { talloc_strndup(talloc_ctx, str.start, str.len), str.len };
+ struct bstr r = { NULL, str.len };
+ if (str.start)
+ r.start = talloc_memdup(talloc_ctx, str.start, str.len);
return r;
}
@@ -84,10 +88,13 @@ 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.
+// Line break characters are not stripped.
struct bstr bstr_getline(struct bstr str, struct bstr *rest);
+// Strip one trailing line break. This is intended for use with bstr_getline,
+// and will remove the trailing \n or \r\n sequence.
+struct bstr bstr_strip_linebreaks(struct bstr str);
+
// 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);
@@ -147,6 +154,11 @@ static inline int bstr_find0(struct bstr haystack, const char *needle)
return bstr_find(haystack, bstr(needle));
}
+static inline int bstr_eatstart0(struct bstr *s, char *prefix)
+{
+ return bstr_eatstart(s, bstr(prefix));
+}
+
#endif
// create a pair (not single value!) for "%.*s" printf syntax