动态计算 unicode 字符
Dynamically calculating unicode characters
对于游戏,我需要处理扑克牌。我想利用 Unicode 中的扑克牌,这基本上归结为U+1F0XY
X
设置颜色和Y
设置牌的面。
我现在需要实现一个函数,该函数返回一个字符串,其中包含表示卡的单个 Unicode 字符。我需要使用什么数据类型而不是占位符unicode_char_t
来对 Unicode 字符进行数学运算?
std::string cardToUnicodeChar(uint8_t face, uint8_t color) {
unicode_char_t unicodeCharacter = 0x1F000 + (color << 4) + face;
return std::string(unicodeCharacter);
}
如果这是一个孤立的位置,您打算在其中使用计算的 unicode 字符,则可以基于以下内容。
UTF-8 中1F0XY
的按位编码为:
11110000 10111111 100000XX 10XXYYYY
您可以按如下方式构造它:
uint8_t buf[5];
buf[0] = 0xf0;
buf[1] = 0x9f;
buf[2] = 0x80 | (color & 12) >> 2;
buf[3] = 0x80 | (color & 3) << 4 | face & 15;
buf[4] = 0;
return std::string(buf);
相关文章:
- 如何存储 unicode 字符并将其输出到文件?
- C++:打印 Unicode 字符
- 在 Windows 中使用 boost::p rogram_options 从命令行参数读取 Unicode 字符
- 获取Unicode字符C++的十进制值
- 用wchar_t处理 unicode 字符好吗?它不会引起任何问题吗?
- C++如何通过忽略每行的第一个字符来读取 unicode 文件
- C++:如何将 unicode 字符打印到文本文件
- 动态计算 unicode 字符
- C Unicode UTF-8解码字符的问题
- 如何替换/忽略 C stdio.h getline() 中的无效 Unicode/UTF8 字符
- 无法使用 Unicode 特殊字符设置窗口文本
- 如何将整数转换为 unicode 字符
- C++20 中的严格别名规则是否允许标准 c++ unicode 字符和下划线类型之间"reinterpret
- MessageBox打印来自TCHAR缓冲区的额外Unicode字符
- 如何将小数NCR转换为Unicode字符(C )
- SQLGetPrivateProfileString 错误地读取 Unicode 字符
- 将 Unicode 字符/字符串写入文件
- 将 Unicode 字符存储在.txt文件中的新行中
- 是否有返回字符UNICODE值的函数?(C++)
- 将字符串宏/常量转换为宽字符/Unicode