| 97 | } |
| 98 | |
| 99 | std::string Url::encode( const std::string &unescaped ) |
| 100 | { |
| 101 | #if defined( CINDER_COCOA ) |
| 102 | cocoa::SafeCfString unescapedStr = cocoa::createSafeCfString( unescaped ); |
| 103 | CFStringRef escaped = ::CFURLCreateStringByAddingPercentEscapes( kCFAllocatorDefault, unescapedStr.get(), NULL, NULL, kCFStringEncodingUTF8 ); |
| 104 | std::string result = cocoa::convertCfString( escaped ); |
| 105 | ::CFRelease( escaped ); |
| 106 | return result; |
| 107 | #elif defined( CINDER_MSW_DESKTOP ) |
| 108 | char16_t buffer[4096]; |
| 109 | DWORD bufferSize = 4096; |
| 110 | std::u16string wideUnescaped = toUtf16( unescaped ); |
| 111 | UrlEscape( (wchar_t*)wideUnescaped.c_str(), (wchar_t*)buffer, &bufferSize, 0 ); |
| 112 | return toUtf8( buffer ); |
| 113 | #elif defined( CINDER_ANDROID ) |
| 114 | std::string result = urlencode( unescaped ); |
| 115 | return result; |
| 116 | #elif defined( CINDER_LINUX ) |
| 117 | // Curl does not seem to agree with encoded URIs. |
| 118 | return unescaped; |
| 119 | #endif |
| 120 | } |
| 121 | |
| 122 | |
| 123 | ////////////////////////////////////////////////////////////////////////////////////////////////////// |