FreeCalypso > hg > sms-coding-utils
comparison libcoding/decode_helpers.c @ 27:7418ca2e9949
libcoding: add functions from freecalypso-tools/uptools/libcoding
that are needed for sms-pdu-decode & pcm-sms-decode
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 13 Jun 2024 02:29:29 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 26:c8cb05b69118 | 27:7418ca2e9949 |
|---|---|
| 1 /* | |
| 2 * This library module implements the is_decoded_char_ok() and emit_utf8_char() | |
| 3 * functions used by gsm7_to_ascii_or_ext() and ucs2_to_ascii_or_ext(). | |
| 4 */ | |
| 5 | |
| 6 #include <sys/types.h> | |
| 7 | |
| 8 is_decoded_char_ok(uni, ascii_ext) | |
| 9 unsigned uni; | |
| 10 { | |
| 11 unsigned upper_limit; | |
| 12 | |
| 13 /* weed out control chars first */ | |
| 14 if (uni < 0x20) | |
| 15 return(0); | |
| 16 if (uni >= 0x7F && uni <= 0x9F) | |
| 17 return(0); | |
| 18 /* see what range our output encoding allows */ | |
| 19 switch (ascii_ext) { | |
| 20 case 0: | |
| 21 upper_limit = 0x7F; | |
| 22 break; | |
| 23 case 1: | |
| 24 upper_limit = 0xFF; | |
| 25 break; | |
| 26 case 2: | |
| 27 upper_limit = 0xFFFF; | |
| 28 break; | |
| 29 default: | |
| 30 upper_limit = 0; | |
| 31 } | |
| 32 if (uni <= upper_limit) | |
| 33 return(1); | |
| 34 else | |
| 35 return(0); | |
| 36 } | |
| 37 | |
| 38 emit_utf8_char(uni, outp) | |
| 39 unsigned uni; | |
| 40 u_char *outp; | |
| 41 { | |
| 42 if (uni < 0x80) { | |
| 43 *outp = uni; | |
| 44 return(1); | |
| 45 } | |
| 46 if (uni < 0x800) { | |
| 47 outp[0] = 0xC0 | (uni >> 6); | |
| 48 outp[1] = 0x80 | (uni & 0x3F); | |
| 49 return(2); | |
| 50 } | |
| 51 if (uni < 0x10000) { | |
| 52 outp[0] = 0xE0 | (uni >> 12); | |
| 53 outp[1] = 0x80 | ((uni >> 6) & 0x3F); | |
| 54 outp[2] = 0x80 | (uni & 0x3F); | |
| 55 return(3); | |
| 56 } | |
| 57 outp[0] = 0xF0 | (uni >> 18); | |
| 58 outp[1] = 0x80 | ((uni >> 12) & 0x3F); | |
| 59 outp[2] = 0x80 | ((uni >> 6) & 0x3F); | |
| 60 outp[3] = 0x80 | (uni & 0x3F); | |
| 61 return(4); | |
| 62 } |
