git-svn-id: svn://db.shs.com.ru/pip@911 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2020-03-06 12:20:12 +00:00
parent 4e03a28a0c
commit a6836b9b97
3 changed files with 38 additions and 33 deletions

View File

@@ -29,6 +29,7 @@
#endif
#ifdef WINDOWS
# include <stringapiset.h>
# include <winnls.h>
#endif
char * __syslocname__ = 0;
char * __sysoemname__ = 0;
@@ -86,6 +87,20 @@ ushort charFromCodepage(const char * c, int size, const char * codepage, int * t
}
int charCompare(const ushort * f, const ushort * s) {
return
#ifdef PIP_ICU
u_strCompare((const UChar*)f, 1, (const UChar*)s, 1, FALSE);
#else
# ifdef WINDOWS
CompareStringW(LOCALE_USER_DEFAULT, 0, (PCNZWCH)f, 1, (PCNZWCH)s, 1);
# else
strcmp((const char *)f, (const char *)s);
# endif
#endif
}
PIChar::PIChar(const char * c, int * bytes) {
ch = charFromCodepage(c, 4, __syslocname__, bytes);
}
@@ -120,42 +135,22 @@ bool PIChar::operator ==(const PIChar & o) const {
bool PIChar::operator >(const PIChar & o) const {
return
#ifdef PIP_ICU
u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) > 0;
#else
strcmp(toCharPtr(), o.toCharPtr()) > 0;
#endif
return charCompare(&ch, &(o.ch)) > 0;
}
bool PIChar::operator <(const PIChar & o) const {
return
#ifdef PIP_ICU
u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) < 0;
#else
strcmp(toCharPtr(), o.toCharPtr()) < 0;
#endif
return charCompare(&ch, &(o.ch)) < 0;
}
bool PIChar::operator >=(const PIChar & o) const {
return
#ifdef PIP_ICU
u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) >= 0;
#else
strcmp(toCharPtr(), o.toCharPtr()) >= 0;
#endif
return charCompare(&ch, &(o.ch)) >= 0;
}
bool PIChar::operator <=(const PIChar & o) const {
return
#ifdef PIP_ICU
u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) <= 0;
#else
strcmp(toCharPtr(), o.toCharPtr()) <= 0;
#endif
return charCompare(&ch, &(o.ch)) <= 0;
}
@@ -269,26 +264,34 @@ char PIChar::toSystem() const {
PIChar PIChar::toUpper() const {
if (isAscii()) return PIChar(toupper(ch));
#ifdef PIP_ICU
UChar c(0);
UErrorCode e((UErrorCode)0);
u_strToUpper(&c, 1, (const UChar*)(&ch), 1, 0, &e);
return PIChar(c);
#else
return PIChar(toupper(ch));
ushort wc = 0;
if (LCMapStringW(LOCALE_USER_DEFAULT, LCMAP_UPPERCASE, (LPCWSTR)&ch, 1, (LPWSTR)&wc, 1) == 1)
return PIChar(wc);
#endif
return PIChar(toupper(ch));
}
PIChar PIChar::toLower() const {
if (isAscii()) return PIChar(tolower(ch));
#ifdef PIP_ICU
UChar c(0);
UErrorCode e((UErrorCode)0);
u_strToLower(&c, 1, (const UChar*)(&ch), 1, 0, &e);
return PIChar(c);
#else
return PIChar(tolower(ch));
ushort wc = 0;
if (LCMapStringW(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, (LPCWSTR)&ch, 1, (LPWSTR)&wc, 1) == 1)
return PIChar(wc);
#endif
return PIChar(tolower(ch));
}