本文整理匯總了C++中CFStringGetMaximumSizeForEncoding函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFStringGetMaximumSizeForEncoding函數的具體用法?C++ CFStringGetMaximumSizeForEncoding怎麽用?C++ CFStringGetMaximumSizeForEncoding使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFStringGetMaximumSizeForEncoding函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: extension_array_applier
// This is the helper function to extract the strings from WebPluginExtensions
// in mimetype_dictionary_applier.
// value CFString containing a single file extension
// context char ** of the current extension list.
static void extension_array_applier(const void *value, void *context)
{
CFIndex ext_length;
char **extension_list;
extension_list = context;
ext_length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(value),
kCFStringEncodingUTF8);
*extension_list = realloc(*extension_list, strlen(*extension_list)
+ ext_length
+ 1
+ 1);
// If I'm not the first extension, append a comma delimiter.
if (strlen(*extension_list)) {
strcat(*extension_list, ",");
}
// Append this string to the list.
CFStringGetCString(value,
*extension_list + strlen(*extension_list),
ext_length + 1,
kCFStringEncodingUTF8);
return;
}
示例2: CFStringGetMaximumSizeOfFileSystemRepresentation
CFIndex
CFStringGetMaximumSizeOfFileSystemRepresentation (CFStringRef string)
{
CFIndex length = CFStringGetLength (string);
return
CFStringGetMaximumSizeForEncoding (length, CFStringGetSystemEncoding ());
}
示例3: ST_ID3v2_TextFrame_setTextStr
ST_FUNC ST_Error ST_ID3v2_TextFrame_setTextStr(ST_TextFrame *f, CFStringRef s) {
CFIndex slen;
CFIndex l;
uint8_t *buf;
void *tmp;
if(!f || !s)
return ST_Error_InvalidArgument;
/* Make space for it */
slen = CFStringGetLength(s);
l = CFStringGetMaximumSizeForEncoding(slen, encs[f->encoding]);
if(!(buf = (uint8_t *)malloc(l)))
return ST_Error_errno;
CFStringGetBytes(s, CFRangeMake(0, slen), encs[f->encoding], 0,
f->encoding == ST_TextEncoding_UTF16, buf, l, &slen);
/* Attempt to make it smaller */
if(slen != l) {
if((tmp = realloc(buf, slen)))
buf = (uint8_t *)tmp;
}
free(f->string);
f->size = slen;
f->string = buf;
return ST_Error_None;
}
示例4: plist_dict_next_item
/**
* Increment iterator of a #PLIST_DICT node.
*
* @param node the node of type #PLIST_DICT
* @param iter iterator of the dictionary
* @param key a location to store the key, or NULL.
* @param val a location to store the value, or NULL.
*/
void plist_dict_next_item(plist_t node, plist_dict_iter iter, char **key, plist_t *val)
{
assert(CFGetTypeID(node) == CFDictionaryGetTypeID());
struct {
CFIndex index;
CFIndex count;
const void * pairs[][2];
} * myiter;
myiter = iter;
if (myiter->index < myiter->count) {
if (key) {
CFStringRef keyRef = myiter->pairs[myiter->index][0];
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(CFStringGetLength(keyRef), kCFStringEncodingUTF8);
char *keyData = malloc(++maxSize);
CFStringGetCString(keyRef, keyData, maxSize, kCFStringEncodingUTF8);
*key = keyData;
}
if (val)
*val = myiter->pairs[myiter->index][1];
myiter->index += 1;
}
else {
if (key) *key = NULL;
if (val) *val = NULL;
}
}
示例5: SecPolicyCreateAppleSSLService
SecPolicyRef SecPolicyCreateAppleSSLService(CFStringRef hostname)
{
// SSL server, pinned to an Apple intermediate
SecPolicyRef policy = SecPolicyCreateSSL(true, hostname);
if (policy) {
// change options for policy evaluation
char *strbuf = NULL;
const char *hostnamestr = NULL;
if (hostname) {
hostnamestr = CFStringGetCStringPtr(hostname, kCFStringEncodingUTF8);
if (hostnamestr == NULL) {
CFIndex maxLen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(hostname), kCFStringEncodingUTF8) + 1;
strbuf = (char *)malloc(maxLen);
if (CFStringGetCString(hostname, strbuf, maxLen, kCFStringEncodingUTF8)) {
hostnamestr = strbuf;
}
}
}
uint32 hostnamelen = (hostnamestr) ? (uint32)strlen(hostnamestr) : 0;
uint32 flags = 0x00000002; // 2nd-lowest bit set to require Apple intermediate pin
CSSM_APPLE_TP_SSL_OPTIONS opts = {CSSM_APPLE_TP_SSL_OPTS_VERSION, hostnamelen, hostnamestr, flags};
CSSM_DATA data = {sizeof(opts), (uint8*)&opts};
SecPolicySetValue(policy, &data);
}
return policy;
}
示例6: WideCharToMultiByte
void ARRAY_TEXT::convertToUTF8(const CUTF16String* fromString, CUTF8String* toString)
{
#ifdef _WIN32
int len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, (LPCWSTR)fromString->c_str(), fromString->length(), NULL, 0, NULL, NULL);
if(len){
std::vector<uint8_t> buf(len + 1);
if(WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, (LPCWSTR)fromString->c_str(), fromString->length(), (LPSTR)&buf[0], len, NULL, NULL)){
*toString = CUTF8String((const uint8_t *)&buf[0]);
}
}
#else
CFStringRef str = CFStringCreateWithCharacters(kCFAllocatorDefault, (const UniChar *)fromString->c_str(), fromString->length());
if(str){
size_t size = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8) + sizeof(uint8_t);
std::vector<uint8_t> buf(size);
CFIndex len = 0;
CFStringGetBytes(str, CFRangeMake(0, CFStringGetLength(str)), kCFStringEncodingUTF8, 0, true, (UInt8 *)&buf[0], size, &len);
*toString = CUTF8String((const uint8_t *)&buf[0], len);
CFRelease(str);
}
#endif
}
示例7: _mongoc_cfstringref_to_cstring
char *
_mongoc_cfstringref_to_cstring (CFStringRef str)
{
CFIndex length;
CFStringEncoding encoding;
CFIndex max_size;
char *cs;
if (!str) {
return NULL;
}
if (CFGetTypeID (str) != CFStringGetTypeID ()) {
return NULL;
}
length = CFStringGetLength (str);
encoding = kCFStringEncodingASCII;
max_size = CFStringGetMaximumSizeForEncoding (length, encoding) + 1;
cs = bson_malloc ((size_t) max_size);
if (CFStringGetCString (str, cs, max_size, encoding)) {
return cs;
}
bson_free (cs);
return NULL;
}
示例8: GetAudioPropertyString
static OSStatus GetAudioPropertyString(AudioObjectID id,
AudioObjectPropertySelector selector,
char **outData)
{
OSStatus err;
AudioObjectPropertyAddress property_address;
UInt32 i_param_size;
CFStringRef string;
CFIndex string_length;
property_address.mSelector = selector;
property_address.mScope = kAudioObjectPropertyScopeGlobal;
property_address.mElement = kAudioObjectPropertyElementMaster;
i_param_size = sizeof(CFStringRef);
err = AudioObjectGetPropertyData(id, &property_address, 0, NULL, &i_param_size, &string);
if (err != noErr)
return err;
string_length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(string),
kCFStringEncodingASCII);
*outData = malloc(string_length + 1);
CFStringGetCString(string, *outData, string_length + 1, kCFStringEncodingASCII);
CFRelease(string);
return err;
}
示例9: FSRef2String
OSG_BEGIN_NAMESPACE
/********************** OS X **************************/
#ifdef __APPLE__
std::string FSRef2String(const FSRef& foundRef)
{
std::string Result("");
CFURLRef tURL;
tURL = CFURLCreateFromFSRef(kCFAllocatorDefault, &foundRef);
CFStringRef tCFString = CFURLCopyFileSystemPath(tURL,
kCFURLPOSIXPathStyle);
CFIndex buf_len = 1 + CFStringGetMaximumSizeForEncoding(CFStringGetLength(tCFString),
kCFStringEncodingUTF8);
char *buffer = new char[buf_len];
CFStringGetCString(tCFString, buffer, buf_len,
kCFStringEncodingUTF8);
Result = std::string(buffer);
delete[] buffer;
CFRelease(tCFString);
CFRelease(tURL);
return Result;
}
示例10: WebApiClientDataCreateWithHexEncodedString
CFDataRef WebApiClientDataCreateWithHexEncodedString(CFStringRef string) {
CFIndex len = CFStringGetLength(string);
CFMutableDataRef result = CFDataCreateMutable(kCFAllocatorDefault, len / 2);
bool allocated = false;
char *str = (char *)CFStringGetCStringPtr(string, kCFStringEncodingUTF8);
if ( str == NULL ) {
CFIndex bufferSize = CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8) + 1;
str = malloc(bufferSize);
if ( !str ) {
return result;
}
if ( !CFStringGetCString(string, str, bufferSize, kCFStringEncodingUTF8) ) {
free(str);
return result;
}
allocated = true;
}
CFIndex i;
unsigned char byte = 0;
size_t slen = strnlen(str, len);
slen -= (slen % 2); // if odd # of characters, truncate down
for ( i = 0; i < slen; i += 2 ) {
if ( sscanf(&str[i], "%2hhx", &byte) ) {
CFDataAppendBytes(result, &byte, 1);
} else {
break;
}
}
if ( allocated ) {
free(str);
}
return result;
}
示例11: APCopyDataFromHexString
/* http://stackoverflow.com/a/12535482 */
static CFDataRef APCopyDataFromHexString(CFStringRef string)
{
CFIndex length = CFStringGetLength(string);
CFIndex maxSize =CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
char *cString = (char *)malloc(maxSize);
CFStringGetCString(string, cString, maxSize, kCFStringEncodingUTF8);
/* allocate the buffer */
UInt8 * buffer = malloc((strlen(cString) / 2));
char *h = cString; /* this will walk through the hex string */
UInt8 *b = buffer; /* point inside the buffer */
/* offset into this string is the numeric value */
char translate[] = "0123456789abcdef";
for ( ; *h; h += 2, ++b) /* go by twos through the hex string */
*b = ((strchr(translate, *h) - translate) * 16) /* multiply leading digit by 16 */
+ ((strchr(translate, *(h+1)) - translate));
CFDataRef data = CFDataCreate(kCFAllocatorDefault, buffer, (strlen(cString) / 2));
free(cString);
free(buffer);
return data;
}
示例12: fopen
FILE* fopen (const char *filename, const char *mode) {
#ifdef HX_MACOS
FILE *result = ::fopen (filename, "rb");
if (!result) {
CFStringRef str = CFStringCreateWithCString (NULL, filename, kCFStringEncodingUTF8);
CFURLRef path = CFBundleCopyResourceURL (CFBundleGetMainBundle (), str, NULL, NULL);
CFRelease (str);
if (path) {
str = CFURLCopyPath (path);
CFIndex maxSize = CFStringGetMaximumSizeForEncoding (CFStringGetLength (str), kCFStringEncodingUTF8);
char *buffer = (char *)malloc (maxSize);
if (CFStringGetCString (str, buffer, maxSize, kCFStringEncodingUTF8)) {
result = ::fopen (buffer,"rb");
free (buffer);
}
CFRelease (str);
CFRelease (path);
}
}
return result;
#else
return ::fopen (filename, mode);
#endif
}
示例13: CFStringGetLength
char *create_cstr_from_cfstring(CFStringRef cfstring)
{
CFIndex str_len = CFStringGetLength(cfstring);
if (str_len < 0)
{
return NULL;
}
CFIndex buf_len = CFStringGetMaximumSizeForEncoding(str_len, kCFStringEncodingUTF8) + 1;
if (buf_len < 1)
{
return NULL;
}
char *cstr = (char *)malloc(buf_len);
if (cstr == NULL)
{
return NULL;
}
if (CFStringGetCString(cfstring, cstr, buf_len, kCFStringEncodingUTF8))
{
return cstr;
}
return NULL;
}
示例14: mdsDict
void MDSAttrParser::parseFile(CFURLRef infoUrl, CFStringRef subdir)
{
CFStringRef infoType = NULL;
/* Get contents of mdsinfo file as dictionary */
MDSDictionary mdsDict(infoUrl, subdir, mPath);
/* Make sure we set all possible MDS values before checking for GUID */
mdsDict.setDefaults(mDefaults);
if (mGuid == NULL) {
CFStringRef guid = (CFStringRef)mdsDict.lookup("ModuleID", true, CFStringGetTypeID());
if (guid) {
CFIndex copylen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(guid), kCFStringEncodingUTF8) + 1/*nul terminator*/;
mGuid = new char[copylen];
if (false == CFStringGetCString(guid, mGuid, copylen, kCFStringEncodingUTF8)) {
logFileError("Error copying GUID", infoUrl, NULL, NULL);
delete [] mGuid;
mGuid = NULL;
CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR);
}
}
else {
logFileError("No GUID associated with plugin?", infoUrl, NULL, NULL);
CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR);
}
}
MPDebug("Parsing mdsinfo file %s", mdsDict.fileDesc());
/* Determine what kind of info file this is and dispatch accordingly */
infoType = (CFStringRef)mdsDict.lookup(CFSTR(MDS_INFO_FILE_TYPE),
true, CFStringGetTypeID());
if(infoType == NULL) {
logFileError("Malformed MDS Info file", infoUrl, NULL, NULL);
CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR);
}
/* be robust here, errors in these low-level routines do not affect
* the rest of our task */
try {
if(CFStringCompare(infoType, CFSTR(MDS_INFO_FILE_TYPE_CSSM), 0)
== kCFCompareEqualTo) {
parseCssmInfo(&mdsDict);
}
else if(CFStringCompare(infoType, CFSTR(MDS_INFO_FILE_TYPE_PLUGIN), 0)
== kCFCompareEqualTo) {
parsePluginCommon(&mdsDict);
}
else if(CFStringCompare(infoType, CFSTR(MDS_INFO_FILE_TYPE_RECORD), 0)
== kCFCompareEqualTo) {
parsePluginSpecific(&mdsDict);
}
else {
logFileError("Malformed MDS Info file", infoUrl, NULL, NULL);
}
}
catch(...) {
}
}
示例15: vprintf_stderr_common
static void vprintf_stderr_common(const char* format, va_list args)
{
#if USE(CF) && !OS(WINDOWS)
if (strstr(format, "%@")) {
CFStringRef cfFormat = CFStringCreateWithCString(NULL, format, kCFStringEncodingUTF8);
#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
CFStringRef str = CFStringCreateWithFormatAndArguments(NULL, NULL, cfFormat, args);
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8);
char* buffer = (char*)malloc(length + 1);
CFStringGetCString(str, buffer, length, kCFStringEncodingUTF8);
logToStderr(buffer);
free(buffer);
CFRelease(str);
CFRelease(cfFormat);
return;
}
#if USE(APPLE_SYSTEM_LOG)
va_list copyOfArgs;
va_copy(copyOfArgs, args);
asl_vlog(0, 0, ASL_LEVEL_NOTICE, format, copyOfArgs);
va_end(copyOfArgs);
#endif
// Fall through to write to stderr in the same manner as other platforms.
#elif HAVE(ISDEBUGGERPRESENT)
if (IsDebuggerPresent()) {
size_t size = 1024;
do {
char* buffer = (char*)malloc(size);
if (buffer == NULL)
break;
if (vsnprintf(buffer, size, format, args) != -1) {
OutputDebugStringA(buffer);
free(buffer);
break;
}
free(buffer);
size *= 2;
} while (size > 1024);
}
#endif
vfprintf(stderr, format, args);
}