//========================  METHOD DECLARATION  =======================
// METHOD NAME : UT_W2S
//---------------------------------------------------------------------
/// \param src 
/// \param dst 
/// \return 
//---------------------------------------------------------------------
// DESCRIPTION :
/// Convert a 'wstring' to a string.
//=====================================================================
void UT_W2S( const UT_String &src, string &dst )
{
#if defined(TARGET_IOS) || defined(TARGET_MACOS)
  CFStringRef	strref = CFStringCreateWithCharactersNoCopy( 0, src.data(), src.length(), kCFAllocatorNull );
  CFIndex	usedBufLen;
  CFStringGetBytes( strref, CFRangeMake( 0, src.length() ), CFStringGetSystemEncoding(), '?', false, NULL, 0, &usedBufLen );
  char *buffer = (char*)MEM_ALLOC(usedBufLen * sizeof(char));
  CFStringGetBytes( strref, CFRangeMake( 0, src.length() ), CFStringGetSystemEncoding(), '?', false, (UInt8 *) buffer, usedBufLen, &usedBufLen );
  CFRelease( strref );
  dst.assign( buffer, usedBufLen );
  MEM_DEALLOC(buffer);
  if ( ! dst.empty() )
    dst.erase(dst.begin(), dst.end());
  copy( src.begin(), src.end(), back_inserter( dst ));
#else
#ifndef TARGET_WIN32
  dst = string();
  if (src.length() < 1)
  {
    return;
  }
  unsigned char *dstC = (unsigned char*)MEM_ALLOC(6 * src.length() * sizeof(unsigned char));
  unsigned char *initial = dstC;
  UTF16 *srcC = const_cast<UTF16*>(src.c_str());
  ConvertUTF16toUTF8(&srcC, srcC + src.length(), &dstC, dstC + 6 * src.length());
  dst.append((const char *)dstC);
  MEM_DEALLOC(initial);
#else // TARGET_WIN32
  (void)src;
  (void)dst;
#endif
#endif
}
//========================  FUNCTION DECLARATION  =====================
// FCT NAME :    UT_A2W
//---------------------------------------------------------------------
/// \param pSrc 
/// \return 
//---------------------------------------------------------------------
// DESCRIPTION :
/// Convert ascii to a 'wstring'.
//=====================================================================
void UT_A2W( const char *pSrc, UT_String &dst)
{
#if defined(TARGET_IOS) || defined(TARGET_MACOS)
  CFStringRef	strref = CFStringCreateWithCStringNoCopy( 0, pSrc, CFStringGetSystemEncoding(), kCFAllocatorNull );
  dst = UT_String( strref );
  CFRelease( strref );
  
  size_t uLen = strlen( pSrc );
  dst.resize( uLen );
  UT_String::iterator it = dst.begin();
  
  while( *pSrc )
  {
    *it = wchar_t( *pSrc );
    ++it;
    ++pSrc;
  }
#else
   dst = UT_String();
  if (!pSrc)
    return;
  while (*pSrc)
  {
    dst.push_back(UniChar_t(*pSrc));
    ++pSrc;
  }

#endif
}
int UT_W2Int( const UT_String &s )
{
  string	as;
  for ( UT_String::const_iterator it = s.begin(); it != s.end(); ++it )
  {
    as.insert( as.end(), (char)*it );
  }
  return atoi( as.c_str() );
}
double UT_W2Float( const UT_String &s )
{
  string	as;
  for ( UT_String::const_iterator it = s.begin(); it != s.end(); ++it )
  {
    if ( *it == (UniChar_t)',' )
      as.insert( as.end(), '.' );
    else
      as.insert( as.end(), (char)*it );
  }
  return atof( as.c_str() );
}