PIChar ICU fixes

git-svn-id: svn://db.shs.com.ru/pip@95 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-04-14 20:17:20 +00:00
parent 2fd1bdfe53
commit dbe80f4e83
5 changed files with 74 additions and 18 deletions

View File

@@ -110,27 +110,47 @@ PIChar PIChar::fromUTF8(const char * c) {
bool PIChar::operator ==(const PIChar & o) const {
return strcmp(o.toCharPtr(), toCharPtr()) == 0;
return ch == o.ch;
}
bool PIChar::operator >(const PIChar & o) const {
return strcmp(o.toCharPtr(), toCharPtr()) < 0;
return
#ifdef PIP_ICU
u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) > 0;
#else
strcmp(toCharPtr(), o.toCharPtr()) > 0;
#endif
}
bool PIChar::operator <(const PIChar & o) const {
return strcmp(o.toCharPtr(), toCharPtr()) > 0;
return
#ifdef PIP_ICU
u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) < 0;
#else
strcmp(toCharPtr(), o.toCharPtr()) < 0;
#endif
}
bool PIChar::operator >=(const PIChar & o) const {
return strcmp(o.toCharPtr(), toCharPtr()) <= 0;
return
#ifdef PIP_ICU
u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) >= 0;
#else
strcmp(toCharPtr(), o.toCharPtr()) >= 0;
#endif
}
bool PIChar::operator <=(const PIChar & o) const {
return strcmp(o.toCharPtr(), toCharPtr()) >= 0;
return
#ifdef PIP_ICU
u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) <= 0;
#else
strcmp(toCharPtr(), o.toCharPtr()) <= 0;
#endif
}
@@ -217,12 +237,26 @@ char PIChar::toConcole1Byte() const {
PIChar PIChar::toUpper() const {
#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));
#endif
}
PIChar PIChar::toLower() const {
#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));
#endif
}
@@ -237,6 +271,18 @@ std::ostream & operator <<(std::ostream & s, const PIChar & v) {
PICout operator <<(PICout s, const PIChar & v) {
s.space();
s.setControl(0, true);
#ifdef PIP_ICU
UErrorCode e((UErrorCode)0);
UConverter * cc = ucnv_open(PICout::isBufferActive() ? __syslocname__ : __sysoemname__, &e);
if (cc) {
char uc[8];
memset(uc, 0, 8);
e = (UErrorCode)0;
ucnv_fromUChars(cc, uc, 8, (const UChar*)(&v.ch), 1, &e);
ucnv_close(cc);
s << uc;
} else
#endif
s << v.toCharPtr();
s.restoreControl();
return s;

View File

@@ -35,6 +35,7 @@ class PIP_EXPORT PIChar
friend class PIString;
friend PIByteArray & operator <<(PIByteArray & s, const PIChar & v);
friend PIByteArray & operator >>(PIByteArray & s, PIChar & v);
friend PICout operator <<(PICout s, const PIChar & v);
public:
//! Contructs ascii symbol
PIChar(const char c) {ch = c; ch &= 0xFF;}