应用场景单片机,编码方式转换
uint8_t get_utf8_bytes(uint8_t utf8) { for (uint8_t i = 0; i < 6; i++) { if ((utf8 & (0x80 >> i)) == 0) { return i == 0? 1: i; } } return 1; } uint16_t utf8_TO_utf16(uint8_t *in, uint16_t inLen, uint16_t *out, uint16_t outLen) { uint16_t length = 0; uint8_t bytes = 0; for (uint16_t i = 0; i < inLen && length < outLen; i++, length++) { bytes = get_utf8_bytes(in[i]); if (bytes > 1) { out[length] = in[i] & (0xFF >> (bytes + 1)); for (uint8_t j = 1; j < bytes; j++) { i++; out[length] <<= 6; out[length] += in[i] & 0x3F; } } else { out[length] = in[i]; } } out[length] = 0; return length; }
总结
在此做个笔录,方面以后查阅,同时,感谢各位看官赏阅^_^。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)