add IndexOfUnicodeBlock function
This commit is contained in:
parent
2e07688151
commit
02cb4bb8b3
@ -321,12 +321,22 @@ namespace hgl
|
||||
supplementary_private_use_area_a,
|
||||
supplementary_private_use_area_b,
|
||||
|
||||
Error=0xFFFF,
|
||||
|
||||
BEGIN_RANGE =basic_latin,
|
||||
END_RANGE =supplementary_private_use_area_b,
|
||||
RANGE_SIZE =(END_RANGE-BEGIN_RANGE+1)
|
||||
RANGE_SIZE =(END_RANGE-BEGIN_RANGE+1),
|
||||
};//
|
||||
|
||||
bool IsInUnicodeBlock(const UnicodeBlock &type,const uint32 ch);
|
||||
/**
|
||||
* 寻找字符属于那一个Unicode块
|
||||
*/
|
||||
const UnicodeBlock IndexOfUnicodeBlock(const u32char ch);
|
||||
|
||||
/**
|
||||
* 判断字符是否属于当前Unicode块
|
||||
*/
|
||||
bool IsInUnicodeBlock(const UnicodeBlock &type,const u32char ch);
|
||||
|
||||
bool isLatin(const u32char ch); //判断当前字符是否是拉丁字符
|
||||
bool isCJK (const u16char ch); //判断当前字符是否是CJK字符
|
||||
|
@ -327,10 +327,55 @@ namespace hgl
|
||||
};
|
||||
}//namespace hgl
|
||||
|
||||
const UnicodeBlock IndexOfUnicodeBlock(const u32char ch)
|
||||
{
|
||||
if(ch>UnicodeBlockList[(size_t)UnicodeBlock::END_RANGE].end)
|
||||
return UnicodeBlock::Error;
|
||||
|
||||
uint left =(uint)UnicodeBlock::BEGIN_RANGE;
|
||||
uint right =(uint)UnicodeBlock::END_RANGE;
|
||||
uint mid;
|
||||
|
||||
while(left<right)
|
||||
{
|
||||
if(ch>UnicodeBlockList[left].begin
|
||||
&&ch<UnicodeBlockList[left].end)
|
||||
return (UnicodeBlock)left;
|
||||
|
||||
--left;
|
||||
|
||||
if(ch>UnicodeBlockList[right].begin
|
||||
&&ch<UnicodeBlockList[right].end)
|
||||
return (UnicodeBlock)right;
|
||||
|
||||
--right;
|
||||
|
||||
mid=(left+right)/2;
|
||||
|
||||
if(ch>UnicodeBlockList[mid].begin
|
||||
&&ch<UnicodeBlockList[mid].end)
|
||||
return (UnicodeBlock)mid;
|
||||
|
||||
if(ch<UnicodeBlockList[mid].begin)
|
||||
{
|
||||
right=mid;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ch>UnicodeBlockList[mid].end)
|
||||
{
|
||||
left=mid;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return UnicodeBlock::Error;
|
||||
}
|
||||
|
||||
bool IsInUnicodeBlock(const UnicodeBlock &type,const uint32 ch)
|
||||
{
|
||||
if(type<UnicodeBlock::basic_latin
|
||||
||type>UnicodeBlock::END_RANGE)
|
||||
||type>UnicodeBlock::END_RANGE)
|
||||
return(false);
|
||||
|
||||
if(ch<UnicodeBlockList[(size_t)type].begin)return(false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user