本文整理匯總了C++中CFStringCreateWithBytes函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFStringCreateWithBytes函數的具體用法?C++ CFStringCreateWithBytes怎麽用?C++ CFStringCreateWithBytes使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFStringCreateWithBytes函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: __create_message
void
__create_message (HWND hwnd,
SQLPOINTER dsn,
SQLPOINTER text,
SQLCHAR waMode,
AlertType id)
{
CFStringRef msg, msg1;
DialogRef dlg;
SInt16 out;
char buf[1024];
if (hwnd == NULL)
return;
if (waMode == 'A')
{
if (dsn)
{
STRCPY(buf, "DSN: ");
STRCAT(buf, dsn);
msg = CFStringCreateWithBytes (NULL, (unsigned char*)buf, STRLEN(buf),
kCFStringEncodingUTF8, false);
msg1 = CFStringCreateWithBytes (NULL, (unsigned char*)text, STRLEN(text),
kCFStringEncodingUTF8, false);
}
else
{
STRCPY(buf, "");
msg = CFStringCreateWithBytes (NULL, (unsigned char*)text, STRLEN(text),
kCFStringEncodingUTF8, false);
msg1 = CFStringCreateWithBytes (NULL, (unsigned char*)buf, STRLEN(buf),
kCFStringEncodingUTF8, false);
}
}
else
{
if (dsn)
{
WCSCPY(buf, L"DSN: ");
WCSCAT(buf, dsn);
msg = convert_wchar_to_CFString((wchar_t*)buf);
msg1 = convert_wchar_to_CFString((wchar_t*)text);
}
else
{
WCSCPY(buf, L"");
msg = convert_wchar_to_CFString((wchar_t*)text);
msg1 = convert_wchar_to_CFString((wchar_t*)buf);
}
}
CreateStandardAlert (id, msg, msg1, NULL, &dlg);
RunStandardAlert (dlg, NULL, &out);
CFRelease(msg);
CFRelease(msg1);
return;
}
示例2: rktio_strcoll_utf16
int rktio_strcoll_utf16(rktio_t *rktio,
rktio_char16_t *s1, intptr_t l1,
rktio_char16_t *s2, intptr_t l2,
rktio_bool_t cvt_case)
{
#ifdef MACOS_UNICODE_SUPPORT
CFStringRef str1, str2;
CFComparisonResult r;
str1 = CFStringCreateWithBytes(NULL, (unsigned char *)s1, (l1 * sizeof(rktio_char16_t)),
kCFStringEncodingUnicode, FALSE);
str2 = CFStringCreateWithBytes(NULL, (unsigned char *)s2, (l2 * sizeof(rktio_char16_t)),
kCFStringEncodingUnicode, FALSE);
r = CFStringCompare(str1, str2, (kCFCompareLocalized
| (cvt_case ? kCFCompareCaseInsensitive : 0)));
CFRelease(str1);
CFRelease(str2);
return (int)r;
#elif defined(RKTIO_SYSTEM_WINDOWS)
int r;
r = CompareStringW(LOCALE_USER_DEFAULT,
((cvt_case ? NORM_IGNORECASE : 0)
| NORM_IGNOREKANATYPE
| NORM_IGNOREWIDTH),
(wchar_t *)s1, l1, (wchar_t *)s2, l2);
return r - 2;
#else
return 0;
#endif
}
示例3: CFStringCreateWithBytes
void *quartz_new_layout(char* fontname, double fontsize, char* text)
{
CFStringRef fontnameref = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)fontname, strlen(fontname), kCFStringEncodingUTF8, FALSE);
CFStringRef textref = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)text, strlen(text), kCFStringEncodingUTF8, FALSE);
CTLineRef line = NULL;
if (fontnameref && textref) {
/* set up the Core Text line */
CTFontRef font = CTFontCreateWithName(fontnameref, fontsize, NULL);
CFDictionaryRef attributes = CFDictionaryCreate(
kCFAllocatorDefault,
(const void**)&kCTFontAttributeName,
(const void**)&font,
1,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFAttributedStringRef attributed = CFAttributedStringCreate(kCFAllocatorDefault, textref, attributes);
line = CTLineCreateWithAttributedString(attributed);
CFRelease(attributed);
CFRelease(attributes);
CFRelease(font);
}
if (textref)
CFRelease(textref);
if (fontnameref)
CFRelease(fontnameref);
return (void *)line;
}
示例4: do_msgbox
static int do_msgbox(const char *str, AlertType alert_type,
AlertStdCFStringAlertParamRec *param,
DialogItemIndex *idx, const char *desc)
{
const char *_title = desc ? desc : "Setup";
int retval = 0;
DialogItemIndex val = 0;
CFStringRef title = CFStringCreateWithBytes(NULL, BAD_CAST _title, strlen(_title),
kCFStringEncodingUTF8, 0);
CFStringRef msg = CFStringCreateWithBytes(NULL, BAD_CAST str, strlen(str),
kCFStringEncodingUTF8, 0);
if ((msg != NULL) && (title != NULL))
{
DialogRef dlg = NULL;
if (CreateStandardAlert(alert_type, title, msg, param, &dlg) == noErr)
{
RunStandardAlert(dlg, NULL, (idx) ? idx : &val);
retval = 1;
} /* if */
} /* if */
if (msg != NULL)
CFRelease(msg);
if (title != NULL)
CFRelease(title);
return(retval);
} /* do_msgbox */
示例5: create_error_Internal
void
create_error_Internal (HWND hwnd,
SQLPOINTER dsn,
SQLPOINTER text,
SQLPOINTER errmsg,
SQLCHAR waMode)
{
CFStringRef msg, msg1;
DialogRef dlg;
SInt16 out;
if (hwnd == NULL)
return;
if (waMode == 'A')
{
msg = CFStringCreateWithBytes (NULL, (unsigned char*)text, STRLEN(text),
kCFStringEncodingUTF8, false);
msg1 = CFStringCreateWithBytes (NULL, (unsigned char*)errmsg, STRLEN(errmsg),
kCFStringEncodingUTF8, false);
}
else
{
msg = convert_wchar_to_CFString((wchar_t*)text);
msg1 = convert_wchar_to_CFString((wchar_t*)errmsg);
}
CreateStandardAlert (kAlertStopAlert, msg, msg1, NULL, &dlg);
RunStandardAlert (dlg, NULL, &out);
CFRelease(msg);
CFRelease(msg1);
return;
}
示例6: frameTextStr
static CFStringRef frameTextStr(const ST_ID3v2 *tag, ST_ID3v2_FrameCode code,
ST_ID3v2_FrameCode code22, ST_Error *err) {
const ST_Frame *frame;
const ST_TextFrame *tframe;
const ST_CommentFrame *cframe;
ST_Error tmp, *e = err;
if(!err)
e = &tmp;
if(!tag || tag->base.type != ST_TagType_ID3v2) {
*e = ST_Error_InvalidArgument;
return NULL;
}
if(tag->majorver == 2) {
if(!(frame = ST_ID3v2_frameForKey(tag, code22, 0))) {
*e = ST_Error_NotFound;
return NULL;
}
}
else {
if(!(frame = ST_ID3v2_frameForKey(tag, code, 0))) {
*e = ST_Error_NotFound;
return NULL;
}
}
if(frame->type == ST_FrameType_Text) {
tframe = (const ST_TextFrame *)frame;
*e = ST_Error_None;
return CFStringCreateWithBytes(kCFAllocatorDefault, tframe->string,
tframe->size, encs[tframe->encoding],
tframe->encoding ==
ST_TextEncoding_UTF16);
}
else if(frame->type == ST_FrameType_Comment) {
cframe = (const ST_CommentFrame *)frame;
*e = ST_Error_None;
return CFStringCreateWithBytes(kCFAllocatorDefault, cframe->string,
cframe->string_size,
encs[cframe->encoding],
cframe->encoding ==
ST_TextEncoding_UTF16);
}
else {
*e = ST_Error_InvalidArgument;
return NULL;
}
}
示例7: QuartzBitmap_Output
void QuartzBitmap_Output(QuartzDesc_t dev, QuartzBitmapDevice *qbd)
{
if(qbd->path && qbd->uti) {
/* On 10.4+ we can employ the CGImageDestination API to create a
variety of different bitmap formats */
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
char buf[PATH_MAX+1];
snprintf(buf, PATH_MAX, qbd->path, qbd->page); buf[PATH_MAX] = '\0';
CFStringRef pathString = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8*) buf, strlen(buf), kCFStringEncodingUTF8, FALSE);
CFURLRef path;
if(CFStringFind(pathString, CFSTR("://"), 0).location != kCFNotFound) {
CFStringRef pathEscaped = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, pathString, NULL, NULL, kCFStringEncodingUTF8);
path = CFURLCreateWithString(kCFAllocatorDefault, pathEscaped, NULL);
CFRelease(pathEscaped);
} else {
path = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8*) buf, strlen(buf), FALSE);
}
CFRelease(pathString);
CFStringRef scheme = CFURLCopyScheme(path);
CFStringRef type = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8*) qbd->uti, strlen(qbd->uti), kCFStringEncodingUTF8, FALSE);
CGImageRef image = CGBitmapContextCreateImage(qbd->bitmap);
if(CFStringCompare(scheme,CFSTR("file"), 0) == 0) { /* file output */
CGImageDestinationRef dest = CGImageDestinationCreateWithURL(path, type, 1, NULL);
if(dest) {
CGImageDestinationAddImage(dest, image, NULL);
CGImageDestinationFinalize(dest);
CFRelease(dest);
} else
error(_("QuartzBitmap_Output - unable to open file '%s'"), buf);
} else if(CFStringCompare(scheme, CFSTR("clipboard"), 0) == 0) { /* clipboard output */
CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0);
CGImageDestinationRef dest = CGImageDestinationCreateWithData(data, type, 1, NULL);
CGImageDestinationAddImage(dest, image, NULL);
CGImageDestinationFinalize(dest);
CFRelease(dest);
PasteboardRef pb = NULL;
if(PasteboardCreate(kPasteboardClipboard, &pb) == noErr) {
PasteboardClear(pb);
PasteboardSynchronize(pb);
PasteboardPutItemFlavor(pb, (PasteboardItemID) 1, type, data, 0);
}
CFRelease(data);
} else
warning(_("not a supported scheme, no image data written"));
CFRelease(scheme);
CFRelease(type);
CFRelease(path);
CFRelease(image);
#endif
}
}
示例8: formatUnicodeString
char* formatUnicodeString(long* input, size_t size_of_one_char, int identifier)
{
if (!input)
return kNullInputError;
size_t length = 0;
CFStringEncoding encoding;
if (size_of_one_char == 2)
{
short* temp = (short*) input;
while (*temp++ && (length < max_length)) length++;
encoding = kCFStringEncodingUTF16LE;
}
else
{
long* temp = (long*) input;
while (*temp++ && (length < max_length)) length++;
encoding = kCFStringEncodingUTF32LE;
}
CFStringRef string = CFStringCreateWithBytes(NULL, (UInt8*) input, length * size_of_one_char, encoding, false);
char* result = ConvertStringToEncoding(string, kCFStringEncodingUTF8, identifier);
CFRelease(string);
return result;
}
示例9: convertChars
int convertChars(char *from, int fromLen, void *fromCode, char *to, int toLen, void *toCode, int norm, int term)
{
CFStringRef cfs= CFStringCreateWithBytes(NULL, (UInt8 *) from, fromLen, (CFStringEncoding)fromCode, 0);
if (cfs == NULL) {
toLen = 0;
to[toLen]= '\0';
return toLen;
}
CFMutableStringRef str= CFStringCreateMutableCopy(NULL, 0, cfs);
CFRelease(cfs);
if (norm) // HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements
CFStringNormalize(str, kCFStringNormalizationFormD); // canonical decomposition
else
CFStringNormalize(str, kCFStringNormalizationFormC); // pre-combined
{
CFRange rng= CFRangeMake(0, CFStringGetLength(str));
CFIndex len= 0;
CFIndex num= CFStringGetBytes(str, rng, (CFStringEncoding)toCode, '?', 0, (UInt8 *)to, toLen - term, &len);
CFRelease(str);
if (!num)
return convertCopy(from, fromLen, to, toLen, term);
if (term)
to[len]= '\0';
return len;
}
}
示例10: makeFSSpec
OSErr makeFSSpec(char *pathString, int pathStringLength,FSSpec *spec)
{
CFURLRef sillyThing;
CFStringRef tmpStrRef;
CFMutableStringRef filePath;
FSRef theFSRef;
OSErr err;
tmpStrRef = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *) pathString,
pathStringLength, gCurrentVMEncoding, true);
if (tmpStrRef == nil)
return -1000;
filePath = CFStringCreateMutableCopy(NULL, 0, tmpStrRef);
if (gCurrentVMEncoding == kCFStringEncodingUTF8)
CFStringNormalize(filePath, kCFStringNormalizationFormD);
sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false);
if (sillyThing == NULL)
return -2000;
if (CFURLGetFSRef(sillyThing,&theFSRef) == false) {
// name contains multiple aliases or does not exist, so fallback to lookupPath
CFRelease(filePath);
CFRelease(sillyThing);
return lookupPath(pathString,pathStringLength,spec,true,true);
}
CFRelease(filePath);
err = FSGetCatalogInfo (&theFSRef,kFSCatInfoNone,nil,nil,spec,nil);
CFRelease(sillyThing);
return err;
}
示例11: CharConvWW
// wchar_t to wchar_t conversion
void CharConvWW(charconv* Conv, wchar_t* Out, size_t OutLen, const wchar_t* In)
{
if (OutLen>0)
{
// assume wchar_t is 16 bits even if it's not true
charconv_osx *CC = (charconv_osx *)Conv;
if (CC)
{
CFStringRef TmpIn = CFStringCreateWithBytes(NULL, (const UInt8*)In, (utf16len((const uint16_t*)In)+1)*sizeof(uint16_t), CC->EncFrom, false);
assert(TmpIn);
CFIndex Read;
CFRange r;
r.location = 0;
r.length = CFStringGetLength(TmpIn);
CFStringGetBytes(TmpIn, r, CC->EncTo,
LOSSY_CHAR, /* no lossy conversion */
0, /* not external representation */
(UInt8*)Out, OutLen, &Read);
CFRelease(TmpIn);
memset((UInt8*)Out+Read,0,sizeof(uint16_t));
}
else
{
fprintf(stderr, "Not supported yet: %s with no CC\n", __FUNCTION__);
}
}
}
示例12: CFStringCreateWithBytes
static PyObject *AE_ConvertPathToURL(PyObject* self, PyObject* args)
{
char *cStr;
CFURLPathStyle style;
CFStringRef str;
CFURLRef url;
CFIndex len;
char buffer[PATH_MAX];
if (!PyArg_ParseTuple(args, "esl", "utf8", &cStr, &style))
return NULL;
str = CFStringCreateWithBytes(NULL,
(UInt8 *)cStr,
(CFIndex)strlen(cStr),
kCFStringEncodingUTF8,
false);
if (!str) return AE_MacOSError(1000);
url = CFURLCreateWithFileSystemPath(NULL,
str,
(CFURLPathStyle)style,
false);
PyMem_Free(cStr);
if (!url) return AE_MacOSError(1001);
len = CFURLGetBytes(url, (UInt8 *)buffer, PATH_MAX);
CFRelease(url);
return PyUnicode_DecodeUTF8(buffer, len, NULL);
}
示例13: SQLite3StatementCreateWithBundleResource
inline SQLite3StatementRef SQLite3StatementCreateWithBundleResource(SQLite3ConnectionRef connection, CFBundleRef bundle, CFStringRef type, CFStringRef name, CFStringRef subdir) {
SQLite3StatementRef statement = NULL;
if (connection) {
SInt32 errorCode = 0;
CFDictionaryRef properties = NULL;
CFDataRef data = NULL;
CFURLRef url = CFBundleCopyResourceURL(bundle, name, type, subdir);
if (url) {
if (CFURLCreateDataAndPropertiesFromResource(connection->allocator, url, &data, &properties, NULL, &errorCode)) {
CFStringRef sql = CFStringCreateWithBytes(connection->allocator, CFDataGetBytePtr(data), CFDataGetLength(data), kCFStringEncodingUTF8, 0);
if (sql) {
statement = SQLite3StatementCreate(connection, sql);
CFRelease(sql);
}
CFRelease(data);
if (properties)
CFRelease(properties);
} else {
// TODO: Error
}
CFRelease(url);
}
}
return statement;
}
示例14: copyConvertStringLiteralIntoUTF16
// Function to convert and copy string literals to the format expected by the exporter API.
// On Win: Pass the input directly to the output
// On Mac: All conversion happens through the CFString format
void copyConvertStringLiteralIntoUTF16(const wchar_t* inputString, prUTF16Char* destination)
{
#ifdef PRMAC_ENV
int length = wcslen(inputString);
CFRange range = {0, kPrMaxPath};
range.length = length;
CFStringRef inputStringCFSR = CFStringCreateWithBytes( kCFAllocatorDefault,
reinterpret_cast<const UInt8 *>(inputString),
length * sizeof(wchar_t),
kCFStringEncodingUTF32LE,
kPrFalse);
CFStringGetBytes( inputStringCFSR,
range,
kCFStringEncodingUTF16,
0,
kPrFalse,
reinterpret_cast<UInt8 *>(destination),
length * (sizeof (prUTF16Char)),
NULL);
destination[length] = 0; // Set NULL-terminator, since CFString calls don't set it, and MediaCore hosts expect it
CFRelease(inputStringCFSR);
#elif defined PRWIN_ENV
size_t length = wcslen(inputString);
wcscpy_s(destination, length + 1, inputString);
#endif
}
示例15: WBKeychainFindGenericPassword
OSStatus WBKeychainFindGenericPassword(CFTypeRef keychain, CFStringRef service, CFStringRef account, CFStringRef *password, SecKeychainItemRef *itemRef) {
OSStatus status;
if (password) *password = NULL;
char *serviceStr = (char *)__WBCFStringCopyUTF8Characters(service);
char *accountStr = (char *)__WBCFStringCopyUTF8Characters(account);
require_action_string(serviceStr != NULL && accountStr != NULL, bail, status = paramErr, "Unable to get service or account characters");
UInt32 length;
UTF8Char *passwordStr;
status = SecKeychainFindGenericPassword(keychain,
(UInt32)strlen(serviceStr), serviceStr,
(UInt32)strlen(accountStr), accountStr,
password ? &length : NULL,
password ? (void **)&passwordStr : NULL,
itemRef);
if ((noErr == status) && password) {
*password = CFStringCreateWithBytes(kCFAllocatorDefault, passwordStr, length, kCFStringEncodingUTF8, FALSE);
SecKeychainItemFreeContent(NULL, passwordStr);
}
bail:
if (serviceStr) free(serviceStr);
if (accountStr) free(accountStr);
return status;
}