本文整理匯總了C++中CFStringGetCharacters函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFStringGetCharacters函數的具體用法?C++ CFStringGetCharacters怎麽用?C++ CFStringGetCharacters使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFStringGetCharacters函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: CFStringCompareWithOptionsAndLocale
CFComparisonResult
CFStringCompareWithOptionsAndLocale (CFStringRef str1,
CFStringRef str2, CFRange rangeToCompare,
CFStringCompareFlags compareOptions, CFLocaleRef locale)
{
CFComparisonResult ret;
UniChar *string1;
UniChar *string2;
CFIndex length1;
CFIndex length2;
CFAllocatorRef alloc;
UCollator *ucol;
alloc = CFAllocatorGetDefault ();
length1 = rangeToCompare.length;
string1 = CFAllocatorAllocate (alloc, (length1) * sizeof(UniChar), 0);
CFStringGetCharacters (str1, rangeToCompare, string1);
length2 = CFStringGetLength (str2);
string2 = CFAllocatorAllocate (alloc, (length2) * sizeof(UniChar), 0);
CFStringGetCharacters (str2, CFRangeMake(0, length2), string2);
ucol = CFStringICUCollatorOpen (compareOptions, locale);
ret = ucol_strcoll (ucol, string2, length2, string1, length1);
CFStringICUCollatorClose (ucol);
CFAllocatorDeallocate (alloc, string1);
CFAllocatorDeallocate (alloc, string2);
return ret;
}
示例2: CFLocaleCreateComponentsFromLocaleIdentifier
CF_PRIVATE UCalendar *__CFCalendarCreateUCalendar(CFStringRef calendarID, CFStringRef localeID, CFTimeZoneRef tz) {
if (calendarID) {
CFDictionaryRef components = CFLocaleCreateComponentsFromLocaleIdentifier(kCFAllocatorSystemDefault, localeID);
CFMutableDictionaryRef mcomponents = CFDictionaryCreateMutableCopy(kCFAllocatorSystemDefault, 0, components);
CFDictionarySetValue(mcomponents, kCFLocaleCalendarIdentifier, calendarID);
localeID = CFLocaleCreateLocaleIdentifierFromComponents(kCFAllocatorSystemDefault, mcomponents);
CFRelease(mcomponents);
CFRelease(components);
}
char buffer[BUFFER_SIZE];
const char *cstr = CFStringGetCStringPtr(localeID, kCFStringEncodingASCII);
if (NULL == cstr) {
if (CFStringGetCString(localeID, buffer, BUFFER_SIZE, kCFStringEncodingASCII)) cstr = buffer;
}
if (NULL == cstr) {
if (calendarID) CFRelease(localeID);
return NULL;
}
UChar ubuffer[BUFFER_SIZE];
CFStringRef tznam = CFTimeZoneGetName(tz);
CFIndex cnt = CFStringGetLength(tznam);
if (BUFFER_SIZE < cnt) cnt = BUFFER_SIZE;
CFStringGetCharacters(tznam, CFRangeMake(0, cnt), (UniChar *)ubuffer);
UErrorCode status = U_ZERO_ERROR;
UCalendar *cal = ucal_open(ubuffer, cnt, cstr, UCAL_DEFAULT, &status);
if (calendarID) CFRelease(localeID);
return cal;
}
示例3: debugstr_cf
/**************************************************************************
* debugstr_cf
*/
const char* debugstr_cf(CFTypeRef t)
{
CFStringRef s;
const char* ret;
if (!t) return "(null)";
if (CFGetTypeID(t) == CFStringGetTypeID())
s = t;
else
s = CFCopyDescription(t);
ret = CFStringGetCStringPtr(s, kCFStringEncodingUTF8);
if (ret) ret = debugstr_a(ret);
if (!ret)
{
const UniChar* u = CFStringGetCharactersPtr(s);
if (u)
ret = debugstr_wn((const WCHAR*)u, CFStringGetLength(s));
}
if (!ret)
{
UniChar buf[200];
int len = min(CFStringGetLength(s), sizeof(buf)/sizeof(buf[0]));
CFStringGetCharacters(s, CFRangeMake(0, len), buf);
ret = debugstr_wn(buf, len);
}
if (s != t) CFRelease(s);
return ret;
}
示例4: getJString
static jstring getJString(JNIEnv *env, CFStringRef cs) {
if (cs == NULL) return NULL;
CFRange range = CFRangeMake(0, CFStringGetLength(cs));
UniChar *chars = alloca(range.length);
CFStringGetCharacters(cs, range, chars);
return (*env)->NewString(env, (jchar *) chars, (jsize) range.length);
}
示例5: MultiByteToWideChar
void ARRAY_TEXT::convertFromUTF8(const CUTF8String* fromString, CUTF16String* toString)
{
#ifdef _WIN32
int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)fromString->c_str(), fromString->length(), NULL, 0);
if(len){
std::vector<uint8_t> buf((len + 1) * sizeof(PA_Unichar));
if(MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)fromString->c_str(), fromString->length(), (LPWSTR)&buf[0], len)){
*toString = CUTF16String((const PA_Unichar *)&buf[0]);
}
}else{
*toString = CUTF16String((const PA_Unichar *)L"");
}
#else
CFStringRef str = CFStringCreateWithBytes(kCFAllocatorDefault, fromString->c_str(), fromString->length(), kCFStringEncodingUTF8, true);
if(str){
int len = CFStringGetLength(str)+1;
std::vector<uint8_t> buf(len * sizeof(PA_Unichar));
CFStringGetCharacters(str, CFRangeMake(0, len), (UniChar *)&buf[0]);
*toString = CUTF16String((const PA_Unichar *)&buf[0]);
CFRelease(str);
}
#endif
}
示例6: callback
static void callback(
ConstFSEventStreamRef streamRef,
void *clientCallBackInfo,
size_t numEvents,
void *eventPathsVoid,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[])
{
qDebug() << "FolderWatcherPrivate::callback by OS X";
QStringList paths;
CFArrayRef eventPaths = (CFArrayRef)eventPathsVoid;
for (int i = 0; i < numEvents; ++i) {
CFStringRef path = reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(eventPaths, i));
QString qstring;
CFIndex pathLength = CFStringGetLength(path);
qstring.resize(pathLength);
CFStringGetCharacters(path, CFRangeMake(0, pathLength), reinterpret_cast<UniChar *>(qstring.data()));
paths.append(qstring);
}
reinterpret_cast<FolderWatcherPrivate*>(clientCallBackInfo)->doNotifyParent(paths);
}
示例7: FindSNESFolder
static OSStatus FindSNESFolder (FSRef *folderRef, char *folderPath, const char *folderName)
{
OSStatus err;
CFURLRef burl, purl;
CFStringRef fstr;
FSRef pref;
UniChar buffer[PATH_MAX + 1];
Boolean r;
fstr = CFStringCreateWithCString(kCFAllocatorDefault, folderName, CFStringGetSystemEncoding());
CFStringGetCharacters(fstr, CFRangeMake(0, CFStringGetLength(fstr)), buffer);
burl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
purl = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, burl);
r = CFURLGetFSRef(purl, &pref);
err = FSMakeFSRefUnicode(&pref, CFStringGetLength(fstr), buffer, kTextEncodingUnicodeDefault, folderRef);
if (err == dirNFErr || err == fnfErr)
{
err = FSCreateDirectoryUnicode(&pref, CFStringGetLength(fstr), buffer, kFSCatInfoNone, NULL, folderRef, NULL, NULL);
if (err == noErr)
AddFolderIcon(folderRef, folderName);
}
if (err == noErr)
err = FSRefMakePath(folderRef, (unsigned char *) folderPath, PATH_MAX);
CFRelease(purl);
CFRelease(burl);
CFRelease(fstr);
return (err);
}
示例8: createJavaString
jstring createJavaString(JNIEnv *env, CFStringRef stringRef)
{
CFIndex length = CFStringGetLength(stringRef);
UniChar buffer[length];
CFStringGetCharacters(stringRef, CFRangeMake(0, length), buffer);
return (*env)->NewString(env, (jchar *)buffer, length);
}
示例9: GetEncTable
static const wxUint16* GetEncTable(wxFontEncoding enc)
{
#ifdef __WXMAC__
if( enc >= wxFONTENCODING_MACMIN && enc <= wxFONTENCODING_MACMAX )
{
int i = enc-wxFONTENCODING_MACMIN ;
if ( gMacEncodingsInited[i] == false )
{
// create
CFStringEncoding cfencoding = wxMacGetSystemEncFromFontEnc( enc ) ;
if( !CFStringIsEncodingAvailable( cfencoding ) )
return NULL;
memset( gMacEncodings[i] , 0 , 128 * 2 );
char s[2] = { 0 , 0 };
CFRange firstchar = CFRangeMake( 0, 1 );
for( unsigned char c = 255 ; c >= 128 ; --c )
{
s[0] = c ;
wxCFStringRef cfref( CFStringCreateWithCStringNoCopy( NULL, s, cfencoding , kCFAllocatorNull ) );
CFStringGetCharacters( cfref, firstchar, (UniChar*) &gMacEncodings[i][c-128] );
}
gMacEncodingsInited[i]=true;
}
return gMacEncodings[i] ;
}
#endif
for (int i = 0; encodings_list[i].table != NULL; i++)
{
if (encodings_list[i].encoding == enc)
return encodings_list[i].table;
}
return NULL;
}
示例10: __CFLocaleICUCurrencyName
static bool __CFLocaleICUCurrencyName(const char *locale, const char *value, UCurrNameStyle style, CFStringRef *out) {
size_t valLen = strlen(value);
if (valLen != 3) // not a valid ISO code
return false;
UChar curr[4];
UBool isChoice = FALSE;
int32_t size = 0;
UErrorCode icuStatus = U_ZERO_ERROR;
u_charsToUChars(value, curr, (int32_t)valLen);
curr[valLen] = '\0';
const UChar *name;
name = ucurr_getName(curr, locale, style, &isChoice, &size, &icuStatus);
if (U_FAILURE(icuStatus) || icuStatus == U_USING_DEFAULT_WARNING)
return false;
UChar result[kMaxICUNameSize];
if (isChoice)
{
UChar pattern[kMaxICUNameSize];
CFStringRef patternRef = CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, CFSTR("{0,choice,%S}"), name);
CFIndex pattlen = CFStringGetLength(patternRef);
CFStringGetCharacters(patternRef, CFRangeMake(0, pattlen), (UniChar *)pattern);
CFRelease(patternRef);
pattern[pattlen] = '\0'; // null terminate the pattern
// Format the message assuming a large amount of the currency
size = u_formatMessage("en_US", pattern, pattlen, result, kMaxICUNameSize, &icuStatus, 10.0);
if (U_FAILURE(icuStatus))
return false;
name = result;
}
*out = CFStringCreateWithCharacters(kCFAllocatorSystemDefault, (UniChar *)name, size);
return (*out != NULL);
}
示例11: GetVisualName
//-------------------------------------------------------------------------------------------------
// GetVisualName
//-------------------------------------------------------------------------------------------------
//
void GetVisualName( ITUniStr255 name )
{
CFIndex length = CFStringGetLength( kTVisualPluginName );
name[0] = (UniChar)length;
CFStringGetCharacters( kTVisualPluginName, CFRangeMake( 0, length ), &name[1] );
}
示例12: UpdateATSUIStuffString
// Sets up the text based on the specified CFString
//
void UpdateATSUIStuffString(CFStringRef string)
{
free(gText);
gLength = CFStringGetLength(string);
gText = (UniChar *)malloc(gLength * sizeof(UniChar));
CFStringGetCharacters(string, CFRangeMake(0, gLength), gText);
}
示例13: assertEqualsAsCharactersPtr
static void assertEqualsAsCharactersPtr(JSValueRef value, const char* expectedValue)
{
JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL);
size_t jsLength = JSStringGetLength(valueAsString);
const JSChar* jsBuffer = JSStringGetCharactersPtr(valueAsString);
CFStringRef expectedValueAsCFString = CFStringCreateWithCString(kCFAllocatorDefault,
expectedValue,
kCFStringEncodingUTF8);
CFIndex cfLength = CFStringGetLength(expectedValueAsCFString);
UniChar* cfBuffer = (UniChar*)malloc(cfLength * sizeof(UniChar));
CFStringGetCharacters(expectedValueAsCFString, CFRangeMake(0, cfLength), cfBuffer);
CFRelease(expectedValueAsCFString);
if (memcmp(jsBuffer, cfBuffer, cfLength * sizeof(UniChar)) != 0) {
fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsBuffer != cfBuffer\n");
failed = 1;
}
if (jsLength != (size_t)cfLength) {
fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
failed = 1;
}
free(cfBuffer);
JSStringRelease(valueAsString);
}
示例14: MoveFile
/********************************************************************
* MoveFile
* lpFromFileName: old file path
* lpToFileName: new file path
********************************************************************/
BOOL MoveFile(const char * lpFromFileName, const char * lpToFileName)
{
OSErr theErr;
FSRef fromFileRef;
FSRef toFileRef;
FSRef parentFolderRef;
// Get the path to the old file
theErr = FSPathMakeRef((const UInt8 *)lpFromFileName, &fromFileRef, NULL);
if (theErr != noErr)
{
SetLastError(theErr);
return false;
}
// Get the path to the new folder for the file
char folderName[strlen(lpToFileName)];
CFStringRef folderPathCFString = CFStringCreateWithCString(NULL, lpToFileName, kCFStringEncodingUTF8);
CFURLRef fileURL = CFURLCreateWithFileSystemPath(NULL, folderPathCFString, kCFURLPOSIXPathStyle, FALSE);
CFURLRef folderURL = CFURLCreateCopyDeletingLastPathComponent(NULL, fileURL);
CFURLGetFileSystemRepresentation(folderURL, TRUE, (UInt8 *)folderName, strlen(lpToFileName));
theErr = FSPathMakeRef((UInt8 *)folderName, &parentFolderRef, NULL);
CFRelease(fileURL);
CFRelease(folderURL);
CFRelease(folderPathCFString);
// Move the old file
theErr = FSMoveObject(&fromFileRef, &parentFolderRef, &toFileRef);
if (theErr != noErr)
{
SetLastError(theErr);
return false;
}
// Get a CFString for the new file name
CFStringRef newFileNameCFString = CFStringCreateWithCString(NULL, lpToFileName, kCFStringEncodingUTF8);
fileURL = CFURLCreateWithFileSystemPath(NULL, newFileNameCFString, kCFURLPOSIXPathStyle, FALSE);
CFRelease(newFileNameCFString);
newFileNameCFString = CFURLCopyLastPathComponent(fileURL);
CFRelease(fileURL);
// Convert CFString to Unicode and rename the file
UniChar unicodeFileName[256];
CFStringGetCharacters(newFileNameCFString, CFRangeMake(0, CFStringGetLength(newFileNameCFString)),
unicodeFileName);
theErr = FSRenameUnicode(&toFileRef, CFStringGetLength(newFileNameCFString), unicodeFileName,
kTextEncodingUnknown, NULL);
if (theErr != noErr)
{
SetLastError(theErr);
CFRelease(newFileNameCFString);
return false;
}
CFRelease(newFileNameCFString);
SetLastError(theErr);
return true;
}
示例15: q_toString
static QString q_toString(const CFStringRef &str)
{
CFIndex length = CFStringGetLength(str);
QVarLengthArray<UniChar> buffer(length);
CFRange range = { 0, length };
CFStringGetCharacters(str, range, buffer.data());
return QString(reinterpret_cast<const QChar *>(buffer.data()), length);
}