mirror of
https://github.com/HEYAHONG/HCppBox.git
synced 2025-05-07 23:52:51 +08:00
完善hlocale组件
This commit is contained in:
parent
fac0b51fa1
commit
6a2181f0c2
@ -50,4 +50,59 @@ const char *hlocale_locale_get(void)
|
||||
return locale;
|
||||
}
|
||||
|
||||
bool hlocale_charset_is_utf8(void)
|
||||
{
|
||||
const char *locale=hlocale_locale_get();
|
||||
if(locale!=NULL && locale[0]!='\0')
|
||||
{
|
||||
/*
|
||||
* windows下根据代码页判断
|
||||
*/
|
||||
if(strstr(locale,"CP65001")!=NULL || strstr(locale,"cp65001")!=NULL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* 其它系统通过UTF-8字符串判断
|
||||
*/
|
||||
if(strstr(locale,"UTF-8")!=NULL || strstr(locale,"utf-8")!=NULL || strstr(locale,"UTF8")!=NULL || strstr(locale,"utf8")!=NULL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hlocale_charset_is_gb2312(void)
|
||||
{
|
||||
const char *locale=hlocale_locale_get();
|
||||
if(locale!=NULL && locale[0]!='\0')
|
||||
{
|
||||
/*
|
||||
* windows下根据代码页判断
|
||||
*/
|
||||
if(strstr(locale,"CP936")!=NULL || strstr(locale,"cp936")!=NULL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(strstr(locale,"CP20936")!=NULL || strstr(locale,"cp20936")!=NULL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
//FreeBSD
|
||||
if(strstr(locale,"eucCN")!=NULL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
//其它环境下
|
||||
if(strstr(locale,"GB2312")!=NULL || strstr(locale,"gb2312")!=NULL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(strstr(locale,"GBK")!=NULL || strstr(locale,"gbk")!=NULL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -8,6 +8,8 @@
|
||||
**************************************************************/
|
||||
#ifndef __HLOCALE_H__
|
||||
#define __HLOCALE_H__
|
||||
#include "stdint.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@ -24,6 +26,22 @@ extern "C"
|
||||
*/
|
||||
const char *hlocale_locale_get(void);
|
||||
|
||||
|
||||
/** \brief 字符集是否是UTF-8
|
||||
*
|
||||
* \return bool 是否为UTF-8
|
||||
*
|
||||
*/
|
||||
bool hlocale_charset_is_utf8(void);
|
||||
|
||||
/** \brief 字符集是否是GB2312
|
||||
* 注意:虽然不严谨,GBK也视作GB2312
|
||||
*
|
||||
* \return bool 是否为GB2312
|
||||
*
|
||||
*/
|
||||
bool hlocale_charset_is_gb2312(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
@ -1270,6 +1270,8 @@ static int hlocale_test(int argc,const char *argv[])
|
||||
{
|
||||
{
|
||||
printf("hlocale:%s\r\n",hlocale_locale_get());
|
||||
printf("hlocale:UTF-8 = %s\r\n",hlocale_charset_is_utf8()?"true":"false");
|
||||
printf("hlocale:GB2312 = %s\r\n",hlocale_charset_is_gb2312()?"true":"false");
|
||||
}
|
||||
{
|
||||
const char *const ascii_test_string="testtest";
|
||||
|
Loading…
x
Reference in New Issue
Block a user