| 1 | // |
| 2 | // XMLString.cpp |
| 3 | // |
| 4 | // Library: XML |
| 5 | // Package: XML |
| 6 | // Module: XMLString |
| 7 | // |
| 8 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
| 9 | // and Contributors. |
| 10 | // |
| 11 | // SPDX-License-Identifier: BSL-1.0 |
| 12 | // |
| 13 | |
| 14 | |
| 15 | #include "Poco/XML/XMLString.h" |
| 16 | |
| 17 | |
| 18 | #if defined(XML_UNICODE_WCHAR_T) |
| 19 | #include <stdlib.h> |
| 20 | #endif |
| 21 | |
| 22 | |
| 23 | namespace Poco { |
| 24 | namespace XML { |
| 25 | |
| 26 | |
| 27 | #if defined(XML_UNICODE_WCHAR_T) |
| 28 | |
| 29 | |
| 30 | std::string fromXMLString(const XMLString& str) |
| 31 | { |
| 32 | std::string result; |
| 33 | result.reserve(str.size()); |
| 34 | |
| 35 | for (XMLString::const_iterator it = str.begin(); it != str.end(); ++it) |
| 36 | { |
| 37 | char c; |
| 38 | wctomb(&c, *it); |
| 39 | result += c; |
| 40 | } |
| 41 | return result; |
| 42 | } |
| 43 | |
| 44 | |
| 45 | XMLString toXMLString(const std::string& str) |
| 46 | { |
| 47 | XMLString result; |
| 48 | result.reserve(str.size()); |
| 49 | |
| 50 | for (std::string::const_iterator it = str.begin(); it != str.end();) |
| 51 | { |
| 52 | wchar_t c; |
| 53 | int n = mbtowc(&c, &*it, MB_CUR_MAX); |
| 54 | result += c; |
| 55 | it += (n > 0 ? n : 1); |
| 56 | } |
| 57 | return result; |
| 58 | } |
| 59 | |
| 60 | |
| 61 | #endif // XML_UNICODE_WCHAR_T |
| 62 | |
| 63 | |
| 64 | } } // namespace Poco::XML |
| 65 | |