The characters in wince are unicode encoded, and the XML used for the project also needs to be unicode characters, while the LCD in the project is a GB character, there is a conversion problem between the two after google, we found that this type of conversion can only be performed in the form of a look-up table. We made the characters corresponding to unicode and GB code into a two-dimensional code table, and then searched and obtained. The total number of GB characters is 21791, And the binary search is used.
1. unicode conversion to GB
// The function converts unicode to GB. The code table must be sorted by unicode!
unsigned short UnicodeTOGBK(unsigned short unicode){int low=0,high=TotalGBKNum-1,mid;while(low <= high){mid = (low+high)/2;int x=GBK2UNICODETBL[mid][1];if(GBK2UNICODETBL[mid][1] == unicode)return GBK2UNICODETBL[mid][0];if(GBK2UNICODETBL[mid][1]>unicode)high=mid-1;elselow=mid+1;}return 0xFFFF;}
2. Convert GB to unicode
// The function is to convert GB to unicode. The code table must be sorted by GB!
unsigned int gb2unicode(unsigned short *unicode,unsigned char*gb,int len) { int i,j; i=0; for(j=0;i<len;j++) { if ((unsigned char)gb[j]<=0x80) { unicode[j]=(unsigned short)gb[j]; i++; } else { unicode[j]=ESM_getValidGBCode(*(unsigned short *)(gb+i)); i+=2; } #ifdef Little2Big_Endianreverise_w(&unicode[j]); #endif } return j*2; }
unsigned short ESM_getValidGBCode(unsigned short gb){int low=0,high=TotalGBKNum-1,mid;while(low <= high){mid = (low+high)/2;if(GBK2UNICODETBL[mid][0] == gb)return GBK2UNICODETBL[mid][1];if(GBK2UNICODETBL[mid][0]>gb)high=mid-1;elselow=mid+1;}return 0xFFFF;}
Corresponding table download link: http://download.csdn.net/detail/mjx91282041/4768949