int UT_Compare( const UT_String& rhs, const UT_String& lhs ) { #if defined(TARGET_IOS) || defined(TARGET_MACOS) CFStringRef theString1 = CFStringCreateWithCharactersNoCopy( 0, rhs.data(), rhs.length(), kCFAllocatorNull ); CFStringRef theString2 = CFStringCreateWithCharactersNoCopy( 0, lhs.data(), lhs.length(), kCFAllocatorNull ); CFComparisonResult result = CFStringCompare( theString1, theString2, kCFCompareLocalized ); CFRelease( theString1 ); CFRelease( theString2 ); return result; #else return rhs.compare(lhs); #endif }
//======================== 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 }