FROM : Stephane Sudre
DATE : Tue Mar 04 11:21:36 2008
On 4 mars 08, at 10:28, Julien Jalon wrote:
> 1) Might not be a good idea to use CFStringGetCStringPtr as it might
> return
> NULL2) kCFStringEncodingMacRoman is likely not a good choice as the
> encoding, especially for localized strings
>
> If I were you, I'd do something like (warning: Mail compiled code):
> const char* MyGetLocalizedCString(CFStringRef string)
> {
> // if you need to be thread safe, add proper locks around that
> static CFMutableDictionaryRef mapping = NULL;
> if(mapping == NULL) {
> mapping = CFDictionaryCreateMutable(NULL, 0,
> &kCFTypeDictionaryKeyCallBacks, NULL);
> }
>
> const char* result = (const char *)CFDictionaryGetValue(mapping,
> string);
> if(result == NULL) {
> CFStringRef localizedString =
> CFCopyLocalizedStringFromTable(string,
> CFSTR("LibraryLocalizable"), NULL);
> result = (const char
> *)malloc(CFStringGetMaximumSizeForEncoding(CFStringGetLength(localizedS
> tring),
> kCFStringEncodingUTF8);
> CFStringGetCString(localizedString, (char *)result, bufferSize,
> kCFStringEncodingUTF8);
> CFDictionarySetValue(mapping, string, result);
I'm not sure CFDictionarySetValue would accept a char *.
DATE : Tue Mar 04 11:21:36 2008
On 4 mars 08, at 10:28, Julien Jalon wrote:
> 1) Might not be a good idea to use CFStringGetCStringPtr as it might
> return
> NULL2) kCFStringEncodingMacRoman is likely not a good choice as the
> encoding, especially for localized strings
>
> If I were you, I'd do something like (warning: Mail compiled code):
> const char* MyGetLocalizedCString(CFStringRef string)
> {
> // if you need to be thread safe, add proper locks around that
> static CFMutableDictionaryRef mapping = NULL;
> if(mapping == NULL) {
> mapping = CFDictionaryCreateMutable(NULL, 0,
> &kCFTypeDictionaryKeyCallBacks, NULL);
> }
>
> const char* result = (const char *)CFDictionaryGetValue(mapping,
> string);
> if(result == NULL) {
> CFStringRef localizedString =
> CFCopyLocalizedStringFromTable(string,
> CFSTR("LibraryLocalizable"), NULL);
> result = (const char
> *)malloc(CFStringGetMaximumSizeForEncoding(CFStringGetLength(localizedS
> tring),
> kCFStringEncodingUTF8);
> CFStringGetCString(localizedString, (char *)result, bufferSize,
> kCFStringEncodingUTF8);
> CFDictionarySetValue(mapping, string, result);
I'm not sure CFDictionarySetValue would accept a char *.
| Related mails | Author | Date |
|---|---|---|
| Mitchell Livingsto… | Mar 4, 03:53 | |
| Deborah Goldsmith | Mar 4, 04:20 | |
| Julien Jalon | Mar 4, 10:28 | |
| Stephane Sudre | Mar 4, 11:21 | |
| Jean-Daniel Dupas | Mar 4, 11:27 | |
| Stephane Sudre | Mar 4, 13:12 |






Cocoa mail archive

