diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2006-05-01 18:31:55 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2006-05-01 18:31:55 +0000 |
commit | 75ae8f6e9822d23c83c5e1efec31a82d27a0047b (patch) | |
tree | 59e538a9a7e601768574e3179390a73fbb0b933b /cpp/test/Ice/custom/StringConverterI.cpp | |
parent | removing redundant 'Client' portion from filter property names (diff) | |
download | ice-75ae8f6e9822d23c83c5e1efec31a82d27a0047b.tar.bz2 ice-75ae8f6e9822d23c83c5e1efec31a82d27a0047b.tar.xz ice-75ae8f6e9822d23c83c5e1efec31a82d27a0047b.zip |
Added ability to configure string converters
Diffstat (limited to 'cpp/test/Ice/custom/StringConverterI.cpp')
-rw-r--r-- | cpp/test/Ice/custom/StringConverterI.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/cpp/test/Ice/custom/StringConverterI.cpp b/cpp/test/Ice/custom/StringConverterI.cpp new file mode 100644 index 00000000000..7187194249b --- /dev/null +++ b/cpp/test/Ice/custom/StringConverterI.cpp @@ -0,0 +1,102 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <StringConverterI.h> +#include <IceUtil/Unicode.h> + +Ice::Byte* +Test::StringConverterI::toUTF8(const char* sourceStart, const char* sourceEnd, Ice::UTF8Buffer& buffer) const +{ + size_t size = static_cast<size_t>(sourceEnd - sourceStart); + Ice::Byte* targetStart = buffer.getMoreBytes(size, 0); + Ice::Byte* targetEnd = targetStart + size; + + char* p = const_cast<char*>(sourceEnd); + for(unsigned int i = 0; i < size; ++i) + { + targetStart[i] = *(--p); + } + return targetEnd; +} + +void +Test::StringConverterI::fromUTF8(const Ice::Byte* sourceStart, const Ice::Byte* sourceEnd, + const char*& targetStart, const char*& targetEnd) const +{ + size_t size = static_cast<size_t>(sourceEnd - sourceStart); + char* buf = new char[size]; + + Ice::Byte* p = const_cast<Ice::Byte*>(sourceEnd); + for(unsigned int i = 0; i < size; ++i) + { + buf[i] = *(--p); + } + + targetStart = buf; + targetEnd = targetStart + size; +} + +void +Test::StringConverterI::freeTarget(const char* target) const +{ + delete[] target; +} + +Ice::Byte* +Test::WstringConverterI::toUTF8(const wchar_t* sourceStart, const wchar_t* sourceEnd, Ice::UTF8Buffer& buffer) const +{ + std::wstring ws(sourceStart, sourceEnd); + std::string s = IceUtil::wstringToString(ws); + + size_t size = s.size(); + Ice::Byte* targetStart = buffer.getMoreBytes(size, 0); + Ice::Byte* targetEnd = targetStart + size; + + char* p = const_cast<char*>(s.c_str() + size); + for(unsigned int i = 0; i < size; ++i) + { + targetStart[i] = static_cast<Ice::Byte>(*(--p)); + } + return targetEnd; +} + +void +Test::WstringConverterI::fromUTF8(const Ice::Byte* sourceStart, const Ice::Byte* sourceEnd, + const wchar_t*& targetStart, const wchar_t*& targetEnd) const +{ + size_t size = static_cast<size_t>(sourceEnd - sourceStart); + std::string s(sourceStart, sourceEnd); + + Ice::Byte* p = const_cast<Ice::Byte*>(sourceEnd); + for(unsigned int i = 0; i < size; ++i) + { + s[i] = *(--p); + } + + std::wstring ws = IceUtil::stringToWstring(s); + size = ws.size(); + wchar_t* buf = new wchar_t[size]; + for(unsigned int i = 0; i < size; ++i) + { + buf[i] = ws[i]; + } + + targetStart = buf; + targetEnd = targetStart + size; +} + +void +Test::WstringConverterI::freeTarget(const wchar_t* target) const +{ +#if defined(_MSC_VER) && _MSC_VER < 1300 + delete[] const_cast<wchar_t*>(target); +#else + delete[] target; +#endif +} |