2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of COLLADABaseUtils.
6
Licensed under the MIT Open Source License,
7
for details please see LICENSE file or the website
8
http://www.opensource.org/licenses/mit-license.php
11
#include "COLLADABUStableHeaders.h"
12
#include "COLLADABUNativeString.h"
13
#include "COLLADABUStringUtils.h"
14
#include "COLLADABUPlatform.h"
18
#ifdef COLLADABU_OS_WIN
26
NativeString::NativeString(const String& str, Encoding encoding ) : std::string()
28
if ( encoding == ENCODING_NATIVE )
34
fromWideString(StringUtils::utf8String2WideString(str));
38
NativeString::NativeString( const char * s, Encoding encoding /*= ENCODING_NATIVE*/ )
40
if ( encoding == ENCODING_NATIVE )
46
fromWideString(StringUtils::utf8String2WideString(String(s)));
51
void NativeString::fromWideString( const WideString& wideString )
53
#ifdef COLLADABU_OS_WIN
54
int multibyteLength = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)wideString.c_str(), -1, 0, 0, 0, 0 );
56
char * dest = new char[ multibyteLength ];
57
WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)wideString.c_str(), -1, dest, multibyteLength, 0, 0 );
60
#elif defined (COLLADABU_OS_LINUX) || defined (COLLADABU_OS_MAC)
61
//# error check if this really works on linux
62
size_t maxStringLength = wcstombs( 0, wideString.c_str(), 0 ) + 1; // wideString.length()*MB_CUR_MAX + 1;
63
char* dest = new char[ maxStringLength ];
64
wcstombs( dest, wideString.c_str(), maxStringLength );
69
# error "No StringUtil::toString defined for your platform"
73
WideString NativeString::toWideString() const
75
#ifdef COLLADABU_OS_WIN
76
wchar_t * dest = new wchar_t[ length() + 1 ];
77
int nDest = MultiByteToWideChar ( CP_ACP, 0, c_str(), ( int ) length(),
78
dest, ( int ) length() );
79
dest[ nDest ] = 0; // null termination
80
WideString returnValue( dest );
83
#elif defined (COLLADABU_OS_LINUX) || defined (COLLADABU_OS_MAC)
84
//# error check if this really works on linux
86
size_t maxStringLength = length() + 1;
87
wchar_t* dest = new wchar_t[ maxStringLength ];
88
mbstowcs( dest, this->c_str(), maxStringLength );
90
WideString returnValue( dest );
97
# error "Not StringUtil::toWideString defined for your platform"
98
// this functions doesn'nt seem to work
99
// return fromUtf8( string );
104
String NativeString::toUtf8String() const
106
return StringUtils::wideString2utf8String(toWideString());
110
} //namespace COLLADA