sl@0: /* sl@0: * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include "utils.h" sl@0: #include "logger.h" sl@0: sl@0: #ifndef __LINUX__ sl@0: #include sl@0: #endif sl@0: sl@0: typedef unsigned char TUint8; sl@0: typedef unsigned int TUint; sl@0: sl@0: #ifdef __LINUX__ sl@0: void OpenUtf8FStreamForRead(std::fstream &aFStream, const char *aUtf8FileName) sl@0: { sl@0: aFStream.open(aUtf8FileName, std::ios_base::binary | std::ios_base::in); sl@0: } sl@0: sl@0: void OpenUtf8FStreamForWrite(std::fstream &aFStream, const char *aUtf8FileName) sl@0: { sl@0: aFStream.open(aUtf8FileName, std::ios_base::binary | std::ios_base::trunc | std::ios_base::out); sl@0: } sl@0: sl@0: #else sl@0: sl@0: WCHAR *WindowsUtf8ToUtf16(const char *aUtf8) sl@0: { sl@0: int utf8Len = strlen(aUtf8) + 1; // We want to copy the terminator to the new string sl@0: int utf16Space = MultiByteToWideChar(CP_UTF8, 0, aUtf8, utf8Len, 0, 0); sl@0: if(utf16Space <= 0) sl@0: { sl@0: dbg << Log::Indent() << "Failed to convert UTF-8 '" << aUtf8 << "' to UTF16" << Log::Endl(); sl@0: FatalError(); sl@0: return 0; sl@0: } sl@0: // prog << Log::Indent() << "utf16Space " << utf16Space << Log::Endl(); sl@0: WCHAR *utf16 = new WCHAR[utf16Space]; sl@0: (void) MultiByteToWideChar(CP_UTF8, 0, aUtf8, utf8Len, utf16, utf16Space); sl@0: #if 0 sl@0: prog << Log::Indent() << "Raw UTF16 name is (chars " << utf16Space << ")" << Log::Endl(); sl@0: for(int i=0; i