PIP ICUlpha ICU support

git-svn-id: svn://db.shs.com.ru/pip@93 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-04-14 10:33:35 +00:00
parent 89eef83786
commit 86f25eddde

174
src/core/pichar.cpp Normal file
View File

@@ -0,0 +1,174 @@
/*! \file pichar.h
* \brief Unicode char
*/
/*
PIP - Platform Independent Primitives
Unicode char
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pichar.h"
#ifdef PIP_ICU
# include "unicode/ucnv.h"
char * __syslocname__ = 0;
char * __sysoemname__ = 0;
#endif
/*! \class PIChar
* \brief Unicode char
* \details This class is wrapper around \c "uint".
* There are many contructors and information functions
*/
PIChar::PIChar(const char * c) {
ch = *reinterpret_cast<const int * >(c);
}
bool PIChar::operator ==(const PIChar & o) const {
return strcmp(o.toCharPtr(), toCharPtr()) == 0;
}
bool PIChar::operator >(const PIChar & o) const {
return strcmp(o.toCharPtr(), toCharPtr()) < 0;
}
bool PIChar::operator <(const PIChar & o) const {
return strcmp(o.toCharPtr(), toCharPtr()) > 0;
}
bool PIChar::operator >=(const PIChar & o) const {
return strcmp(o.toCharPtr(), toCharPtr()) <= 0;
}
bool PIChar::operator <=(const PIChar & o) const {
return strcmp(o.toCharPtr(), toCharPtr()) >= 0;
}
bool PIChar::isDigit() const {
return isdigit(ch) != 0;
}
bool PIChar::isHex() const {
return isxdigit(ch) != 0;
}
bool PIChar::isGraphical() const {
return isgraph(ch) != 0;
}
bool PIChar::isControl() const {
return iscntrl(ch) != 0;
}
bool PIChar::isLower() const {
return islower(ch) != 0;
}
bool PIChar::isUpper() const {
return isupper(ch) != 0;
}
bool PIChar::isPrint() const {
return isprint(ch) != 0;
}
bool PIChar::isSpace() const {
return isspace(ch) != 0;
}
bool PIChar::isAlpha() const {
return isalpha(ch) != 0;
}
bool PIChar::isAscii() const {
return isascii(ch) != 0;
}
const wchar_t * PIChar::toWCharPtr() const {
return reinterpret_cast<const wchar_t * >(&ch);
}
const char * PIChar::toCharPtr() const {
return reinterpret_cast<const char * >(&ch);
}
wchar_t PIChar::toWChar() const {
return wchar_t(ch);
}
char PIChar::toConcole1Byte() const {
if (ch < 0x80) return ch;
#ifdef PIP_ICU
UErrorCode e((UErrorCode)0);
UConverter * cc = ucnv_open(__sysoemname__, &e);
if (cc) {
char uc[8];
e = (UErrorCode)0;
ucnv_fromUChars(cc, uc, 8, (const UChar*)(&ch), 1, &e);
ucnv_close(cc);
return uc[0];
}
#endif
return toAscii();
}
PIChar PIChar::toUpper() const {
return PIChar(toupper(ch));
}
PIChar PIChar::toLower() const {
return PIChar(tolower(ch));
}
std::ostream & operator <<(std::ostream & s, const PIChar & v) {
s << v.toCharPtr();
return s;
}
PICout operator <<(PICout s, const PIChar & v) {
s.space();
s.setControl(0, true);
s << v.toCharPtr();
s.restoreControl();
return s;
}