1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _CFSTRINGUTILITIES_HXX_
25 #define _CFSTRINGUTILITIES_HXX_
26 
27 #include <premac.h>
28 #include <Carbon/Carbon.h>
29 #include <Cocoa/Cocoa.h>
30 #include <CoreFoundation/CoreFoundation.h>
31 #include <postmac.h>
32 #include <rtl/ustring.hxx>
33 #include <sal/types.h>
34 #include <osl/diagnose.h>
35 
36 enum InfoType {
37     FULLPATH,
38     FILENAME,
39     PATHWITHOUTLASTCOMPONENT
40 };
41 
42 rtl::OUString CFStringToOUString(const CFStringRef sOrig);
43 rtl::OUString FSRefToOUString(FSRef fsRef, InfoType info = FULLPATH);
44 rtl::OUString CFURLRefToOUString(CFURLRef aUrlRef, InfoType info);
45 CFStringRef CFStringCreateWithOUString(const rtl::OUString& aString);
46 
47 //debug utils
48 #define PARAMFILLER "\n                    "
49 
DBG_PRINT_ENTRY()50 inline void DBG_PRINT_ENTRY() {
51     OSL_TRACE(">>> %s", __func__);
52 }
53 
DBG_PRINT_ENTRY(const char * classname,const char * methodname)54 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname) {
55     OSL_TRACE(">>> %s::%s", classname, methodname);
56 }
57 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const char * value1)58 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const char* value1) {
59     OSL_TRACE(">>> %s::%s%s%s = %s", classname, methodname, PARAMFILLER, param1, value1);
60 }
61 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const rtl::OUString & value1)62 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const rtl::OUString& value1) {
63     OSL_TRACE(">>> %s::%s%s%s = %s", classname, methodname, PARAMFILLER, param1, OUStringToOString(value1, RTL_TEXTENCODING_UTF8).getStr());
64 }
65 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const CFStringRef value1)66 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const CFStringRef value1) {
67     OSL_TRACE(">>> %s::%s%s%s =", classname, methodname, PARAMFILLER, param1);
68 #if OSL_DEBUG_LEVEL > 1
69     CFShow(value1);
70 #endif
71 }
72 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const NSString * value1)73 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const NSString* value1) {
74     OSL_TRACE(">>> %s::%s%s%s =", classname, methodname, PARAMFILLER, param1);
75 #if OSL_DEBUG_LEVEL > 1
76     NSLog( const_cast<NSString*>(value1));
77 #endif
78 }
79 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const int value1)80 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const int value1) {
81     OSL_TRACE(">>> %s::%s%s%s = %d", classname, methodname, PARAMFILLER, param1, value1);
82 }
83 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const char * value1,const char * param2,const int value2)84 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const char* value1, const char* param2, const int value2) {
85     OSL_TRACE(">>> %s::%s%s%s = %s%s%s = %d", classname, methodname, PARAMFILLER, param1, value1, PARAMFILLER, param2, value2);
86 }
87 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const char * value1,const char * param2,const char * value2)88 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const char* value1, const char* param2, const char* value2) {
89     OSL_TRACE(">>> %s::%s%s%s = %s%s%s = %s", classname, methodname, PARAMFILLER, param1, value1, PARAMFILLER, param2, value2);
90 }
91 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const int value1,const char * param2,const int value2)92 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const int value1, const char* param2, const int value2) {
93     OSL_TRACE(">>> %s::%s%s%s = %d%s%s = %d", classname, methodname, PARAMFILLER, param1, value1, PARAMFILLER, param2, value2);
94 }
95 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const int value1,const char * param2,const char * value2)96 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const int value1, const char* param2, const char* value2) {
97     OSL_TRACE(">>> %s::%s%s%s = %d%s%s = %s", classname, methodname, PARAMFILLER, param1, value1, PARAMFILLER, param2, value2);
98 }
99 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const int value1,const char * param2,const CFStringRef value2)100 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const int value1, const char* param2, const CFStringRef value2) {
101     OSL_TRACE(">>> %s::%s%s%s = %d%s%s =", classname, methodname, PARAMFILLER, param1, value1, PARAMFILLER, param2, value2);
102 #if OSL_DEBUG_LEVEL > 1
103     CFShow(value2);
104 #endif
105 }
106 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const int value1,const char * param2,const NSString * value2)107 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const int value1, const char* param2, const NSString* value2) {
108     OSL_TRACE(">>> %s::%s%s%s = %d%s%s =", classname, methodname, PARAMFILLER, param1, value1, PARAMFILLER, param2, value2);
109 #if OSL_DEBUG_LEVEL > 1
110     NSLog( const_cast<NSString*>(value2));
111 #endif
112 }
113 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const rtl::OUString & value1,const char * param2,const rtl::OUString & value2)114 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const rtl::OUString& value1, const char* param2, const rtl::OUString& value2) {
115     OSL_TRACE(">>> %s::%s%s%s = %s%s%s = %s", classname, methodname, PARAMFILLER, param1, OUStringToOString(value1, RTL_TEXTENCODING_UTF8).getStr(), PARAMFILLER, param2, OUStringToOString(value2, RTL_TEXTENCODING_UTF8).getStr());
116 }
117 
DBG_PRINT_ENTRY(const char * classname,const char * methodname,const char * param1,const rtl::OUString & value1,const char * param2,const int value2)118 inline void DBG_PRINT_ENTRY(const char * classname, const char * methodname, const char* param1, const rtl::OUString& value1, const char* param2, const int value2) {
119     OSL_TRACE(">>> %s::%s%s%s = %s%s%s = %d", classname, methodname, PARAMFILLER, param1, OUStringToOString(value1, RTL_TEXTENCODING_UTF8).getStr(), PARAMFILLER, param2, value2);
120 }
121 
122 //exit method debugs
123 
DBG_PRINT_EXIT()124 inline void DBG_PRINT_EXIT() {
125     OSL_TRACE("<<< %s", __func__);
126 }
127 
DBG_PRINT_EXIT(const char * classname,const char * methodname)128 inline void DBG_PRINT_EXIT(const char * classname, const char * methodname) {
129     OSL_TRACE("<<< %s::%s", classname, methodname);
130 }
131 
DBG_PRINT_EXIT(const char * classname,const char * methodname,const char * retVal)132 inline void DBG_PRINT_EXIT(const char * classname, const char * methodname, const char* retVal) {
133     OSL_TRACE("<<< %s::%s%sreturnValue = %s", classname, methodname, PARAMFILLER, retVal);
134 }
135 
DBG_PRINT_EXIT(const char * classname,const char * methodname,int retVal)136 inline void DBG_PRINT_EXIT(const char * classname, const char * methodname, int retVal) {
137     OSL_TRACE("<<< %s::%s%sreturnValue = %d", classname, methodname, PARAMFILLER, retVal);
138 }
139 
DBG_PRINT_EXIT(const char * classname,const char * methodname,const CFStringRef retVal)140 inline void DBG_PRINT_EXIT(const char * classname, const char * methodname, const CFStringRef retVal) {
141     OSL_TRACE("<<< %s::%s%sreturnValue = ", classname, methodname, PARAMFILLER);
142 #if OSL_DEBUG_LEVEL > 1
143     CFShow(retVal);
144 #endif
145 }
146 
DBG_PRINT_EXIT(const char * classname,const char * methodname,const NSString * retVal)147 inline void DBG_PRINT_EXIT(const char * classname, const char * methodname, const NSString* retVal) {
148     OSL_TRACE("<<< %s::%s%sreturnValue = ", classname, methodname, PARAMFILLER);
149 #if OSL_DEBUG_LEVEL > 1
150     NSLog( const_cast<NSString*>(retVal));
151 #endif
152 }
153 
DBG_PRINT_EXIT(const char * classname,const char * methodname,const rtl::OUString & retVal)154 inline void DBG_PRINT_EXIT(const char * classname, const char * methodname, const rtl::OUString& retVal) {
155     OSL_TRACE("<<< %s::%s%sreturnValue = %s", classname, methodname, PARAMFILLER, OUStringToOString(retVal, RTL_TEXTENCODING_UTF8).getStr());
156 }
157 
158 #endif //_CFSTRINGUTILITIES_HXX_
159