Ocean
StringApple.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_BASE_STRING_APPLE_H
9 #define META_OCEAN_BASE_STRING_APPLE_H
10 
11 #include "ocean/base/Base.h"
12 #include "ocean/base/String.h"
13 
14 #ifndef __APPLE__
15  #error This library is available on Apple platforms only!
16 #endif
17 
18 #include <CoreFoundation/CoreFoundation.h>
19 
20 #ifdef __OBJC__
21  #include <Foundation/Foundation.h>
22 #endif
23 
24 namespace Ocean
25 {
26 
27 /**
28  * This class provides function allowing to convert Apple-platform specific string objects.
29  * Beware: This class is implemented for Apple-platforms only and therefore, it is recommended to use this class in non-header files only to reduce issues with the Objective C compiler.
30  * @ingroup base
31  */
32 class OCEAN_BASE_EXPORT StringApple
33 {
34  public:
35 
36 #ifdef __OBJC__
37 
38  /**
39  * Converts a given string to a NSString object.
40  * @param value The string to convert, may be empty
41  * @return The resulting converted string object
42  */
43  static NSString* toNSString(const std::string& value);
44 
45  /**
46  * Converts a given string to a NSString object.
47  * @param value The string to convert, may be empty
48  * @return The resulting converted string object
49  */
50  static NSString* toNSString(const std::wstring& value);
51 
52  /**
53  * Converts a given NSString object to a string with UTF8 encoding.
54  * @param object The string object to convert, may be nullptr
55  * @return The resulting string with UTF8 encoding
56  */
57  static std::string toUTF8(NSString* object);
58 
59  /**
60  * Converts a given NSString object to a string with 32 bit character encoding.
61  * @param object The string object to convert, may be nullptr
62  * @return The resulting string with 32 bit character encoding
63  */
64  static std::wstring toWString(NSString* object);
65 
66 #endif
67 
68  /**
69  * Converts a given CFStringRef object to a string with UTF8 encoding.
70  * @param object The string object to convert, may be nullptr
71  * @return The resulting string with UTF8 encoding
72  */
73  static std::string toUTF8(CFStringRef object);
74 
75  /**
76  * Converts a given CFStringRef object to a string with 32 bit character encoding.
77  * @param object The string object to convert, may be nullptr
78  * @return The resulting string with 32 bit character encoding
79  */
80  static std::wstring toWString(CFStringRef object);
81 };
82 
83 }
84 
85 #endif // META_OCEAN_BASE_STRING_APPLE_H
This class provides function allowing to convert Apple-platform specific string objects.
Definition: StringApple.h:33
static NSString * toNSString(const std::wstring &value)
Converts a given string to a NSString object.
static std::wstring toWString(NSString *object)
Converts a given NSString object to a string with 32 bit character encoding.
static NSString * toNSString(const std::string &value)
Converts a given string to a NSString object.
static std::string toUTF8(NSString *object)
Converts a given NSString object to a string with UTF8 encoding.
static std::wstring toWString(CFStringRef object)
Converts a given CFStringRef object to a string with 32 bit character encoding.
static std::string toUTF8(CFStringRef object)
Converts a given CFStringRef object to a string with UTF8 encoding.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15