如何检查Unicode字符是否在C中的给定范围内? [英] How to check if a unicode character is within given range in C?

查看:93
本文介绍了如何检查Unicode字符是否在C中的给定范围内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下函数是为Java编写的,并已针对C进行了修改.

The following function was written for java and has been adapted for C.

bool isFullwidthKatakana(WideChar C)
{
  return(('\u30a0'<=C)&&(C<='\u30ff'));
}

问题是我的框架("CodeGear C ++ Builder")显示此错误:

The problem is that my framework ("CodeGear C++Builder") shows this error:

[BCC32警告] Unit1.cpp(101):W8114字符代表通用字符名称'\ u30a0'无法在当前中表示代码页(1252)

[BCC32 Warning] Unit1.cpp(101): W8114 Character represented by universal-character-name '\u30a0' cannot be represented in the current code page (1252)

并且是否满足条件并不会返回true.

and it does not return true whether the conditions are met.

例如,一个输入是'ア'(0x30A2).

For example one input is 'ア' (0x30A2).

我该怎么办?如何更改代码页?

What should I do? How can I change the code page?

谢谢三个答案,他们都解决了.

return((0x30a0<=C)&&(C<=0x30ff));

似乎\ u30a0表达式不正确,这一切都是正确的

It seems the that the expression \u30a0 wasn't correct, this all were correct

return((0x30a0<=C)&&(C<=0x30ff));
return (unsigned int) C >= 0x30a0u && (unsigned int) C <= 0x30ffu;
return((L'\u30a0'<=C)&&(C<=L'\u30ff'));

推荐答案

应该可以(显式或隐式)将字符转换为无符号整数,然后仅使用以下常量:

It should be possible to cast (explicitly or implicitly) the character to an unsigned integer, and then just use such constants:

return (unsigned int) C >= 0x30a0u && (unsigned int) C <= 0x30ffu;

应该这样做.

顺便说一句,我建议不要使用(单字符)大写参数名称,很容易认为它是编译时常量(在C和C ++中通常为大写).

By the way, I'd recommend against using a (single-character) uppercase argument name, it's very easy to think it's a compile-time constant (which are typically uppercase in C and C++).

这篇关于如何检查Unicode字符是否在C中的给定范围内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆