secureswitools/swisistools/source/interpretsislib/utils_win32.cpp
branchRCL_3
changeset 62 5cc91383ab1e
parent 0 ba25891c3a9e
child 65 7333d7932ef7
equal deleted inserted replaced
61:cd189dac02f7 62:5cc91383ab1e
     1 /*
     1 /*
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   271 		}
   271 		}
   272 	}
   272 	}
   273 
   273 
   274 	return 0;
   274 	return 0;
   275 }
   275 }
   276 std::string Utils::wstring2string (const std::wstring& aWide)
       
   277 	{
       
   278 	int max = WideCharToMultiByte(CP_OEMCP,0,aWide.c_str(),aWide.length(),0,0,0,0);
       
   279 	std::string reply;
       
   280 	if (max > 0 )
       
   281 		{
       
   282 		char* buffer = new char [max];
       
   283 		try
       
   284 			{
       
   285 			WideCharToMultiByte(CP_OEMCP,0,aWide.c_str(),aWide.length(),buffer,max,0,0);
       
   286 			reply = std::string (buffer, max);
       
   287 			}
       
   288 		catch (...)
       
   289 			{
       
   290 			}
       
   291 		delete [] buffer;
       
   292 		}
       
   293 	return reply;
       
   294 	}
       
   295 
       
   296 std::wstring Utils::string2wstring (const std::string& aNarrow)
       
   297 	{
       
   298 	int max = MultiByteToWideChar(CP_OEMCP,0,aNarrow.c_str(),aNarrow.length(),0,0);
       
   299 	std::wstring reply;
       
   300 	if (max > 0 )
       
   301 		{
       
   302 		wchar_t* buffer = new wchar_t [max];
       
   303 		try
       
   304 			{
       
   305 			MultiByteToWideChar(CP_OEMCP,0,aNarrow.c_str(),aNarrow.length(),buffer,max);
       
   306 			reply = std::wstring (buffer, max);
       
   307 			}
       
   308 		catch (...)
       
   309 			{
       
   310 			}
       
   311 		delete [] buffer;
       
   312 		}
       
   313 	return reply;
       
   314 	}
       
   315 
       
   316 const std::wstring Utils::IntegerToWideString(int aInt)
       
   317 	{
       
   318 	std::wstringstream wstream;
       
   319 	wstream << aInt;
       
   320 	return wstream.str();
       
   321 	}
       
   322 
       
   323 std::wstring Utils::Int64ToWideString(TInt64 aInt)
       
   324 	{
       
   325 	wchar_t wint[20];
       
   326 	
       
   327 #ifdef _MSC_VER
       
   328 	swprintf(wint, L"%I64u", aInt);
       
   329 #else
       
   330 	swprintf(wint, 20, L"%I64u", aInt);
       
   331 #endif // _MSC_VER
       
   332 	
       
   333 	std::wstring strInt64(wint);
       
   334 	return strInt64;
       
   335 	}
       
   336 
       
   337 int Utils::WideStringToInteger(const std::wstring& aWideString)
       
   338 	{
       
   339 	unsigned long int value=0;
       
   340 	std::wstringstream str(aWideString);
       
   341 	str >> value;
       
   342 	return value;
       
   343 	}