/* Convert a UTF-8 string into a UCS-2 array. */
void tcstrutftoucs(const char *str, uint16_t *ary, int *np){
assert(str && ary && np);
const unsigned char *rp = (unsigned char *)str;
unsigned int wi = ;
while(*rp != '\0'){
int c = *(unsigned char *)rp;
if(c < 0x80){
ary[wi++] = c;
} else if(c < 0xe0){
if(rp[] >= 0x80){
ary[wi++] = ((rp[] & 0x1f) << ) | (rp[] & 0x3f);
rp++;
}
} else if(c < 0xf0){
if(rp[] >= 0x80 && rp[] >= 0x80){
ary[wi++] = ((rp[] & 0xf) << ) | ((rp[] & 0x3f) << ) | (rp[] & 0x3f);
rp += ;
}
}
rp++;
}
*np = wi;
} /* Convert a UCS-2 array into a UTF-8 string. */
int tcstrucstoutf(const uint16_t *ary, int num, char *str){
assert(ary && num >= && str);
unsigned char *wp = (unsigned char *)str;
for(int i = ; i < num; i++){
unsigned int c = ary[i];
if(c < 0x80){
*(wp++) = c;
} else if(c < 0x800){
*(wp++) = 0xc0 | (c >> );
*(wp++) = 0x80 | (c & 0x3f);
} else {
*(wp++) = 0xe0 | (c >> );
*(wp++) = 0x80 | ((c & 0xfff) >> );
*(wp++) = 0x80 | (c & 0x3f);
}
}
*wp = '\0';
return (char *)wp - str;
}

最新文章

  1. bat获取所有的参数
  2. Palindrome Pairs -- LeetCode 336
  3. IOS第九天(2:QQ聊天界面键盘优化 和自动回复)
  4. 如何从github上面拷贝源码
  5. [译]Memory Reordering Caught in the Act
  6. 深入理解windows
  7. jQuery EasyUI API 中文文档 - 菜单按钮(menubutton)
  8. iOS基础 - 多媒体
  9. phpstrom 快捷键
  10. SpringBoot-SpringMvc的Interceptor拦截器配置
  11. NodeJs实现他人项目实例
  12. 一文让你明白Redis主从同步
  13. pycharm中运行成功的python代码在jenkin中运行问题总结
  14. js实现reqire中的amd,cmd功能
  15. ubuntu下core file文件生成及调试
  16. 【Selenium】【BugList3】firefox与Selenium版本不兼容,报: Message: Unsupported Marionette protocol version 2, required 3
  17. SharePoint 2013 Newsfeed 没有出现的解决方法
  18. hwclock
  19. Letter Combinations of a Phone Number leetcode java
  20. type、object和class的关系

热门文章

  1. dateline 在数据库中就是 整型字段。date函数是可以转换成可读日期的。
  2. 在C中定义一个动态的二维数组
  3. 【转载】lua中的require机制
  4. 访问修饰符(access modifier)。
  5. HDU-4627 The Unsolvable Problem 简单数学
  6. localtime()方法的疑惑
  7. Objective-C Runtime 运行时之二:成员变量与属性
  8. js-弹出一个新窗口 新窗口自动转接到一个页面然后自动关闭
  9. (Map)利用Map,完成下面的功能:&#160; 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队。如果该&#160;年没有举办世界杯,则输出:没有举办世界杯。&#160; 附:世界杯冠军以及对应的夺冠年份,请参考本章附录。&#160;附录&#160;(Map)在原有世界杯Map&#160;的基础上,增加如下功能:&#160;读入一支球队的名字,输出该球队夺冠的年份列表。&#160;例如,读入“巴西”,应当输出&#160;1958&#160;1962&#160;1970&#160;1
  10. ABAP ALV 颜色设置(行,列,单元格)