diff options
author | Anders Broman <anders.broman@ericsson.com> | 2007-12-09 17:41:16 +0000 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2007-12-09 17:41:16 +0000 |
commit | e5f48395f18dcdfe5a65a0163b750179aad64b33 (patch) | |
tree | d8be6b7a292ac5589d0206d140f5a92fb8fa7776 /epan/tvbuff.c | |
parent | 006d1c446e03af37c260693076d501b6fb5aa887 (diff) |
Move the routines tvb_skip_wsp() to tvbuff.c
svn path=/trunk/; revision=23818
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r-- | epan/tvbuff.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c index a7a315684a..70a97a8bb0 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -2556,6 +2556,60 @@ tvb_find_line_end_unquoted(tvbuff_t *tvb, gint offset, int len, } /* + * Copied from the mgcp dissector. (This function should be moved to /epan ) + * tvb_skip_wsp - Returns the position in tvb of the first non-whitespace + * character following offset or offset + maxlength -1 whichever + * is smaller. + * + * Parameters: + * tvb - The tvbuff in which we are skipping whitespace. + * offset - The offset in tvb from which we begin trying to skip whitespace. + * maxlength - The maximum distance from offset that we may try to skip + * whitespace. + * + * Returns: The position in tvb of the first non-whitespace + * character following offset or offset + maxlength -1 whichever + * is smaller. + */ +gint tvb_skip_wsp(tvbuff_t* tvb, gint offset, gint maxlength) +{ + gint counter = offset; + gint end = offset + maxlength,tvb_len; + guint8 tempchar; + + /* Get the length remaining */ + tvb_len = tvb_length(tvb); + end = offset + maxlength; + if (end >= tvb_len) + { + end = tvb_len; + } + + /* Skip past spaces, tabs, CRs and LFs until run out or meet something else */ + for (counter = offset; + counter < end && + ((tempchar = tvb_get_guint8(tvb,counter)) == ' ' || + tempchar == '\t' || tempchar == '\r' || tempchar == '\n'); + counter++); + + return (counter); +} + +gint tvb_skip_wsp_return(tvbuff_t* tvb, gint offset){ + gint counter = offset; + gint end; + guint8 tempchar; + end = 0; + + for(counter = offset; counter > end && + ((tempchar = tvb_get_guint8(tvb,counter)) == ' ' || + tempchar == '\t' || tempchar == '\n' || tempchar == '\r'); counter--); + counter++; + return (counter); +} + + +/* * Format a bunch of data from a tvbuff as bytes, returning a pointer * to the string with the formatted data, with "punct" as a byte * separator. |