utf8-win.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
/* $Id$ */
/** @file
* IPRT - UTF8 helpers.
*/
/*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_UTF8
#include <Windows.h>
/**
* Allocates tmp buffer, translates pszString from UTF8 to current codepage.
*
* @returns iprt status code.
* @param ppszString Receives pointer of allocated native CP string.
* The returned pointer must be freed using RTStrFree().
* @param pszString UTF-8 string to convert.
*/
{
/*
* Check for zero length input string.
*/
if (!*pszString)
{
*ppszString = (char *)RTMemTmpAllocZ(sizeof(char));
if (*ppszString)
return VINF_SUCCESS;
return VERR_NO_TMP_MEMORY;
}
*ppszString = NULL;
/*
* Convert to wide char first.
*/
if (RT_FAILURE(rc))
return rc;
/*
* First calc result string length.
*/
if (cbResult > 0)
{
/*
* Alloc space for result buffer.
*/
if (lpString)
{
/*
* Do the translation.
*/
{
/* ok */
*ppszString = lpString;
return VINF_SUCCESS;
}
/* translation error */
int iLastErr = GetLastError();
}
else
}
else
{
/* translation error */
int iLastErr = GetLastError();
}
return rc;
}
/**
* Allocates tmp buffer, translates pszString from current codepage to UTF-8.
*
* @returns iprt status code.
* @param ppszString Receives pointer of allocated UTF-8 string.
* The returned pointer must be freed using RTStrFree().
* @param pszString Native string to convert.
*/
{
*ppszString = NULL;
/** @todo is there a quicker way? Currently: ACP -> UTF-16 -> UTF-8 */
if (cch <= 0)
{
/* zero length string passed. */
*ppszString = (char *)RTMemTmpAllocZ(sizeof(char));
if (*ppszString)
return VINF_SUCCESS;
return VERR_NO_TMP_MEMORY;
}
/*
* First calc result string length.
*/
int rc;
if (cwc > 0)
{
/*
* Alloc space for result buffer.
*/
if (pwszString)
{
/*
* Do the translation.
*/
{
/*
* Now we got UTF-16, convert it to UTF-8
*/
return rc;
}
/* translation error */
int iLastErr = GetLastError();
}
else
}
else
{
/* translation error */
int iLastErr = GetLastError();
}
return rc;
}