本文整理匯總了C++中CFRangeMake函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFRangeMake函數的具體用法?C++ CFRangeMake怎麽用?C++ CFRangeMake使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFRangeMake函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: CFStringGetLength
std::ostream& operator<<(std::ostream& out, CFStringRef s)
{
if(NULL == s) {
out << "(null)";
return out;
}
char buf [BUFFER_LENGTH];
CFIndex totalCharacters = CFStringGetLength(s);
CFIndex currentCharacter = 0;
CFIndex charactersConverted = 0;
CFIndex bytesWritten;
while(currentCharacter < totalCharacters) {
charactersConverted = CFStringGetBytes(s, CFRangeMake(currentCharacter, totalCharacters), kCFStringEncodingUTF8, 0, false, reinterpret_cast<UInt8 *>(buf), BUFFER_LENGTH, &bytesWritten);
currentCharacter += charactersConverted;
out.write(buf, bytesWritten);
};
return out;
}
示例2: CFStringGetLength
static ST_APE_item *make_item_str(CFStringRef s, uint32_t flags) {
ST_APE_item *rv;
uint8_t *tmp, *stmp;
CFIndex len, slen, clen;
/* Setup and convert the string to UTF8 */
slen = CFStringGetLength(s);
len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(s),
kCFStringEncodingUTF8);
if(!(tmp = (uint8_t *)malloc(len)))
return NULL;
if(CFStringGetBytes(s, CFRangeMake(0, slen), kCFStringEncodingUTF8, 0,
false, (UInt8 *)tmp, len, &clen) != len) {
free(tmp);
errno = EILSEQ;
return NULL;
}
/* Trim the buffer down to the smallest it can be, since we allocated the
maximum length it could've been up above. */
if(!(stmp = (uint8_t *)realloc(tmp, clen))) {
free(tmp);
return NULL;
}
free(tmp);
/* Make the comment structure and return it! */
if((rv = (ST_APE_item *)malloc(sizeof(ST_APE_item)))) {
rv->data = stmp;
rv->length = clen;
rv->flags = flags;
return rv;
}
free(stmp);
return NULL;
}
示例3: _CFStringTransformCopy
static void _CFStringTransformCopy(UReplaceable *rep, int32_t start, int32_t limit, int32_t dest) {
CFMutableStringRef string = (CFMutableStringRef)rep;
UniChar stack_text[BUFFER_SIZE];
UniChar *text = &stack_text[0];
if (limit - start > BUFFER_SIZE) {
text = malloc(limit - start);
if (text == NULL) {
// we cant throw a NSException here, but return before anything blows up...
DEBUG_LOG("ICU Internal failure occurred, we are out of memory: time to go cry in a corner now...");
return;
}
}
CFStringGetCharacters(string, CFRangeMake(start, limit - start), text);
CFStringRef insert = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, text, limit - start, kCFAllocatorNull);
CFStringInsert(string, dest, insert);
CFRelease(insert);
if (text != &stack_text[0]) {
free(text);
}
}
示例4: druPrintFailureMessage
/*
druPrintFailureMessage
Prints out a localized burn failure message from the burn engine.
*/
void
druPrintFailureMessage(const char *task, CFDictionaryRef status)
{
CFDictionaryRef errorStatus = CFDictionaryGetValue(status,kDRErrorStatusKey);
UInt8 message[256];
CFIndex len = 0;
strncpy(message,"no error message available.",sizeof(message));
if (errorStatus != NULL)
{
CFStringRef errorString = CFDictionaryGetValue(errorStatus,kDRErrorStatusErrorStringKey);
if (errorString != NULL)
{
CFStringGetBytes(errorString, CFRangeMake(0,CFStringGetLength(errorString)), kCFStringEncodingASCII,
'.', false, (UInt8*)message, sizeof(message)-1, &len);
message[len] = 0;
}
}
printf("%s failed: %s\n", task, message);
}
示例5: HIDRebuildDevices
void HIDRebuildDevices( void ) {
// get the set of devices from the IOHID manager
CFSetRef devCFSetRef = IOHIDManagerCopyDevices( gIOHIDManagerRef );
if ( devCFSetRef ) {
// if the existing array isn't empty...
if ( gDeviceCFArrayRef ) {
// release it
CFRelease( gDeviceCFArrayRef );
}
// create an empty array
gDeviceCFArrayRef = CFArrayCreateMutable( kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks );
// now copy the set to the array
CFSetApplyFunction( devCFSetRef, CFSetApplierFunctionCopyToCFArray, ( void * ) gDeviceCFArrayRef );
// now sort the array by location ID's
CFIndex cnt = CFArrayGetCount( gDeviceCFArrayRef );
CFArraySortValues( gDeviceCFArrayRef, CFRangeMake( 0, cnt ), CFDeviceArrayComparatorFunction, NULL );
// and release the set we copied from the IOHID manager
CFRelease( devCFSetRef );
}
} // HIDRebuildDevices
示例6: NDASPreferencesGetIDorWriteKey
//
// Read ID or Write Key and Decrypt it.
//
// Return : NULL if not exist or decryped value.
//
CFStringRef NDASPreferencesGetIDorWriteKey( CFDictionaryRef dictEntry, CFStringRef keyString )
{
bool present;
CFStringRef strValue;
CFDataRef cfdEncrypedData;
UInt8 data[8];
present = CFDictionaryGetValueIfPresent(
dictEntry,
keyString,
(const void**)&cfdEncrypedData
);
if(!present || !cfdEncrypedData) {
return NULL;
} else {
if(CFDataGetTypeID() == CFGetTypeID(cfdEncrypedData)) {
CFDataGetBytes(cfdEncrypedData, CFRangeMake(0, 8), data);
Decrypt32(data, 8, (unsigned char*)&ENCRYPT_KEY, (unsigned char*)hostIDKey);
strValue = CFStringCreateWithBytes (
kCFAllocatorDefault,
data,
5,
CFStringGetSystemEncoding(),
false
);
return strValue;
} else {
return NULL;
}
}
}
示例7: sysEventConfigurationNotifier
static void
sysEventConfigurationNotifier(
SCDynamicStoreRef store, /* I - System data (unused) */
CFArrayRef changedKeys, /* I - Changed data */
void *context) /* I - Thread context data */
{
cupsd_thread_data_t *threadData; /* Thread context data */
threadData = (cupsd_thread_data_t *)context;
(void)store; /* anti-compiler-warning-code */
CFRange range = CFRangeMake(0, CFArrayGetCount(changedKeys));
if (CFArrayContainsValue(changedKeys, range, ComputerNameKey) ||
CFArrayContainsValue(changedKeys, range, BTMMKey))
threadData->sysevent.event |= SYSEVENT_NAMECHANGED;
else
{
threadData->sysevent.event |= SYSEVENT_NETCHANGED;
/*
* Indicate the network interface list needs updating...
*/
NetIFUpdate = 1;
}
/*
* Because we registered for several different kinds of change notifications
* this callback usually gets called several times in a row. We use a timer to
* de-bounce these so we only end up generating one event for the main thread.
*/
CFRunLoopTimerSetNextFireDate(threadData->timerRef,
CFAbsoluteTimeGetCurrent() + 5);
}
示例8: MoreAEOCreateObjSpecifierFromCFURLRef
pascal OSStatus MoreAEOCreateObjSpecifierFromCFURLRef(const CFURLRef pCFURLRef,AEDesc *pObjSpecifier)
{
OSErr anErr = paramErr;
if (nil != pCFURLRef)
{
Boolean isDirectory = CFURLHasDirectoryPath(pCFURLRef);
CFStringRef tCFStringRef = CFURLCopyFileSystemPath(pCFURLRef, kCFURLHFSPathStyle);
AEDesc containerDesc = {typeNull, NULL};
AEDesc nameDesc = {typeNull, NULL};
UniCharPtr buf = nil;
if (nil != tCFStringRef)
{
Size bufSize = (CFStringGetLength(tCFStringRef) + (isDirectory ? 1 : 0)) * sizeof(UniChar);
buf = (UniCharPtr) NewPtr(bufSize);
if ((anErr = MemError()) == noErr)
{
CFStringGetCharacters(tCFStringRef, CFRangeMake(0,bufSize/2), buf);
if (isDirectory) (buf)[(bufSize-1)/2] = (UniChar) 0x003A;
}
} else
anErr = coreFoundationUnknownErr;
if (anErr == noErr)
anErr = AECreateDesc(typeUnicodeText, buf, GetPtrSize((Ptr) buf), &nameDesc);
if (anErr == noErr)
anErr = CreateObjSpecifier(isDirectory ? cFolder : cFile,&containerDesc,formName,&nameDesc,false,pObjSpecifier);
MoreAEDisposeDesc(&nameDesc);
if (buf)
DisposePtr((Ptr)buf);
}
return anErr;
}//end MoreAEOCreateObjSpecifierFromCFURLRef
示例9: DisplayTagAndString
/*
* DisplayTagAndString displays the tag and then the str or "(not found)"
* if str is NULL.
*/
static void DisplayTagAndString(
CFStringRef tag, // input: the tag
CFStringRef str) // input: the CFString
{
CFStringRef displayStr;
UInt8 *buffer;
CFRange range;
CFIndex bytesToConvert;
CFIndex bytesConverted;
if ( str != NULL )
{
displayStr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("\t%@: \"%@\""), tag, str);
}
else
{
displayStr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("\t%@: (not found)"), tag);
}
require(displayStr != NULL, CFStringCreateWithFormat);
range = CFRangeMake(0, CFStringGetLength(displayStr));
CFStringGetBytes(displayStr, range, kCFStringEncodingUTF8, 0, false, NULL, 0, &bytesToConvert);
buffer = malloc(bytesToConvert + 1);
require(buffer != NULL, malloc_buffer);
CFStringGetBytes(displayStr, range, kCFStringEncodingUTF8, 0, false, buffer, bytesToConvert, &bytesConverted);
buffer[bytesConverted] = '\0';
fprintf(stdout, "%s\n", buffer);
free(buffer);
malloc_buffer:
CF_RELEASE_CLEAR(displayStr);
CFStringCreateWithFormat:
return;
}
示例10: FindSNESFolder
static OSErr 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, nil, folderRef, nil, nil);
if (err == noErr)
AddFolderIcon(folderRef, folderName);
}
if (err != noErr && !folderWarning)
{
AppearanceAlert(kAlertCautionAlert, kFolderFail, kFolderHint);
folderWarning = true;
}
else
err = FSRefMakePath(folderRef, (unsigned char *) folderPath, PATH_MAX);
CFRelease(purl);
CFRelease(burl);
CFRelease(fstr);
return err;
}
示例11: PasteboardCreate
GHOST_TUns8* GHOST_SystemCarbon::getClipboard(bool selection) const
{
PasteboardRef inPasteboard;
PasteboardItemID itemID;
CFDataRef flavorData;
OSStatus err = noErr;
GHOST_TUns8 * temp_buff;
CFRange range;
OSStatus syncFlags;
err = PasteboardCreate(kPasteboardClipboard, &inPasteboard);
if(err != noErr) { return NULL;}
syncFlags = PasteboardSynchronize( inPasteboard );
/* as we always get in a new string, we can safely ignore sync flags if not an error*/
if(syncFlags <0) { return NULL;}
err = PasteboardGetItemIdentifier( inPasteboard, 1, &itemID );
if(err != noErr) { return NULL;}
err = PasteboardCopyItemFlavorData( inPasteboard, itemID, CFSTR("public.utf8-plain-text"), &flavorData);
if(err != noErr) { return NULL;}
range = CFRangeMake(0, CFDataGetLength(flavorData));
temp_buff = (GHOST_TUns8*) malloc(range.length+1);
CFDataGetBytes(flavorData, range, (UInt8*)temp_buff);
temp_buff[range.length] = '\0';
if(temp_buff) {
return temp_buff;
} else {
return NULL;
}
}
示例12: MultiByteToWideChar
void ARRAY_TEXT::convertFromUTF8(const CUTF8String* fromString, CUTF16String* toString)
{
#ifdef _WIN32
int len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, (LPCSTR)fromString->c_str(), fromString->length(), NULL, 0);
if(len){
std::vector<uint8_t> buf((len + 1) * sizeof(PA_Unichar));
if(MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, (LPCSTR)fromString->c_str(), fromString->length(), (LPWSTR)&buf[0], len)){
*toString = CUTF16String((const PA_Unichar *)&buf[0]);
}
}
#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
}
示例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[cfLength];
CFStringGetCharacters(expectedValueAsCFString, CFRangeMake(0, cfLength), cfBuffer);
CFRelease(expectedValueAsCFString);
if (memcmp(jsBuffer, cfBuffer, cfLength * sizeof(UniChar)) != 0)
fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsBuffer != cfBuffer\n");
if (jsLength != (size_t)cfLength)
fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
JSStringRelease(valueAsString);
}
示例14: CFStringCompareWithOptionsAndLocale
CFComparisonResult XMacStringCompare::_CompareCFString( const UniChar *inText1, sLONG inSize1, const UniChar *inText2, sLONG inSize2, bool inWithDiacritics)
{
CFStringRef string1 = ::CFStringCreateWithCharactersNoCopy( kCFAllocatorDefault, inText1, inSize1, kCFAllocatorNull);
CFStringRef string2 = ::CFStringCreateWithCharactersNoCopy( kCFAllocatorDefault, inText2, inSize2, kCFAllocatorNull);
CFComparisonResult result = kCFCompareEqualTo;
if ( (string1 != NULL) && (string2 != NULL) )
{
CFStringCompareFlags flags = kCFCompareWidthInsensitive | kCFCompareLocalized;
if (!inWithDiacritics)
flags |= (kCFCompareDiacriticInsensitive | kCFCompareCaseInsensitive);
result = CFStringCompareWithOptionsAndLocale( string1, string2, CFRangeMake( 0, CFStringGetLength( string1)), flags, GetCFLocale());
}
if (string1 != NULL)
CFRelease( string1);
if (string2 != NULL)
CFRelease( string2);
return result;
}
示例15: SecCreateRecoveryPassword
CFStringRef
SecCreateRecoveryPassword(void)
{
CFStringRef result = NULL;
CFErrorRef error = NULL;
CFDataRef encodedData = NULL;
CFDataRef randData = getRandomBytes(16);
int i;
// base32FDE is a "private" base32 encoding, it has no 0/O or L/l/1 in it (it uses 8 and 9).
SecTransformRef encodeTrans = SecEncodeTransformCreate(CFSTR("base32FDE"), &error);
if(error == NULL) {
SecTransformSetAttribute(encodeTrans, kSecTransformInputAttributeName, randData, &error);
if(error == NULL) encodedData = SecTransformExecute(encodeTrans, &error);
CFRelease(encodeTrans);
}
CFRelease(randData);
if(encodedData != NULL && error == NULL) {
CFStringRef b32string = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, encodedData, kCFStringEncodingMacRoman);
CFMutableStringRef encodedString = CFStringCreateMutableCopy(kCFAllocatorDefault, 64, b32string);
// Add some hyphens to make the generated password easier to use
for(i = 4; i < 34; i += 5) CFStringInsert(encodedString, i, CFSTR("-"));
// Trim so the last section is 4 characters long
CFStringDelete(encodedString, CFRangeMake(29,CFStringGetLength(encodedString)-29));
result = CFStringCreateCopy(kCFAllocatorDefault, encodedString);
CFRelease(encodedString);
CFRelease(b32string);
CFRelease(encodedData);
} else {
secDebug(ASL_LEVEL_ERR, "Failed to base32 encode random data for recovery password\n", NULL);
}
return result;
}