123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include "unicode.h"
- #include "GB2312UnicodeTable.h"
- #include <stdint.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- /*
- MIN_CODE = $A1A1;
- MAX_CODE = $F7FE;
- */
- #define GB2312_CODE_ZONE_MIN 0xA1
- #define GB2312_CODE_ZONE_MAX 0xF7
- #define GB2312_CODE_POS_MIN 0xA1
- #define GB2312_CODE_POS_MAX 0xFE
- static uint16_t
- GB2312_to_Unicode(uint16_t c)
- {
- uint8_t zone, pos;
- uint32_t offset;
- uint16_t retval;
- zone = c >> 8;
- pos = c & 0xFF;
- if ((zone > GB2312_CODE_ZONE_MAX) ||
- (zone < GB2312_CODE_ZONE_MIN) ||
- (pos > GB2312_CODE_POS_MAX) ||
- (pos < GB2312_CODE_POS_MIN))
- {
- return c;
- }
- offset = (zone - GB2312_CODE_ZONE_MIN) * (GB2312_CODE_POS_MAX - GB2312_CODE_POS_MIN + 1) +
- (pos - GB2312_CODE_POS_MIN);
- retval=GB2312_UNICODE_MAP[offset];//offset*2
- return retval;
- }
- uint16_t
- Ansi_to_Unicode(uint16_t *dest, uint16_t size, const uint8_t *src, uint16_t length) //GBK_Unicode
- {
- uint16_t count = 0;
- uint16_t temp,tmp;
- while((count < size) && length){
- if ((*src > 0x7F) && (length > 1)){
- dest[count] = GB2312_to_Unicode(((uint16_t)src[0] << 8) | src[1]);
- src += 2;
- length -= 2;
- }
- else
- {
- dest[count] = *src;
- src++;
- length--;
- }
- ++count;
- }
- return count;
- }
|