Exemplo n.º 1
0
void main () {
    CFStringRef names[kNumFamilyMembers];
    CFArrayRef  array;
    CFDataRef   xmlData;
    CFRange range = {0, kNumFamilyMembers};
    char name[100];
    const void *ret_val = NULL;
    // Define the family members.
    names[0] = CFSTR("Marge");
    names[1] = CFSTR("Homer");
    names[2] = CFSTR("Bart");
    names[3] = CFSTR("Lisa");
    names[4] = CFSTR("Maggie");
    // Create a property list using the string array of names.
    array = CFArrayCreate( kCFAllocatorDefault,
                (const void **)names,
                kNumFamilyMembers,
                &kCFTypeArrayCallBacks );
    printf("Array size = %d\n", CFArrayGetCount(array));
    printf("Array has %s %d times\n", "Marge", CFArrayGetCountOfValue(array, range, CFSTR("Marge")));

    printf("\nCFShow:\n");
    CFShow((CFTypeRef)CFArrayGetValueAtIndex(array, 3));
    printf("\n\nCFShowStr:");
    CFShowStr(CFArrayGetValueAtIndex(array, 3));
    printf("\n");

    ret_val = CFArrayGetValueAtIndex(array, 3);
    CFStringGetCString(ret_val, name, sizeof(name), 0);
    printf("Value at index %d is 0x%x %s\n", 3, ret_val, name);
    // Convert the plist into XML data.
    xmlData = CFPropertyListCreateXMLData( kCFAllocatorDefault, array );
    // Clean up CF types.
    CFRelease( array );
    CFRelease( xmlData );
}
Exemplo n.º 2
0
/////////////////////////////////////////////////////////////////////////////
//
//	Method:
//
//		GetReasonableLocalFileName()
//
//	Purpose:
//
//		Converts some file URLs to reasonable file names.
//
//	Parameters:
//
//		CHXString& fileName
//		File reference or URL to convert to reasonable local file name.
//
//	Return:
//
//		None.
//
void HXXFile::GetReasonableLocalFileName(CHXString& fileName)
{
#if defined(_MAC_UNIX) || defined(_CARBON)
#ifdef _DEBUG
	CHXString debugSaveURL = (const char*) fileName;
#endif
	
	(void) PathFromURL(fileName, fileName);

#ifdef _DEBUG
	if (!CHXFileSpecUtils::FileExists(fileName))
	{
		CHXString msg;
		msg.Format("GetReasonableLocalFileName is returning invalid path '%s' given URL '%s'",
			 (const char*) fileName, (const char*) debugSaveURL);
		CFStringRef ref = CFStringCreateWithCString(nil, (const char*)msg, kCFStringEncodingUTF8);
		if (ref)
		{
			CFShowStr(ref);
			CFRelease(ref);
		}
	}
#endif // _DEBUG
	return;
	
#endif
	// Trim off any leading and trailing spaces... 
	// Oooh... those pesky QA folks!
	fileName.TrimLeft();
	fileName.TrimRight();

	char szProtocol[6]; /* Flawfinder: ignore */
	strncpy(szProtocol,(const char*)fileName,5); /* Flawfinder: ignore */
	szProtocol[5] = '\0';
	strlwr(szProtocol);
	
	if (strncasecmp(szProtocol,"file:",5) == 0)
	{
		fileName = fileName.Mid(5);

		// Get this, sometimes, Netscape actually puts three whacks!
		// now that's whacky. <g>
		// That's because the third one is the leading slash on
		// an absolute path, don't strip the damn thing off!
#if !defined(_UNIX) && !defined(_OPENWAVE)
		// This first case looks for 4 whacks meaning it is a UNC path on Windows should fail on Mac and UNIX
		if (fileName.Left(4) == "////")
		{
			fileName = fileName.Mid(2);
		}
		// This case occurs if the drive letter is present such as file:///G|/windows/test.rm
		else if (fileName.Left(3) == "///")
		{
			fileName = fileName.Mid(3);
		}
		// trim off those damn double whacks as well
		else 
#endif
		    if (fileName.Left(2) == "//")
		{
			fileName = fileName.Mid(2);
		}
	}


	//////////////////////////////////////////////////////
	// Replace all directory markers with correct platform
	// specific directory markers!
	//
#if defined (_MACINTOSH) || defined (_WINDOWS)
	int nFoundAt = 0;
	do
	{
		nFoundAt = fileName.Find('/');
		if (nFoundAt != -1)
		{
#ifdef _MACINTOSH
			fileName.SetAt(nFoundAt,':');
#else
			fileName.SetAt(nFoundAt,'\\');
#endif
		}

	}
	while(nFoundAt != -1);
#endif

#if defined (_UNIX)
	int nFoundAt = 0;
	do
	{
		nFoundAt = fileName.Find('\\');
		if (nFoundAt != -1)
		{
			fileName.SetAt(nFoundAt,'/');
		}

	}
	while(nFoundAt != -1);
#endif
}