update emoji autocorrect entries from po-files
[LibreOffice.git] / fpicker / source / aqua / CFStringUtilities.mm
blobc1f0c5b905731f4433afb696609dc2cce32fbd1e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
20 #include "sal/log.hxx"
21 #include "CFStringUtilities.hxx"
23 rtl::OUString CFStringToOUString(const CFStringRef sOrig) {
24     //DBG_PRINT_ENTRY("CFStringUtilities", __func__, "sOrig", sOrig);
26     if (NULL == sOrig) {
27         return rtl::OUString();
28     }
30     CFRetain(sOrig);
31     CFIndex nFileNameLength = CFStringGetLength(sOrig);
32     //SAL_INFO("fpicker.aqua","FH: string length: " << (int)(nFileNameLength));
33     UniChar unichars[nFileNameLength+1];
34     //'close' the string buffer correctly
35     unichars[nFileNameLength] = '\0';
37     CFStringGetCharacters (sOrig, CFRangeMake(0,nFileNameLength), unichars);
39     //we no longer need the original string
40     CFRelease(sOrig);
42     //DBG_PRINT_EXIT("CFStringUtilities", __func__, unichars);
44     return rtl::OUString(unichars);
47 CFStringRef CFStringCreateWithOUString(const rtl::OUString& aString) {
48     //DBG_PRINT_ENTRY("CFStringUtilities", __func__);
50     CFStringRef ref = CFStringCreateWithCharacters(kCFAllocatorDefault, aString.getStr(), aString.getLength());
52     //DBG_PRINT_EXIT("CFStringUtilities", __func__, ref);
54     return ref;
57 rtl::OUString FSRefToOUString(FSRef const & fsRef, InfoType info)
59     //DBG_PRINT_ENTRY("CFStringUtilities", __func__);
61     SAL_WNODEPRECATED_DECLARATIONS_PUSH //TODO: 10.9 CFURLCreateFromFSRef
62     CFURLRef aUrlRef = CFURLCreateFromFSRef(NULL, &fsRef);
63     SAL_WNODEPRECATED_DECLARATIONS_POP
65     rtl::OUString sResult = CFURLRefToOUString(aUrlRef, info);
67     //we no longer need the CFURLRef
68     CFRelease(aUrlRef);
70     //DBG_PRINT_EXIT("CFStringUtilities", __func__, OUStringToOString(sResult, RTL_TEXTENCODING_UTF8).getStr());
72     return sResult;
75 rtl::OUString CFURLRefToOUString(CFURLRef aUrlRef, InfoType info)
77     //DBG_PRINT_ENTRY("CFStringUtilities", __func__);
79     CFStringRef sURLString = NULL;
81     switch(info) {
82         case FULLPATH:
83             SAL_INFO("fpicker.aqua","Extracting the full path of an item");
84             sURLString = CFURLGetString(aUrlRef);
85             CFRetain(sURLString);
86             break;
87         case FILENAME:
88             {
89                 SAL_INFO("fpicker.aqua","Extracting the file name of an item");
90                 CFStringRef fullString = CFURLGetString(aUrlRef);
91                 CFURLRef dirRef = CFURLCreateCopyDeletingLastPathComponent(NULL,aUrlRef);
92                 CFIndex dirLength = CFStringGetLength(CFURLGetString(dirRef));
93                 CFRelease(dirRef);
94                 CFIndex fullLength = CFStringGetLength(fullString);
95                 CFRange substringRange = CFRangeMake(dirLength, fullLength - dirLength);
96                 sURLString = CFStringCreateWithSubstring(NULL, fullString, substringRange);
97             }
98             break;
99         case PATHWITHOUTLASTCOMPONENT:
100             {
101                 SAL_INFO("fpicker.aqua","Extracting the last but one component of an item's path");
102                 CFURLRef directoryRef = CFURLCreateCopyDeletingLastPathComponent(NULL,aUrlRef);
103                 sURLString = CFURLGetString(directoryRef);
104                 CFRetain(sURLString);
105                 CFRelease(directoryRef);
106             }
107             break;
108         default:
109             break;
110     }
112     rtl::OUString sResult = CFStringToOUString(sURLString);
114     CFRelease(sURLString);
116     //DBG_PRINT_EXIT("CFStringUtilities", __func__, OUStringToOString(sResult, RTL_TEXTENCODING_UTF8).getStr());
118     return sResult;
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */