os/security/securityanddataprivacytools/securitytools/certapp/utils/stringconv.cpp
Update contrib.
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 #include "stringconv.h"
25 TUint8 *cstrFromUtf16(const TText *aUtf16, TInt aLength, TInt &outputBytes)
27 TPtrC16 src(aUtf16, aLength);
31 TInt len = CnvUtfConverter::ConvertFromUnicodeToUtf8(nulldest, src);
34 dbg << Log::Indent() << "ConvertFromUnicodeToUtf8 failed" << Log::Endl();
38 TUint8 *buf = new TUint8[len+1];
41 (void) CnvUtfConverter::ConvertFromUnicodeToUtf8(dest, src);
42 buf[len] = 0; // Add NUL termination in case it is used with windows APIs
43 outputBytes = dest.Length();
47 std::string stringFromUtf16(const TText *aUtf16, TInt aLength)
50 TUint8 *outBuf = cstrFromUtf16(aUtf16, aLength, outputBytes);
52 std::string str((const char *)outBuf, outputBytes);
57 std::string stringFromUtf16(const TDesC &aUtf16)
59 return stringFromUtf16(aUtf16.Ptr(), aUtf16.Length());
62 TText *utf16FromUtf8(const TUint8 *aUtf8, TInt aLength, TInt &outputWords)
64 // Expand UTF-8 into internal UTF-16LE representation
66 TPtrC8 src(aUtf8, aLength);
70 TInt len = CnvUtfConverter::ConvertToUnicodeFromUtf8(nulldest, src);
73 dbg << Log::Indent() << "ConvertToUnicodeFromUtf8 failed" << Log::Endl();
77 TUint16 *buf = new TUint16[len+1];
78 TPtr16 dest(buf, len);
80 (void) CnvUtfConverter::ConvertToUnicodeFromUtf8(dest, src);
82 buf[len] = 0; // Add null termination in case it gets used with windows APIs
83 outputWords = dest.Length();