diff --git a/main.cpp b/main.cpp index 7219383d..5488797c 100644 --- a/main.cpp +++ b/main.cpp @@ -1,22 +1,16 @@ #include "pip.h" #include "pivector2d.h" +#include "pistring.h" int main(int argc, char *argv[]) { - /*PIKbdListener kbd; - kbd.enableExitCapture(); - kbd.start();*/ - /*PIScreen s(false); - PIScreenTile t; - t.minimumHeight = t.minimumWidth = t.maximumHeight = t.maximumWidth = 1; - t.back_format.color_back = PIScreenTypes::Green; - s.rootTile()->addTile(&t); - s.rootTile()->addTile(new PIScreenTile()); - s.enableExitCapture(); - s.start(); - piMSleep(100); - piCout << t.x() << t.y() << t.width() << t.height();*/ - WAIT_FOR_EXIT + PIString s = PIString::fromUTF8("hello, привет"); + piCout << s; + PIByteArray ba = s.toUTF8(); + piCout << ba.toHex(); + PIString s2; + s2 = PIString::fromUTF8(ba); + piCout << s2; return 0; } diff --git a/src_main/core/pistring.cpp b/src_main/core/pistring.cpp index 6832f5a4..f6a85127 100755 --- a/src_main/core/pistring.cpp +++ b/src_main/core/pistring.cpp @@ -254,9 +254,21 @@ PIString PIString::fromUTF8(const char * s) { PIString ret; if (l > 0) ret.appendFromChars(s, l #ifdef PIP_ICU - , "UTF-8" + , "UTF-8" #endif - ); + ); + return ret; +} + + +PIString PIString::fromUTF8(const PIByteArray & ba) { + PIString ret; + if (ba.isEmpty()) return ret; + ret.appendFromChars((const char*)ba.data(), ba.size() +#ifdef PIP_ICU + , "UTF-8" +#endif + ); return ret; } diff --git a/src_main/core/pistring.h b/src_main/core/pistring.h index 80d8cccc..cb23f72d 100755 --- a/src_main/core/pistring.h +++ b/src_main/core/pistring.h @@ -675,6 +675,9 @@ public: //! \brief Return string constructed from UTF-8 static PIString fromUTF8(const char * s); + //! \brief Return string constructed from UTF-8 + static PIString fromUTF8(const PIByteArray &ba); + //! \brief Return string constructed from ASCII static PIString fromAscii(const char * s);