Пример #1
0
//========================  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
}
Пример #2
0
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() );
}
Пример #3
0
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() );
}