diff options
| author | Colin Walters <walters@verbum.org> | 2008-07-24 16:19:34 -0400 | 
|---|---|---|
| committer | Colin Walters <walters@verbum.org> | 2008-07-24 16:19:34 -0400 | 
| commit | d86df0220e37b9bf10878625664b44b5d79ee488 (patch) | |
| tree | 0f7d2cd535d35823499ecf262b5d24870522483c /dbus/dbus-string.c | |
| parent | 4cbc30465e4fba8026240945cac7a651fda5dca3 (diff) | |
| parent | 3bc6840b04108d895ec3962ed5933bb0edb20cf4 (diff) | |
Merge branch 'master' of ssh://walters@git.freedesktop.org/git/dbus/dbus
Diffstat (limited to 'dbus/dbus-string.c')
| -rw-r--r-- | dbus/dbus-string.c | 42 | 
1 files changed, 42 insertions, 0 deletions
| diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index cb108a8d..6b9b2bfe 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -1677,6 +1677,48 @@ _dbus_string_replace_len (const DBusString *source,    return TRUE;  } +/** + * Looks for the first occurance of a byte, deletes that byte, + * and moves everything after the byte to the beginning of a + * separate string.  Both strings must be initialized, valid + * strings. + * + * @param source the source string + * @param byte the byte to remove and split the string at + * @param tail the split off string + * @returns #FALSE if not enough memory or if byte could not be found + * + */ +dbus_bool_t +_dbus_string_split_on_byte (DBusString        *source, +                            unsigned char      byte, +                            DBusString        *tail) +{ +  int byte_position; +  char byte_string[2] = ""; +  int head_length; +  int tail_length; + +  byte_string[0] = (char) byte; + +  if (!_dbus_string_find (source, 0, byte_string, &byte_position)) +    return FALSE; + +  head_length = byte_position; +  tail_length = _dbus_string_get_length (source) - head_length - 1; + +  if (!_dbus_string_move_len (source, byte_position + 1, tail_length, +                              tail, 0)) +    return FALSE; + +  /* remove the trailing delimiter byte from the head now. +   */ +  if (!_dbus_string_set_length (source, head_length)) +    return FALSE; + +  return TRUE; +} +  /* Unicode macros and utf8_validate() from GLib Owen Taylor, Havoc   * Pennington, and Tom Tromey are the authors and authorized relicense.   */ | 
