优化英语环境检测

This commit is contained in:
gb 2023-09-18 17:51:39 +08:00
parent 8bf63f6815
commit e64617c1c9
1 changed files with 22 additions and 16 deletions

View File

@ -557,6 +557,17 @@ class lang_mgr
} }
public: public:
static bool is_english_cp(int cp)
{
return cp == 37 // IBM EBCDIC US-Canada
|| cp == 437 // OEM-US
|| cp == 500 // IBM EBCDIC International
|| cp == 1146 // IBM EBCDIC England
|| cp == 1252 // ANSI west Europe
|| cp == 20127 // English - US
|| cp == 20285 // IBM EBCDIC English
;
}
static int get_os_code_page(void) static int get_os_code_page(void)
{ {
char* locale = setlocale(LC_ALL, ""); char* locale = setlocale(LC_ALL, "");
@ -583,21 +594,21 @@ public:
} }
if (!found && strrchr(locale, '.')) if (!found && strrchr(locale, '.'))
{ {
// windows: Chinese (Simplified)_China.DEFAULT_CODE_PAGE if (strstr(locale, "English"))
locale = strrchr(locale, '.') + 1; cp = 20127;
if (*locale >= '0' && *locale <= '9') else
cp = atoi(locale); {
// windows: Chinese (Simplified)_China.DEFAULT_CODE_PAGE
locale = strrchr(locale, '.') + 1;
if (*locale >= '0' && *locale <= '9')
cp = atoi(locale);
}
} }
if(end) if(end)
*end = ';'; *end = ';';
} }
if (cp == 37 // IBM EBCDIC US-Canada if (lang_mgr::is_english_cp(cp))
|| cp == 437 // OEM-US
|| cp == 500 // IBM EBCDIC International
|| cp == 1146 // IBM EBCDIC England
|| cp == 20285 // IBM EBCDIC English
)
cp = 20127; cp = 20127;
return cp; return cp;
@ -805,12 +816,7 @@ extern "C"
} }
int lang_set_code_page(int cp) int lang_set_code_page(int cp)
{ {
if (cp == 37 // IBM EBCDIC US-Canada if (lang_mgr::is_english_cp(cp))
|| cp == 437 // OEM-US
|| cp == 500 // IBM EBCDIC International
|| cp == 1146 // IBM EBCDIC England
|| cp == 20285 // IBM EBCDIC English
)
cp = 20127; cp = 20127;
return lang_mgr::instance()->set_code_page(cp); return lang_mgr::instance()->set_code_page(cp);