Changeset 453 for branches/thune/thread_safe/encoding.c
- Timestamp:
- 08/25/07 22:49:09 (15 months ago)
- Files:
-
- 1 modified
-
branches/thune/thread_safe/encoding.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/thune/thread_safe/encoding.c
r447 r453 1 1 /*============================================================================ 2 2 Urlan Interpreter 3 Copyright (C) 2005-200 6Karl Robillard3 Copyright (C) 2005-2007 Karl Robillard 4 4 5 5 This library is free software; you can redistribute it and/or … … 31 31 Returns number of characters copied. 32 32 */ 33 int copyUtf16ToAscii( char* dest, const uint16_t* src, int len ) 33 int copyUcs2ToUtf8( char* dest, const uint16_t* src, int len ) 34 { 35 // TODO: Prevent overflow of dest. 36 const char* start; 37 const uint16_t* end; 38 uint16_t c; 39 40 start = dest; 41 end = src + len; 42 43 while( src != end ) 44 { 45 c = *src++; 46 if( c > 127 ) 47 { 48 if( c > 0x07ff ) 49 { 50 *dest++ = 0xE0 | (c >> 12); 51 *dest++ = 0x80 | ((c >> 6) & 0x3f); 52 c = 0x80 | (c & 0x3f); 53 } 54 else 55 { 56 *dest++ = 0xC0 | (c >> 6); 57 c = 0x80 | (c & 0x3f); 58 } 59 } 60 *dest++ = (char) c; 61 } 62 return dest - start; 63 } 64 65 66 #if 0 67 int copyUcs2ToAscii( char* dest, const uint16_t* src, int len ) 34 68 { 35 69 const uint16_t* end; … … 47 81 return len; 48 82 } 83 #endif 49 84 50 85 51 #ifndef UR_CONFIG_UDS52 86 /* 53 87 Returns number of characters copied. … … 87 121 case UR_ENC_UTF16: 88 122 count >>= 1; 89 strN = ur_makeBinary( count , &bin );90 bin->used = copyU tf16ToAscii( bin->ptr.c,91 (uint16_t*) cpA, count );123 strN = ur_makeBinary( count * 2, &bin ); 124 bin->used = copyUcs2ToUtf8( bin->ptr.c, 125 (uint16_t*) cpA, count ); 92 126 enc = UR_ENC_ASCII; 93 127 goto set_result; … … 156 190 } 157 191 } 158 #endif159 192 160 193
