From 86f25edddeeb335e3bb0ed981a8959d59dd095a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Tue, 14 Apr 2015 10:33:35 +0000 Subject: [PATCH] PIP ICUlpha ICU support git-svn-id: svn://db.shs.com.ru/pip@93 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src/core/pichar.cpp | 174 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 src/core/pichar.cpp diff --git a/src/core/pichar.cpp b/src/core/pichar.cpp new file mode 100644 index 00000000..ba14fbba --- /dev/null +++ b/src/core/pichar.cpp @@ -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 . +*/ + +#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(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(&ch); +} + + +const char * PIChar::toCharPtr() const { + return reinterpret_cast(&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; +}