Skip to content

Commit

Permalink
[Fix] Change from DarwinCFStringRefToString to DarwinCFStringRefToUTF…
Browse files Browse the repository at this point in the history
…8String.
  • Loading branch information
ulion committed Apr 2, 2013
1 parent 0482c22 commit b8e0db7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void CCoreAudioHardware::GetOutputDeviceName(std::string& name)
if (ret != noErr)
return;

DarwinCFStringRefToString(theDeviceName, name);
DarwinCFStringRefToUTF8String(theDeviceName, name);

CFRelease(theDeviceName);
}
Expand Down
8 changes: 4 additions & 4 deletions xbmc/network/osx/ZeroconfBrowserOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace
for(idx = 0; idx < numValues; idx++)
{
std::string key;
if (DarwinCFStringRefToString(keys[idx], key))
if (DarwinCFStringRefToUTF8String(keys[idx], key))
{
recordMap.insert(
std::make_pair(
Expand Down Expand Up @@ -148,9 +148,9 @@ void CZeroconfBrowserOSX::BrowserCallback(CFNetServiceBrowserRef browser, CFOpti

//store the service
std::string name, type, domain;
if (!DarwinCFStringRefToString(CFNetServiceGetName(service), name) ||
!DarwinCFStringRefToString(CFNetServiceGetType(service), type) ||
!DarwinCFStringRefToString(CFNetServiceGetDomain(service), domain))
if (!DarwinCFStringRefToUTF8String(CFNetServiceGetName(service), name) ||
!DarwinCFStringRefToUTF8String(CFNetServiceGetType(service), type) ||
!DarwinCFStringRefToUTF8String(CFNetServiceGetDomain(service), domain))
{
CLog::Log(LOGWARNING, "CZeroconfBrowserOSX::BrowserCallback failed to convert service strings.");
return;
Expand Down
1 change: 1 addition & 0 deletions xbmc/osx/DarwinUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern "C"
int DarwinBatteryLevel(void);
void DarwinSetScheduling(int message);
bool DarwinCFStringRefToString(CFStringRef source, std::string& destination);
bool DarwinCFStringRefToUTF8String(CFStringRef source, std::string& destination);
#ifdef __cplusplus
}
#endif
Expand Down
18 changes: 14 additions & 4 deletions xbmc/osx/DarwinUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -393,19 +393,19 @@ void DarwinSetScheduling(int message)
result = pthread_setschedparam(this_pthread_self, policy, &param );
}

bool DarwinCFStringRefToString(CFStringRef source, std::string &destination)
bool DarwinCFStringRefToStringWithEncoding(CFStringRef source, std::string &destination, CFStringEncoding encoding)
{
const char *cstr = CFStringGetCStringPtr(source, CFStringGetSystemEncoding());
const char *cstr = CFStringGetCStringPtr(source, encoding);
if (!cstr)
{
CFIndex strLen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(source) + 1,
CFStringGetSystemEncoding());
encoding);
char *allocStr = (char*)malloc(strLen);

if(!allocStr)
return false;

if(!CFStringGetCString(source, allocStr, strLen, CFStringGetSystemEncoding()))
if(!CFStringGetCString(source, allocStr, strLen, encoding))
{
free((void*)allocStr);
return false;
Expand All @@ -421,4 +421,14 @@ bool DarwinCFStringRefToString(CFStringRef source, std::string &destination)
return true;
}

bool DarwinCFStringRefToString(CFStringRef source, std::string &destination)
{
return DarwinCFStringRefToStringWithEncoding(source, destination, CFStringGetSystemEncoding());
}

bool DarwinCFStringRefToUTF8String(CFStringRef source, std::string &destination)
{
return DarwinCFStringRefToStringWithEncoding(source, destination, kCFStringEncodingUTF8);
}

#endif
2 changes: 1 addition & 1 deletion xbmc/peripherals/bus/osx/PeripheralBusUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void CPeripheralBusUSB::DeviceAttachCallback(CPeripheralBusUSB* refCon, io_itera
if (deviceFilePathAsCFString)
{
// Convert the path from a CFString to a std::string
if (!DarwinCFStringRefToString(deviceFilePathAsCFString, ttlDeviceFilePath))
if (!DarwinCFStringRefToUTF8String(deviceFilePathAsCFString, ttlDeviceFilePath))
CLog::Log(LOGWARNING, "CPeripheralBusUSB::DeviceAttachCallback failed to convert CFStringRef");
CFRelease(deviceFilePathAsCFString);
}
Expand Down
2 changes: 1 addition & 1 deletion xbmc/windowing/osx/WinSystemOSX.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ static void DisplayReconfigured(CGDirectDisplayID display,
if (!obscureLogged)
{
std::string appName;
if (DarwinCFStringRefToString(ownerName, appName))
if (DarwinCFStringRefToUTF8String(ownerName, appName))
CLog::Log(LOGDEBUG, "WinSystemOSX: Fullscreen window %s obscures XBMC!", appName.c_str());
obscureLogged = true;
}
Expand Down

0 comments on commit b8e0db7

Please sign in to comment.