From 6a1f3a66939308668ab8dce0d195afec16e02af9 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 14 Jul 2011 23:15:00 -0700 Subject: Major refactoring: upb_string is gone in favor of upb_strref. --- src/upb_strstream.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/upb_strstream.h') diff --git a/src/upb_strstream.h b/src/upb_strstream.h index e092b55..e57406e 100644 --- a/src/upb_strstream.h +++ b/src/upb_strstream.h @@ -21,8 +21,8 @@ extern "C" { struct _upb_stringsrc { upb_bytesrc bytesrc; - upb_string *str; - upb_strlen_t offset; + const char *str; + size_t len; }; typedef struct _upb_stringsrc upb_stringsrc; @@ -33,9 +33,9 @@ void upb_stringsrc_uninit(upb_stringsrc *s); // Resets the stringsrc to a state where it will vend the given string. The // stringsrc will take a reference on the string, so the caller need not ensure // that it outlives the stringsrc. A stringsrc can be reset multiple times. -void upb_stringsrc_reset(upb_stringsrc *s, upb_string *str); +void upb_stringsrc_reset(upb_stringsrc *s, const char *str, size_t len); -// Returns the upb_bytesrc* for this stringsrc. Invalidated by reset above. +// Returns the upb_bytesrc* for this stringsrc. upb_bytesrc *upb_stringsrc_bytesrc(upb_stringsrc *s); @@ -43,7 +43,8 @@ upb_bytesrc *upb_stringsrc_bytesrc(upb_stringsrc *s); struct _upb_stringsink { upb_bytesink bytesink; - upb_string *str; + char *str; + size_t len, size; }; typedef struct _upb_stringsink upb_stringsink; @@ -51,11 +52,14 @@ typedef struct _upb_stringsink upb_stringsink; void upb_stringsink_init(upb_stringsink *s); void upb_stringsink_uninit(upb_stringsink *s); -// Resets the stringsink to a state where it will append to the given string. -// The string must be newly created or recycled. The stringsink will take a -// reference on the string, so the caller need not ensure that it outlives the -// stringsink. A stringsink can be reset multiple times. -void upb_stringsink_reset(upb_stringsink *s, upb_string *str); +// Resets the sink's string to "str", which the sink takes ownership of. +// "str" may be NULL, which will make the sink allocate a new string. +void upb_stringsink_reset(upb_stringsink *s, char *str, size_t size); + +// Releases ownership of the returned string (which is "len" bytes long) and +// resets the internal string to be empty again (as if reset were called with +// NULL). +const char *upb_stringsink_release(upb_stringsink *s, size_t *len); // Returns the upb_bytesink* for this stringsrc. Invalidated by reset above. upb_bytesink *upb_stringsink_bytesink(); -- cgit v1.2.3