char xxx_gb2312( unsigned long word )
{
static const unsigned long areacode[] = {
0xB0A1, 0xB0C5, 0xB2C1, 0xB4EE, 0xB6EA, 0xB7A2, 0xB8C1 // a b c d e f g
, 0xB9FE, 0xBBF7, 0xBBF7, 0xBFA6, 0xC0AC, 0xC2E8, 0xC4C3 // h i j k l m n
, 0xC5B6, 0xC5BE, 0xC6DA, 0xC8BB, 0xC8F6, 0xCBFA // o p q r s t
, 0xCDDA, 0xCDDA, 0xCDDA, 0xCEF4, 0xD1B9, 0xD4D1 // u v w x y z
, 0xF7FF };
if( word>=areacode[0] && word<areacode[26] && (word&0xFF)>0xA0 && (word&0xFF)<0xFF )
{
for( int i=0; i<26; ++i )
{
if( word>=areacode[i] && word<areacode[i+1] )
return 'A'+i;
}
}
return '?';
}
#include <string>
std::string GetChineseSpell( const char* ptext ) // for test
{
std::string s;
for( const unsigned char* p=(const unsigned char*)ptext; *p; )
{
if( *p>0xA0 )
{
s += xxx_gb2312( p[0]<<8 | p[1] );
p += 2;
}
else
{
s += xxx_gb2312( p[0] );
p += 1;
}
}
return s;
}
#include <iostream>
using namespace std;
int main( void )
{
cout << GetChineseSpell("获取汉字的首拼字母") << endl;
return 0;
}
汉字首拼实现
最新推荐文章于 2023-11-21 14:07:41 发布