diff --git a/inc/hgl/type/UnicodeBlocks.h b/inc/hgl/type/UnicodeBlocks.h index 4f07831..1980122 100644 --- a/inc/hgl/type/UnicodeBlocks.h +++ b/inc/hgl/type/UnicodeBlocks.h @@ -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字符 diff --git a/src/Other/UnicodeBlocks.cpp b/src/Other/UnicodeBlocks.cpp index c094893..756a74f 100644 --- a/src/Other/UnicodeBlocks.cpp +++ b/src/Other/UnicodeBlocks.cpp @@ -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(leftUnicodeBlockList[left].begin + &&chUnicodeBlockList[right].begin + &&chUnicodeBlockList[mid].begin + &&chUnicodeBlockList[mid].end) + { + left=mid; + continue; + } + } + + return UnicodeBlock::Error; + } + bool IsInUnicodeBlock(const UnicodeBlock &type,const uint32 ch) { if(typeUnicodeBlock::END_RANGE) + ||type>UnicodeBlock::END_RANGE) return(false); if(ch