当前位置: 首页>>代码示例>>C++>>正文


C++ CFRangeMake函数代码示例

本文整理汇总了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;
}
开发者ID:hjzc,项目名称:SFBAudioEngine,代码行数:22,代码来源:Logger.cpp

示例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;
}
开发者ID:ljsebald,项目名称:SonatinaTag,代码行数:39,代码来源:APETag.c

示例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);
    }
}
开发者ID:Gamecharger,项目名称:Foundation,代码行数:22,代码来源:CFStringTransform.c

示例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);
}
开发者ID:fruitsamples,项目名称:audioburntest,代码行数:27,代码来源:dru_burning.c

示例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
开发者ID:2mc,项目名称:supercollider,代码行数:22,代码来源:HID_Utilities.c

示例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;
		}
	}
}
开发者ID:dansdrivers,项目名称:ndas4mac,代码行数:43,代码来源:NDASPreferences.c

示例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);
}
开发者ID:thangap,项目名称:tizen-release,代码行数:38,代码来源:sysman.c

示例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
开发者ID:specious,项目名称:osxutils,代码行数:38,代码来源:main.c

示例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;
}
开发者ID:kuolei,项目名称:CocoaSampleCode,代码行数:42,代码来源:main.c

示例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;
}
开发者ID:BruceJawn,项目名称:flashsnes,代码行数:38,代码来源:mac-file.cpp

示例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;
	}
}
开发者ID:BHCLL,项目名称:blendocv,代码行数:38,代码来源:GHOST_SystemCarbon.cpp

示例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	
}
开发者ID:xk,项目名称:4d-plugin-wizard-miyako-version,代码行数:23,代码来源:ARRAY_TEXT.cpp

示例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);
}
开发者ID:FilipBE,项目名称:qtextended,代码行数:23,代码来源:testapi.c

示例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;
}
开发者ID:StephaneH,项目名称:core-XToolbox,代码行数:23,代码来源:XMacStringCompare.cpp

示例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;
	
}
开发者ID:unofficial-opensource-apple,项目名称:Security,代码行数:37,代码来源:SecRecoveryPassword.c


注:本文中的CFRangeMake函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。