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


C++ CFStringCreateExternalRepresentation函数代码示例

本文整理汇总了C++中CFStringCreateExternalRepresentation函数的典型用法代码示例。如果您正苦于以下问题:C++ CFStringCreateExternalRepresentation函数的具体用法?C++ CFStringCreateExternalRepresentation怎么用?C++ CFStringCreateExternalRepresentation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CFStringCreateExternalRepresentation函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: configWrite

/*
 * Writes a new configuration file with the contents of a CFArrayRef. Each
 * element of the array is a CFStringRef.
 */
void
configWrite(const char *path, CFArrayRef config)
{
	CFStringRef	str;
	CFDataRef	data;
	int		fd = -1;
	int		len;

	str  = CFStringCreateByCombiningStrings(NULL, config, CFSTR("\n"));
	data = CFStringCreateExternalRepresentation(NULL, str, kCFStringEncodingMacRoman, '.');
	CFRelease(str);

	fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644);
	if (fd < 0) {
		goto done;
	}

	len = CFDataGetLength(data);
	if (len) {
		(void)write(fd, CFDataGetBytePtr(data), len);
	}

    done:

	if (fd >= 0)
		close(fd);
	CFRelease(data);
	return;
}
开发者ID:unofficial-opensource-apple,项目名称:configd_plugins,代码行数:33,代码来源:cfManager.c

示例2: impExpImportDeleteExtension

/* do a [NSString stringByDeletingPathExtension] equivalent */
CFStringRef impExpImportDeleteExtension(
	CFStringRef			fileStr)
{
	CFDataRef fileStrData = CFStringCreateExternalRepresentation(NULL, fileStr,
		kCFStringEncodingUTF8, 0);
	if(fileStrData == NULL) {
		return NULL;
	}

	CFURLRef urlRef = CFURLCreateFromFileSystemRepresentation(NULL,
		CFDataGetBytePtr(fileStrData), CFDataGetLength(fileStrData), false);
	if(urlRef == NULL) {
		CFRelease(fileStrData);
		return NULL;
	}
	CFURLRef rtnUrl = CFURLCreateCopyDeletingPathExtension(NULL, urlRef);
	CFStringRef rtnStr = NULL;
	CFRelease(urlRef);
	if(rtnUrl) {
		rtnStr = CFURLGetString(rtnUrl);
		CFRetain(rtnStr);
		CFRelease(rtnUrl);
	}
	CFRelease(fileStrData);
	return rtnStr;
}
开发者ID:unofficial-opensource-apple,项目名称:Security,代码行数:27,代码来源:SecImportExportUtils.cpp

示例3: CFStringCreateExternalRepresentation

std::wstring MacUtils::CFStringRefToWString(CFStringRef aString)
{
    if (aString == NULL) {
        return L"";
    }
    
    if (!aString)
        return false;
    CFDataRef cfData = CFStringCreateExternalRepresentation(kCFAllocatorDefault,
                                                            aString, kCFStringEncodingUTF32, 0);
    CFRelease(aString);
    if (!cfData)
        return false;
    int out_byte_len = CFDataGetLength(cfData);
    out_byte_len -= sizeof(wchar_t); // don't count the 32 bit BOM char at start
    int out_len = out_byte_len / sizeof(wchar_t);
    wchar_t *tmp = new wchar_t[out_len + 1];
    // start after the BOM, hence sizeof(wchar_t)
    CFDataGetBytes(cfData, CFRangeMake(sizeof(wchar_t), out_byte_len),
                   (UInt8*)tmp);
    CFRelease(cfData);
    tmp[out_len] = 0;
    std::wstring result = tmp;
    delete[] tmp;
    
    return result;
}
开发者ID:cristiantm,项目名称:webcrypto-key-certificate-discovery-js,代码行数:27,代码来源:MacUtils.cpp

示例4: __JSONParseWithString

inline bool __JSONParseWithString(__JSONRef json, CFStringRef string, CFErrorRef *error) {
  bool success = 1;
  json->yajlParser = yajl_alloc(&json->yajlParserCallbacks, &json->yajlAllocFuncs, (void *)json);
  if (json->yajlParser) {
//  yajl_config(json->yajlParser, yajl_allow_comments, kJSONReadOptionAllowComments | options ? 1 : 0);
//  yajl_config(json->yajlParser, yajl_dont_validate_strings, kJSONReadOptionCheckUTF8 | options ? 1 : 0);
  
    CFDataRef data = CFStringCreateExternalRepresentation(json->allocator, string, kCFStringEncodingUTF8, 0);
    if (data) {
      if ((json->yajlParserStatus = yajl_parse(json->yajlParser, CFDataGetBytePtr(data), CFDataGetLength(data))) != yajl_status_ok) {
        if (error) {
          success = 0;
          
          unsigned char * str = yajl_get_error(json->yajlParser, 1, CFDataGetBytePtr(data), CFDataGetLength(data));
          fprintf(stderr, "%s", (const char *) str);
          yajl_free_error(json->yajlParser, str);
          
          *error = CFErrorCreateWithUserInfoKeysAndValues(json->allocator, CFSTR("com.github.mirek.CoreJSON"), (CFIndex)json->yajlParserStatus, (const void *) { kCFErrorDescriptionKey }, (const void *) { CFSTR("Test") }, 1);
        }
        // TODO: Error stuff
        //printf("ERROR: %s\n", yajl_get_error(json->yajlParser, 1, __JSONUTF8StringGetBuffer(utf8), __JSONUTF8StringGetMaximumSize(utf8)));
      }
    
      json->yajlParserStatus = yajl_complete_parse(json->yajlParser);
      CFRelease(data);
    } else {
开发者ID:childhood,项目名称:CoreJSON,代码行数:26,代码来源:CoreJSON.c

示例5: IPCCallback

static CFDataRef IPCCallback(__unused CFMessagePortRef port, SInt32 messageID, __unused CFDataRef data, __unused void *info)
{
	switch(messageID)
	{
		case ServerCommandGetIP:
		{
			if(publicIPState == IPStateInvalid)
			{
				SCNetworkReachabilityFlags flags;
				SCNetworkReachabilityGetFlags(reachability, &flags);

				ReachabilityCallback(reachability, flags, NULL);
			}

			if(publicIPData)
				return publicIPData;

			return CFStringCreateExternalRepresentation(kCFAllocatorDefault, CFSTR(""), kCFStringEncodingUTF8, 0);
		}
		case ServerCommandStop:
		{
			CFRunLoopStop(CFRunLoopGetMain());
			return NULL;
		}
		case ServerCommandReload:
		{
			FetchIPAddress();
			return NULL;
		}

		default:
			return NULL;
	}
}
开发者ID:JustSid,项目名称:extip,代码行数:34,代码来源:server.c

示例6: encryptString

static CFDataRef
encryptString(SecKeyRef wrapKey, CFDataRef iv, CFStringRef str)
{
	CFDataRef retval = NULL;
 	CFErrorRef error = NULL;
    CFDataRef inputString = CFStringCreateExternalRepresentation(kCFAllocatorDefault, str, kCFStringEncodingMacRoman, 0xff);

 	SecTransformRef encryptTrans = SecEncryptTransformCreate(wrapKey, &error);
    if(error == NULL) {
		SecTransformRef group = SecTransformCreateGroupTransform();
		
        SecTransformSetAttribute(encryptTrans, kSecEncryptionMode, kSecModeCBCKey, &error);
        if(error == NULL) SecTransformSetAttribute(encryptTrans, kSecPaddingKey, kSecPaddingPKCS7Key, &error);
        if(error == NULL) SecTransformSetAttribute(encryptTrans, kSecTransformInputAttributeName, inputString, &error);
        if(error == NULL) SecTransformSetAttribute(encryptTrans, kSecIVKey, iv, &error);
		SecTransformRef encodeTrans = SecEncodeTransformCreate(kSecBase64Encoding, &error);
		SecTransformConnectTransforms(encryptTrans, kSecTransformOutputAttributeName, encodeTrans, kSecTransformInputAttributeName, group, &error);
		CFRelease(encodeTrans);  
		CFRelease(encryptTrans);
		if(error == NULL) retval = SecTransformExecute(group, &error);
        if(error != NULL) secDebug(ASL_LEVEL_ERR, "Failed to encrypt recovery password\n", NULL);
        CFRelease(group);
    }
    return retval;
}
开发者ID:unofficial-opensource-apple,项目名称:Security,代码行数:25,代码来源:SecRecoveryPassword.c

示例7: main

int main (int argc, const char * argv[]) {
    
	if (argv[1] != NULL)
	{
		CFDataRef data;
		CFStringRef searchterm = CFStringCreateWithCString(NULL, argv[1],
														   kCFStringEncodingMacRoman);
		CFRange searchRange = CFRangeMake(0, CFStringGetLength(searchterm));
		CFStringRef dictResult = DCSCopyTextDefinition(NULL, searchterm, searchRange);
		CFRelease(searchterm);

		if (dictResult != NULL) {
			data = CFStringCreateExternalRepresentation(NULL, dictResult, CFStringGetSystemEncoding(), '?');
			CFRelease(dictResult);

		}
		if (data != NULL) {
			printf ("%.*s\n\n", (int)CFDataGetLength(data), CFDataGetBytePtr(data));
			CFRelease(data);
		}
		else {
			printf("Could not find word in Dictionary.app.\n");
		}

		return 0;
	}
	else {
		printf("Usage: dictlookup \"word\"\n");
		return 1;
	}

}
开发者ID:davidhaselb,项目名称:dictlookup,代码行数:32,代码来源:main.c

示例8: impExpAddStringAttr

/*
* Add a CFString to a crypto context handle.
*/
static CSSM_RETURN impExpAddStringAttr(
	CSSM_CC_HANDLE ccHand,
	CFStringRef str,
	CSSM_ATTRIBUTE_TYPE attrType)
{
	/* CFStrings are passed as external rep in UTF8 encoding by convention */
	CFDataRef outData;
	outData = CFStringCreateExternalRepresentation(NULL,
		str, kCFStringEncodingUTF8,	0);		// lossByte 0 ==> no loss allowed
	if(outData == NULL) {
		SecImpExpDbg("impExpAddStringAttr: bad string format");
		return errSecParam;
	}

	CSSM_DATA attrData;
	attrData.Data = (uint8 *)CFDataGetBytePtr(outData);
	attrData.Length = CFDataGetLength(outData);
	CSSM_RETURN crtn = impExpAddContextAttribute(ccHand, attrType, sizeof(CSSM_DATA),
		&attrData);
	CFRelease(outData);
	if(crtn) {
		SecImpExpDbg("impExpAddStringAttr: CSSM_UpdateContextAttributes error");
	}
	return crtn;
}
开发者ID:unofficial-opensource-apple,项目名称:Security,代码行数:28,代码来源:SecImportExportUtils.cpp

示例9: _SQLite3StatementCreate

inline SQLite3StatementRef _SQLite3StatementCreate(CFAllocatorRef allocator, SQLite3ConnectionRef connection, CFStringRef sql, CFErrorRef *error) {
  SQLite3StatementRef statement = NULL;
  if (connection && sql) {
    statement = CFAllocatorAllocate(allocator, sizeof(__SQLite3Statement), 0);
    if (statement) {
      statement->connection = SQLite3ConnectionRetain(connection);   // Let's retain connection
      statement->allocator = allocator ? CFRetain(allocator) : NULL; // ...and allocator if not null
      statement->retainCount = 1;
      statement->stmt = NULL;
      CFDataRef sqlData = CFStringCreateExternalRepresentation(statement->allocator, sql, kCFStringEncodingUTF8, 0);
      if (sqlData) {
        SQLite3Status status = sqlite3_prepare_v2(connection->db, (const char *)CFDataGetBytePtr(sqlData), -1, &statement->stmt, NULL);
        if (kSQLite3StatusOK != status) {
          if (error) {
            *error = CFErrorCreate(allocator, CFSTR("com.github.mirek.SQLite3"), status, NULL);
          }
          printf("ERROR: %s\n", sqlite3_errmsg(connection->db));
          statement = SQLite3StatementRelease(statement); // ...will be set to NULL
        }
        CFRelease(sqlData);
      }
    }
  }
  return statement;
}
开发者ID:neostoic,项目名称:CoreSQLite3,代码行数:25,代码来源:SQLite3Statement.c

示例10: iSCSIDaemonSetSharedSecret

/*! Sets or updates a shared secret.
 *  @param handle a handle to a daemon connection.
 *  @param authorization an authorization for the right kiSCSIAuthModifyRights.
 *  @param nodeIQN the node iSCSI qualified name.
 *  @param sharedSecret the secret to set.
 *  @return an error code indicating whether the operating was successful. */
errno_t iSCSIDaemonSetSharedSecret(iSCSIDaemonHandle handle,
                                   AuthorizationRef authorization,
                                   CFStringRef nodeIQN,
                                   CFStringRef sharedSecret)
{
    // Validate inputs
    if(handle < 0 || !authorization || !nodeIQN || !sharedSecret)
        return EINVAL;
    
    AuthorizationExternalForm authExtForm;
    AuthorizationMakeExternalForm(authorization,&authExtForm);
    
    CFDataRef authData = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
                                                     (UInt8*)&authExtForm.bytes,
                                                     kAuthorizationExternalFormLength,
                                                     kCFAllocatorDefault);
    
    CFDataRef nodeIQNData = CFStringCreateExternalRepresentation(kCFAllocatorDefault,nodeIQN,kCFStringEncodingASCII,0);
    CFDataRef sharedSecretData = CFStringCreateExternalRepresentation(kCFAllocatorDefault,sharedSecret,kCFStringEncodingASCII,0);
    
    iSCSIDMsgSetSharedSecretCmd cmd = iSCSIDMsgSetSharedSecretCmdInit;
    cmd.authorizationLength = (UInt32)CFDataGetLength(authData);
    cmd.nodeIQNLength = (UInt32)CFDataGetLength(nodeIQNData);
    cmd.secretLength = (UInt32)CFDataGetLength(sharedSecretData);
    
    errno_t error = iSCSIDaemonSendMsg(handle,(iSCSIDMsgGeneric *)&cmd,
                                       authData,nodeIQNData,sharedSecretData,NULL);
    
    if(nodeIQNData)
        CFRelease(nodeIQNData);
    
    if(sharedSecretData)
        CFRelease(sharedSecretData);

    if(error)
        return error;
    
    iSCSIDMsgSetSharedSecretRsp rsp;
    
    if(recv(handle,&rsp,sizeof(rsp),0) != sizeof(rsp))
        return EIO;
    
    if(rsp.funcCode != kiSCSIDSetSharedSecret)
        return EIO;

    return rsp.errorCode;
}
开发者ID:jeditekunum,项目名称:iSCSIInitiator,代码行数:53,代码来源:iSCSIDaemonInterface.c

示例11: stringGettingContentsAsCStringExample

void stringGettingContentsAsCStringExample(void) {

    CFStringRef str;
    CFDataRef data;
    CFRange rangeToProcess;
    const char *bytes;

    show(CFSTR("------------------C String Manipulations---------------"));

    // Create some test CFString
    // Note that in general the string might contain Unicode characters which cannot
    // be converted to a 8-bit character encoding
    str = CFStringCreateWithCString(NULL, "Hello World", kCFStringEncodingASCII);

    show(CFSTR("Original String : %@"), str);
   
    // First, the fast but unpredictable way to get at the C String contents...
    // This is O(1), meaning it takes constant time.
    // This might return NULL!
    bytes = CFStringGetCStringPtr(str, kCFStringEncodingASCII);
   
    // If that fails, you can try to get the contents by copying it out
    if (bytes == NULL) {
        char localBuffer[10];
        Boolean success;

        // This might also fail, either if you provide a buffer that is too small, 
        // or the string cannot be converted into the specified encoding
        success = CFStringGetCString(str, localBuffer, 10, kCFStringEncodingASCII);
    }
    else
        show(CFSTR("From CStringPtr : %@"), bytes);   
    
    // A pretty simple solution is to use a CFData; this frees you from guessing at the buffer size
    // But it does allocate a CFData...
    data = CFStringCreateExternalRepresentation(NULL, str, kCFStringEncodingASCII, 0);
    if (data) {
        show(CFSTR("External Rep: %@"), data);   
        bytes = (const char *)CFDataGetBytePtr(data);
    }

    // More complicated but efficient solution is to use a fixed size buffer, and put a loop in
    rangeToProcess = CFRangeMake(0, CFStringGetLength(str));

    while (rangeToProcess.length > 0) {
        UInt8 localBuffer[100];
        CFIndex usedBufferLength;
        CFIndex numChars = CFStringGetBytes(str, rangeToProcess, kCFStringEncodingASCII, 0, FALSE, (UInt8 *)localBuffer, 100, &usedBufferLength);

        if (numChars == 0) break;	// Means we failed to convert anything...

        // Otherwise we converted some stuff; process localBuffer containing usedBufferLength bytes
        // Note that the bytes in localBuffer are not NULL terminated
		
        // Update the remaining range to continue looping
        rangeToProcess.location += numChars;
        rangeToProcess.length -= numChars;
    }
}
开发者ID:edconnor,项目名称:TestCairo,代码行数:59,代码来源:testCairo.cpp

示例12: TLProjectionGeoidCreateDataRepresentation

CFDataRef TLProjectionGeoidCreateDataRepresentation(TLProjectionGeoidRef projGeoid) {
	CFStringRef ellipseValue = TLProjectionGeoidCreateEllipseValue(projGeoid);
	CFStringRef geoidArgs = TLProjectionParametersCreateStringWithKeyAndValue(TLProjectionParametersEllipseNameKey, ellipseValue);
	CFRelease(ellipseValue);
	CFDataRef geoidAsData = CFStringCreateExternalRepresentation(kCFAllocatorDefault, geoidArgs, kCFStringEncodingASCII, 0);
	CFRelease(geoidArgs);
	return geoidAsData;
}
开发者ID:Web5design,项目名称:Geotagalog,代码行数:8,代码来源:TLProjectionGeoid.c

示例13: write_gdb_prep_cmds

void write_gdb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) {
    CFMutableStringRef cmds = CFStringCreateMutableCopy(NULL, 0, GDB_PREP_CMDS);
    CFRange range = { 0, CFStringGetLength(cmds) };

    CFStringRef ds_path = copy_device_support_path(device);
    CFStringFindAndReplace(cmds, CFSTR("{ds_path}"), ds_path, range, 0);
    range.length = CFStringGetLength(cmds);

    if (args) {
        CFStringRef cf_args = CFStringCreateWithCString(NULL, args, kCFStringEncodingASCII);
        CFStringFindAndReplace(cmds, CFSTR("{args}"), cf_args, range, 0);
        CFRelease(cf_args);
    } else {
        CFStringFindAndReplace(cmds, CFSTR(" {args}"), CFSTR(""), range, 0);
    }
    range.length = CFStringGetLength(cmds);

    CFStringRef bundle_identifier = copy_disk_app_identifier(disk_app_url);
    CFURLRef device_app_url = copy_device_app_url(device, bundle_identifier);
    CFStringRef device_app_path = CFURLCopyFileSystemPath(device_app_url, kCFURLPOSIXPathStyle);
    CFStringFindAndReplace(cmds, CFSTR("{device_app}"), device_app_path, range, 0);
    range.length = CFStringGetLength(cmds);

    CFStringRef disk_app_path = CFURLCopyFileSystemPath(disk_app_url, kCFURLPOSIXPathStyle);
    CFStringFindAndReplace(cmds, CFSTR("{disk_app}"), disk_app_path, range, 0);
    range.length = CFStringGetLength(cmds);

    CFURLRef device_container_url = CFURLCreateCopyDeletingLastPathComponent(NULL, device_app_url);
    CFStringRef device_container_path = CFURLCopyFileSystemPath(device_container_url, kCFURLPOSIXPathStyle);
    CFMutableStringRef dcp_noprivate = CFStringCreateMutableCopy(NULL, 0, device_container_path);
    range.length = CFStringGetLength(dcp_noprivate);
    CFStringFindAndReplace(dcp_noprivate, CFSTR("/private/var/"), CFSTR("/var/"), range, 0);
    range.length = CFStringGetLength(cmds);
    CFStringFindAndReplace(cmds, CFSTR("{device_container}"), dcp_noprivate, range, 0);
    range.length = CFStringGetLength(cmds);

    CFURLRef disk_container_url = CFURLCreateCopyDeletingLastPathComponent(NULL, disk_app_url);
    CFStringRef disk_container_path = CFURLCopyFileSystemPath(disk_container_url, kCFURLPOSIXPathStyle);
    CFStringFindAndReplace(cmds, CFSTR("{disk_container}"), disk_container_path, range, 0);

    CFDataRef cmds_data = CFStringCreateExternalRepresentation(NULL, cmds, kCFStringEncodingASCII, 0);
    FILE *out = fopen(PREP_CMDS_PATH, "w");
    fwrite(CFDataGetBytePtr(cmds_data), CFDataGetLength(cmds_data), 1, out);
    fclose(out);

    CFRelease(cmds);
    if (ds_path != NULL) CFRelease(ds_path);
    CFRelease(bundle_identifier);
    CFRelease(device_app_url);
    CFRelease(device_app_path);
    CFRelease(disk_app_path);
    CFRelease(device_container_url);
    CFRelease(device_container_path);
    CFRelease(dcp_noprivate);
    CFRelease(disk_container_url);
    CFRelease(disk_container_path);
    CFRelease(cmds_data);
}
开发者ID:ccastleb,项目名称:fruitstrap,代码行数:58,代码来源:fruitstrap.c

示例14: __copy_legacy_password

static CFDataRef
__copy_legacy_password(CFTypeRef password)
{
	if (password == NULL) {
		return NULL;
	}

	if (isA_CFData(password)) {
		CFIndex	n;

		n = CFDataGetLength(password);
		if ((n % sizeof(UniChar)) == 0) {
			CFStringEncoding	encoding;
			CFStringRef		str;

#if	__BIG_ENDIAN__
			encoding = (*(CFDataGetBytePtr(password) + 1) == 0x00) ? kCFStringEncodingUTF16LE : kCFStringEncodingUTF16BE;
#else	// __LITTLE_ENDIAN__
			encoding = (*(CFDataGetBytePtr(password)    ) == 0x00) ? kCFStringEncodingUTF16BE : kCFStringEncodingUTF16LE;
#endif
			str = CFStringCreateWithBytes(NULL,
						      (const UInt8 *)CFDataGetBytePtr(password),
						      n,
						      encoding,
						      FALSE);
			password = CFStringCreateExternalRepresentation(NULL,
									str,
									kCFStringEncodingUTF8,
									0);
			CFRelease(str);
		} else {
			password = NULL;
		}
	} else if (isA_CFString(password) && (CFStringGetLength(password) > 0)) {
		// convert password to CFData
		password = CFStringCreateExternalRepresentation(NULL,
								password,
								kCFStringEncodingUTF8,
								0);
	} else {
		password = NULL;
	}

	return password;
}
开发者ID:010001111,项目名称:darling,代码行数:45,代码来源:SCNetworkConfigurationInternal.c

示例15: TSICTStringCreateWithStringAndFormat

TStringIRep* TSICTStringCreateWithStringAndFormat(CFStringRef string, TSITStringFormat format)
{
    CFRetain(string);
    CFDataRef data = CFStringCreateExternalRepresentation(kCFAllocatorDefault, string, kCFStringEncodingUTF8, '?');
    TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(data, kTSITStringTagString, format);
    CFRelease(data);
    CFRelease(string);
    return rep;
}
开发者ID:4justinstewart,项目名称:Polity,代码行数:9,代码来源:TSICTString.c


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