1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CFStringUtilities.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <osl/diagnose.h>
32 #include "CFStringUtilities.hxx"
34 rtl::OUString
CFStringToOUString(const CFStringRef sOrig
) {
35 //DBG_PRINT_ENTRY("CFStringUtilities", __func__, "sOrig", sOrig);
38 return rtl::OUString();
42 CFIndex nFileNameLength
= CFStringGetLength(sOrig
);
43 //OSL_TRACE("FH: string length: %d", (int)(nFileNameLength));
44 UniChar unichars
[nFileNameLength
+1];
45 //'close' the string buffer correctly
46 unichars
[nFileNameLength
] = '\0';
48 CFStringGetCharacters (sOrig
, CFRangeMake(0,nFileNameLength
), unichars
);
50 //we no longer need the original string
53 //DBG_PRINT_EXIT("CFStringUtilities", __func__, unichars);
55 return rtl::OUString(unichars
);
58 CFStringRef
CFStringCreateWithOUString(const rtl::OUString
& aString
) {
59 //DBG_PRINT_ENTRY("CFStringUtilities", __func__);
61 CFStringRef ref
= CFStringCreateWithCharacters(kCFAllocatorDefault
, aString
.getStr(), aString
.getLength());
63 //DBG_PRINT_EXIT("CFStringUtilities", __func__, ref);
68 rtl::OUString
FSRefToOUString(FSRef fsRef
, InfoType info
)
70 //DBG_PRINT_ENTRY("CFStringUtilities", __func__);
72 CFURLRef aUrlRef
= CFURLCreateFromFSRef(NULL
, &fsRef
);
74 rtl::OUString sResult
= CFURLRefToOUString(aUrlRef
, info
);
76 //we no longer need the CFURLRef
79 //DBG_PRINT_EXIT("CFStringUtilities", __func__, OUStringToOString(sResult, RTL_TEXTENCODING_UTF8).getStr());
84 rtl::OUString
CFURLRefToOUString(CFURLRef aUrlRef
, InfoType info
)
86 //DBG_PRINT_ENTRY("CFStringUtilities", __func__);
88 CFStringRef sURLString
= NULL
;
92 OSL_TRACE("Extracting the full path of an item");
93 sURLString
= CFURLGetString(aUrlRef
);
97 OSL_TRACE("Extracting the file name of an item");
98 CFStringRef fullString
= CFURLGetString(aUrlRef
);
99 CFURLRef dirRef
= CFURLCreateCopyDeletingLastPathComponent(NULL
,aUrlRef
);
100 CFIndex dirLength
= CFStringGetLength(CFURLGetString(dirRef
));
102 CFIndex fullLength
= CFStringGetLength(fullString
);
103 CFRange substringRange
= CFRangeMake(dirLength
, fullLength
- dirLength
);
104 sURLString
= CFStringCreateWithSubstring(NULL
, fullString
, substringRange
);
106 case PATHWITHOUTLASTCOMPONENT
:
107 OSL_TRACE("Extracting the last but one component of an item's path");
108 CFURLRef directoryRef
= CFURLCreateCopyDeletingLastPathComponent(NULL
,aUrlRef
);
109 sURLString
= CFURLGetString(directoryRef
);
110 CFRetain(sURLString
);
111 CFRelease(directoryRef
);
117 rtl::OUString sResult
= CFStringToOUString(sURLString
);
119 CFRelease(sURLString
);
121 //DBG_PRINT_EXIT("CFStringUtilities", __func__, OUStringToOString(sResult, RTL_TEXTENCODING_UTF8).getStr());