charset: change GSM unpack to take number of characters rather than octets
Change interface to take the number of GSM characters rather than the number of octets, so that it is possible to distinguish the 7-character and 8-character cases.
This commit is contained in:

committed by
Dan Williams

parent
0a06dd324d
commit
d05c87e4c8
@@ -427,14 +427,13 @@ mm_charset_utf8_to_unpacked_gsm (const char *utf8, guint32 *out_len)
|
||||
|
||||
guint8 *
|
||||
gsm_unpack (const guint8 *gsm,
|
||||
guint32 gsm_len,
|
||||
guint32 nchars,
|
||||
guint8 start_offset, /* in _bits_ */
|
||||
guint32 *out_unpacked_len)
|
||||
{
|
||||
GByteArray *unpacked;
|
||||
int i, nchars;
|
||||
int i;
|
||||
|
||||
nchars = ((gsm_len * 8) - start_offset) / 7;
|
||||
unpacked = g_byte_array_sized_new (nchars + 1);
|
||||
|
||||
for (i = 0; i < nchars; i++) {
|
||||
|
@@ -53,7 +53,7 @@ guint8 *mm_charset_utf8_to_unpacked_gsm (const char *utf8, guint32 *out_len);
|
||||
guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, guint32 len);
|
||||
|
||||
guint8 *gsm_unpack (const guint8 *gsm,
|
||||
guint32 gsm_len,
|
||||
guint32 nchars, /* number of gsm characters, not octets */
|
||||
guint8 start_offset, /* in bits */
|
||||
guint32 *out_unpacked_len);
|
||||
|
||||
|
@@ -98,7 +98,7 @@ test_unpack_gsm7 (void *f, gpointer d)
|
||||
guint8 *unpacked;
|
||||
guint32 unpacked_len = 0;
|
||||
|
||||
unpacked = gsm_unpack (gsm, sizeof (gsm), 0, &unpacked_len);
|
||||
unpacked = gsm_unpack (gsm, (sizeof (gsm) * 8) / 7, 0, &unpacked_len);
|
||||
g_assert (unpacked);
|
||||
g_assert_cmpint (unpacked_len, ==, sizeof (expected));
|
||||
g_assert_cmpint (memcmp (unpacked, expected, unpacked_len), ==, 0);
|
||||
@@ -110,17 +110,16 @@ static void
|
||||
test_unpack_gsm7_7_chars (void *f, gpointer d)
|
||||
{
|
||||
static const guint8 gsm[] = { 0xF1, 0x7B, 0x59, 0x4E, 0xCF, 0xD7, 0x01 };
|
||||
static const guint8 expected[] = { 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x00 };
|
||||
static const guint8 expected[] = { 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75};
|
||||
guint8 *unpacked;
|
||||
guint32 unpacked_len = 0;
|
||||
|
||||
/* Tests the edge case where there are 7 bits left in the packed
|
||||
* buffer but those 7 bits do not contain a character. In this case
|
||||
* we expect a trailing NULL byte and the caller must know enough about
|
||||
* the intended message to remove it when required.
|
||||
* we expect to get the number of characters that were specified.
|
||||
*/
|
||||
|
||||
unpacked = gsm_unpack (gsm, sizeof (gsm), 0, &unpacked_len);
|
||||
unpacked = gsm_unpack (gsm, 7 , 0, &unpacked_len);
|
||||
g_assert (unpacked);
|
||||
g_assert_cmpint (unpacked_len, ==, sizeof (expected));
|
||||
g_assert_cmpint (memcmp (unpacked, expected, unpacked_len), ==, 0);
|
||||
@@ -153,7 +152,7 @@ test_unpack_gsm7_all_chars (void *f, gpointer d)
|
||||
guint32 unpacked_len = 0;
|
||||
int i;
|
||||
|
||||
unpacked = gsm_unpack (gsm, sizeof (gsm), 0, &unpacked_len);
|
||||
unpacked = gsm_unpack (gsm, (sizeof (gsm) * 8) / 7, 0, &unpacked_len);
|
||||
g_assert (unpacked);
|
||||
g_assert_cmpint (unpacked_len, ==, 148);
|
||||
|
||||
|
Reference in New Issue
Block a user