diff options
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r-- | epan/tvbuff.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c index c6d5c8c6fa..70a0c2150e 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -1808,6 +1808,35 @@ tvb_get_string(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, const } static guint8 * +tvb_get_string_8859_1(wmem_allocator_t *scope, tvbuff_t *tvb, gint offset, gint length) +{ + wmem_strbuf_t *str; + + str = wmem_strbuf_new(scope, ""); + + while (length > 0) { + guint8 ch = tvb_get_guint8(tvb, offset); + + if (ch < 0x80) + wmem_strbuf_append_c(str, ch); + else { + /* + * Note: we assume here that the code points + * 0x80-0x9F are used for C1 control characters, + * and thus have the same value as the corresponding + * Unicode code points. + */ + wmem_strbuf_append_unichar(str, ch); + } + offset++; + length--; + } + + /* XXX, discarding constiness, should we have some function which "take-over" strbuf->str (like when strbuf is no longer needed) */ + return (guint8 *) wmem_strbuf_get_str(str); +} + +static guint8 * tvb_get_string_unichar2(wmem_allocator_t *scope, tvbuff_t *tvb, gint offset, gint length, const gunichar2 table[0x80]) { wmem_strbuf_t *str; @@ -1911,6 +1940,15 @@ tvb_get_string_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, strbuf = tvb_get_string_unichar2(scope, tvb, offset, length, charset_table_cp1250); break; + case ENC_ISO_8859_1: + /* + * ISO 8859-1 printable code point values are equal + * to the equivalent Unicode code point value, so + * no translation table is needed. + */ + strbuf = tvb_get_string_8859_1(scope, tvb, offset, length); + break; + case ENC_ISO_8859_2: strbuf = tvb_get_string_unichar2(scope, tvb, offset, length, charset_table_iso_8859_2); break; @@ -1991,6 +2029,17 @@ tvb_get_stringz(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint } static guint8 * +tvb_get_stringz_8859_1(wmem_allocator_t *scope, tvbuff_t *tvb, gint offset, gint *lengthp) +{ + guint size; + + /* XXX, convertion between signed/unsigned integer */ + *lengthp = size = tvb_strsize(tvb, offset); + + return tvb_get_string_8859_1(scope, tvb, offset, size); +} + +static guint8 * tvb_get_stringz_unichar2(wmem_allocator_t *scope, tvbuff_t *tvb, gint offset, gint *lengthp, const gunichar2 table[0x80]) { guint size; @@ -2030,6 +2079,15 @@ tvb_get_stringz_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, g strptr = tvb_get_stringz_unichar2(scope, tvb, offset, lengthp, charset_table_cp1250); break; + case ENC_ISO_8859_1: + /* + * ISO 8859-1 printable code point values are equal + * to the equivalent Unicode code point value, so + * no translation table is needed. + */ + strptr = tvb_get_stringz_8859_1(scope, tvb, offset, lengthp); + break; + case ENC_ISO_8859_2: strptr = tvb_get_stringz_unichar2(scope, tvb, offset, lengthp, charset_table_iso_8859_2); break; |