diff options
author | Daniel Wilhelm <daniel@wili.li> | 2015-10-02 14:49:33 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2015-10-02 14:49:33 +0200 |
commit | a6e9143baf48bdc093788545636570808f9c103c (patch) | |
tree | d223a9360134cd8105a96ee0faf5c2643bd9141b /zen/osx_string.h | |
parent | 6.4 (diff) | |
download | FreeFileSync-a6e9143baf48bdc093788545636570808f9c103c.tar.gz FreeFileSync-a6e9143baf48bdc093788545636570808f9c103c.tar.bz2 FreeFileSync-a6e9143baf48bdc093788545636570808f9c103c.zip |
6.5
Diffstat (limited to 'zen/osx_string.h')
-rw-r--r-- | zen/osx_string.h | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/zen/osx_string.h b/zen/osx_string.h deleted file mode 100644 index ba83ca27..00000000 --- a/zen/osx_string.h +++ /dev/null @@ -1,82 +0,0 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** - -#ifndef OSX_STRING_1873641732143214324 -#define OSX_STRING_1873641732143214324 - -#include <CoreFoundation/CoreFoundation.h> //CFString -#include "zstring.h" - -namespace osx -{ -Zstring cfStringToZstring(const CFStringRef& cfStr); - -CFStringRef createCFString (const char* utf8Str); //returns nullptr on error -CFMutableStringRef createMutableCFString(const char* utf8Str); //pass ownership! => ZEN_ON_SCOPE_EXIT(::CFRelease(str)); - - - - - - - - - - - - - -//################# implementation ##################### -inline -Zstring cfStringToZstring(const CFStringRef& cfStr) -{ - if (cfStr) - { - //perf: try to get away cheap: - if (const char* utf8Str = ::CFStringGetCStringPtr(cfStr, kCFStringEncodingUTF8)) - return utf8Str; - - CFIndex length = ::CFStringGetLength(cfStr); - if (length > 0) - { - CFIndex bufferSize = ::CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8); - Zstring buffer; - buffer.resize(bufferSize); - - if (::CFStringGetCString(cfStr, &*buffer.begin(), bufferSize, kCFStringEncodingUTF8)) - { - buffer.resize(zen::strLength(buffer.c_str())); //caveat: memory consumption of returned string! - return buffer; - } - } - } - return Zstring(); -} - - -inline -CFStringRef createCFString(const char* utf8Str) -{ - //don't bother with CFStringCreateWithBytes: it's slightly slower, despite passing length info - return ::CFStringCreateWithCString(nullptr, //CFAllocatorRef alloc, - utf8Str, //const char *cStr, - kCFStringEncodingUTF8); //CFStringEncoding encoding -} - - -inline -CFMutableStringRef createMutableCFString(const char* utf8Str) -{ - if (CFMutableStringRef strRef = ::CFStringCreateMutable(NULL, 0)) - { - ::CFStringAppendCString(strRef, utf8Str, kCFStringEncodingUTF8); - return strRef; - } - return nullptr; -} -} - -#endif //OSX_STRING_1873641732143214324 |