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


C++ CFStringGetBytes函数代码示例

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


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

示例1: ConvertStringToEncoding

char* ConvertStringToEncoding(CFStringRef string, CFStringEncoding encoding, int identifier)
{
	char* output = NULL;
    if (_pbxgdb_plugin_functions)
	{
		// we want to convert the whole string
		CFRange range;
		range.location = 0;
		range.length = CFStringGetLength(string);
		
		// find out how big our utf-8 buffer needs to be
		CFIndex length_needed;
		CFStringGetBytes(string, range, encoding, '?', false, NULL, 0, &length_needed);
		
		// make the output buffer
		// just in case the convert call fails completely, we zero terminate it
        output = (char*)(_pbxgdb_plugin_functions->allocate(identifier, length_needed + 1));
		if (output)
		{
			output[0] = 0; 
			
			// try to get the actual string - we terminate it for safety
			CFStringGetBytes(string, range, encoding, '?', false, (UInt8*) output, length_needed, &length_needed);
			output[length_needed] = 0;
		}
    }
    
	if (output) DEBUG_PRINT("converted: %s\n", output);
		
	
	return output ? output : kNullPluginError;    
}
开发者ID:samdeane,项目名称:xcode-unicode-formatter,代码行数:32,代码来源:unicode_formatter.c

示例2: _SC_cfstring_to_cstring

char *
_SC_cfstring_to_cstring(CFStringRef cfstr, char *buf, CFIndex bufLen, CFStringEncoding encoding)
{
	CFIndex	converted;
	CFIndex	last	= 0;
	CFIndex	len;

	if (cfstr == NULL) {
		cfstr = CFSTR("");
	}
	len = CFStringGetLength(cfstr);

	/* how much buffer space will we really need? */
	converted = CFStringGetBytes(cfstr,
				     CFRangeMake(0, len),
				     encoding,
				     0,
				     FALSE,
				     NULL,
				     0,
				     &last);
	if (converted < len) {
		/* if full string could not be converted */
		if (buf != NULL) {
			buf[0] = '\0';
		}
		return NULL;
	}

	if (buf != NULL) {
		if (bufLen < (last + 1)) {
			/* if the size of the provided buffer is too small */
			buf[0] = '\0';
			return NULL;
		}
	} else {
		/* allocate a buffer */
		bufLen = last + 1;
		buf = CFAllocatorAllocate(NULL, bufLen, 0);
		if (buf == NULL) {
			return NULL;
		}
	}

	(void)CFStringGetBytes(cfstr,
			       CFRangeMake(0, len),
			       encoding,
			       0,
			       FALSE,
			       (UInt8 *)buf,
			       bufLen,
			       &last);
	buf[last] = '\0';

	return buf;
}
开发者ID:010001111,项目名称:darling,代码行数:56,代码来源:SCDPrivate.c

示例3: CFStringCreateWithCharactersNoCopy

const char *Tcl_UniCharToUtfDString(Tcl_UniChar *characters, size_t length, Tcl_DString *ds)
{
    CFStringRef str = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault,characters, length, kCFAllocatorNull);
    CFRange range = {0,length}; // all the characters
    CFIndex bufLen = 0;
    CFStringGetBytes(str, range, kCFStringEncodingUTF8, true, false, NULL, 0, &bufLen);
    *ds = (malloc(bufLen));
    CFStringGetBytes(str, range, kCFStringEncodingUTF8, true, false, *ds, bufLen, &bufLen);
    CFRelease(str);
    return (const char *)*ds;
}
开发者ID:CodaFi,项目名称:IDEKit,代码行数:11,代码来源:FakeTCLBridge.c

示例4: CFQStringCopyCString

extern pascal OSStatus CFQStringCopyCString(CFStringRef str, CFStringEncoding encoding, char **cStrPtr)
	// See comment in header.
{
	OSStatus		err;
	CFIndex			cStrLen;
	CFRange 		range;
	
	assert( str     != NULL);
	assert( cStrPtr != NULL);
	assert(*cStrPtr == NULL);

	err = noErr;
	
	range = CFRangeMake(0, CFStringGetLength(str));
		
	(void) CFStringGetBytes(str, range, encoding, 0, false, NULL, 0, &cStrLen);

	// Can't convert to CFQAllocate because the caller is required 
	// to free the string using "free", and there's no guarantee that 
	// CFQAllocate and "free" are compatible (for example, if you're 
	// compiling CFM and running on Mac OS X, "free" is from an MSL pool 
	// while CFQAllocate allocates from System framework).
	// 
	// Anyway, this isn't a problem because the size is always at 
	// least one byte, so malloc won't misbehave.
	
	*cStrPtr = (char *) malloc( ((size_t) cStrLen) + 1);
	if (*cStrPtr == NULL) {
		err = memFullErr;
	}

	if (err == noErr) {
		#if MORE_DEBUG
			(*cStrPtr)[cStrLen] = '¥';
		#endif
		
		if ( CFStringGetBytes(str, range, encoding, 0, false, (UInt8 *) *cStrPtr, cStrLen, &cStrLen) != range.length ) {
			err = kCFQDataErr;
		}
	}
	if (err == noErr) {		
		assert((*cStrPtr)[cStrLen] == '¥');
		(*cStrPtr)[cStrLen] = 0;
	} else {
		free(*cStrPtr);
		*cStrPtr = NULL;
	}

	assert( (err == noErr) == (*cStrPtr != NULL) );

	return err;
}
开发者ID:paullalonde,项目名称:B,代码行数:52,代码来源:MoreCFQ.c

示例5: CFRangeMake

std::string
Path::toUTF8() const {
#ifdef OSX
    CFRange myRange = CFRangeMake(0, CFStringGetLength(_myString));
    CFIndex myBufferSize = 0;
    std::string myResult;
    CFIndex myCharCount = CFStringGetBytes(_myString, myRange, kCFStringEncodingUTF8, '?', FALSE, 0, 0, &myBufferSize);
    if (myCharCount) {
        myResult.resize(myBufferSize);
        CFIndex myExCharCount = CFStringGetBytes(_myString, myRange, kCFStringEncodingUTF8, '?',
                                                    FALSE, (UInt8*)&(*(myResult.begin())), myBufferSize, &myBufferSize);
        ASSURE_WITH(AssurePolicy::Throw, myExCharCount == myCharCount);
    }
    return myResult;
#elif _WIN32
    if (_myLocaleChars == 0) {
        return std::string();
    }
    // convert from active codepage to WideChars
    AC_SIZE_TYPE myWCharSize = MultiByteToWideChar(CP_ACP, getMultibyteToWideCharFlags(), _myLocaleChars, -1, 0, 0);
    if (myWCharSize == 0) {
        throw UnicodeException(errorDescription(lastError()), PLUS_FILE_LINE);
    }
    LPWSTR myWChars = new WCHAR[myWCharSize];
    MultiByteToWideChar(CP_ACP, getMultibyteToWideCharFlags(), _myLocaleChars, -1, myWChars, myWCharSize);

    // convert from WideChars to UTF8
    AC_SIZE_TYPE myUTF8Size = WideCharToMultiByte(CP_UTF8, 0, myWChars, -1, 0, 0, 0, 0);
    if (myUTF8Size == 0) {
        throw UnicodeException(errorDescription(lastError()), PLUS_FILE_LINE);
    }
    char * myUTF8Chars = new char[myUTF8Size];
    WideCharToMultiByte(CP_UTF8, 0, myWChars, -1, myUTF8Chars, myUTF8Size, 0, 0);

    std::string myUTF8String(myUTF8Chars);
    delete [] myWChars;
    delete [] myUTF8Chars;
    return myUTF8String;
#else
    if (_myLocaleChars == 0) {
        return std::string();
    }
    gchar * myUTF = g_filename_to_utf8(_myLocaleChars, -1, 0, 0, 0);
    if ( ! myUTF) {
        throw UnicodeException(std::string("Failed to convert filename '") + _myLocaleChars  +
                "' to UTF8.", PLUS_FILE_LINE);
    }
    std::string myUTF8String(myUTF);
    g_free(myUTF);
   return myUTF8String;
 #endif
}
开发者ID:artcom,项目名称:asl,代码行数:52,代码来源:Path.cpp

示例6: copy

CString TextCodecMac::encode(const UChar* characters, size_t length, UnencodableHandling handling)
{
    // FIXME: We should really use TEC here instead of CFString for consistency with the other direction.

    // FIXME: Since there's no "force ASCII range" mode in CFString, we change the backslash into a yen sign.
    // Encoding will change the yen sign back into a backslash.
    String copy(characters, length);
    copy.replace('\\', m_backslashAsCurrencySymbol);
    CFStringRef cfs = copy.createCFString();

    CFIndex startPos = 0;
    CFIndex charactersLeft = CFStringGetLength(cfs);
    Vector<char> result;
    size_t size = 0;
    UInt8 lossByte = handling == QuestionMarksForUnencodables ? '?' : 0;
    while (charactersLeft > 0) {
        CFRange range = CFRangeMake(startPos, charactersLeft);
        CFIndex bufferLength;
        CFStringGetBytes(cfs, range, m_encoding, lossByte, false, NULL, 0x7FFFFFFF, &bufferLength);

        result.grow(size + bufferLength);
        unsigned char* buffer = reinterpret_cast<unsigned char*>(result.data() + size);
        CFIndex charactersConverted = CFStringGetBytes(cfs, range, m_encoding, lossByte, false, buffer, bufferLength, &bufferLength);
        size += bufferLength;

        if (charactersConverted != charactersLeft) {
            unsigned badChar = CFStringGetCharacterAtIndex(cfs, startPos + charactersConverted);
            ++charactersConverted;
            if ((badChar & 0xFC00) == 0xD800 && charactersConverted != charactersLeft) { // is high surrogate
                UniChar low = CFStringGetCharacterAtIndex(cfs, startPos + charactersConverted);
                if ((low & 0xFC00) == 0xDC00) { // is low surrogate
                    badChar <<= 10;
                    badChar += low;
                    badChar += 0x10000 - (0xD800 << 10) - 0xDC00;
                    ++charactersConverted;
                }
            }
            UnencodableReplacementArray entity;
            int entityLength = getUnencodableReplacement(badChar, handling, entity);
            result.grow(size + entityLength);
            memcpy(result.data() + size, entity, entityLength);
            size += entityLength;
        }

        startPos += charactersConverted;
        charactersLeft -= charactersConverted;
    }
    CFRelease(cfs);
    return CString(result.data(), size);
}
开发者ID:Fale,项目名称:qtmoko,代码行数:50,代码来源:TextCodecMac.cpp

示例7: IOHIDDeviceGetProperty

bool HIDDeviceManager::getStringProperty(IOHIDDeviceRef device,
                                         CFStringRef propertyName,
                                         String* pResult)
{
    
    CFStringRef str = (CFStringRef) IOHIDDeviceGetProperty(device, propertyName);
    
    if (!str)
    {
        return false;
    }

    CFIndex length = CFStringGetLength(str);
    CFRange range = CFRangeMake(0, length);
    
    // Test the conversion first to get required buffer size.
    CFIndex bufferLength;
    CFIndex numberOfChars = CFStringGetBytes(str,
                                             range,
                                             kCFStringEncodingUTF8,
                                             (char) '?',
                                             FALSE,
                                             NULL,
                                             0,
                                             &bufferLength);
    
    if (numberOfChars == 0)
    {
        return false;
    }
    
    // Now allocate buffer.
    char* buffer = new char[bufferLength+1];
    
    numberOfChars = CFStringGetBytes(str,
                                     range,
                                     kCFStringEncodingUTF8,
                                     (char) '?',
                                     FALSE,
                                     (UInt8*) buffer,
                                     bufferLength,
                                     NULL);
    OVR_ASSERT_LOG(numberOfChars != 0, ("CFStringGetBytes failed."));

    buffer[bufferLength] = '\0';
    *pResult = String(buffer);
    
    return true;
}
开发者ID:123woodman,项目名称:minko,代码行数:49,代码来源:OVR_OSX_HIDDevice.cpp

示例8: CA4CCToCString

void	HP_Object::Show() const
{
	//  the default implementation is to print the object's ID, class ID and name (if it has one)
	
	//  make a string for the class ID
	char theClassID[] = CA4CCToCString(mClassID);
	
	//  get the object's name
	CAPropertyAddress theAddress(kAudioObjectPropertyName, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster);
	CFStringRef theCFName = NULL;
	UInt32 theSize = sizeof(CFStringRef);
	try
	{
		GetPropertyData(theAddress, 0, NULL, theSize, &theCFName);
	}
	catch(...)
	{
		theCFName = NULL;
	}
	
	//  make a C string out of the name
	char theName[256];
	theName[0] = 0;
	if(theCFName != NULL)
	{
		CFIndex theLength = 0;
		CFRange theRange = { 0, CFStringGetLength(theCFName) };
		CFStringGetBytes(theCFName, theRange, kCFStringEncodingUTF8, 0, false, (UInt8*)theName, 255, &theLength);
		theName[theLength] = 0;
		CFRelease(theCFName);
	}
	
	//  print the information to the standard output
	printf("AudioObjectID:\t\t0x%lX\n\tAudioClassID:\t'%s'\n\tName:\t\t\t%s\n", (long unsigned int)mObjectID, theClassID, theName);
}
开发者ID:paulz,项目名称:zirkonium,代码行数:35,代码来源:HP_Object.cpp

示例9: cfstring_to_cstring

static char *
cfstring_to_cstring(CFStringRef cfstr, char *buf, int bufLen)
{
	CFIndex	len	= CFStringGetLength(cfstr);

	if (!buf) {
		bufLen = len + 1;
		buf = CFAllocatorAllocate(NULL, bufLen, 0);
	}

	if (len >= bufLen) {
		len = bufLen - 1;
	}

	(void)CFStringGetBytes(cfstr,
			CFRangeMake(0, len),
			kCFStringEncodingASCII,
			0,
			FALSE,
			buf,
			bufLen,
			NULL);
	buf[len] = '\0';

	return buf;
}
开发者ID:aosm,项目名称:configd_plugins,代码行数:26,代码来源:atconfig.c

示例10: charToPA_Unichar

PA_Unichar* charToPA_Unichar(char* src){
	CFStringRef cfstr = CFStringCreateWithCString(kCFAllocatorDefault, src, kCFStringEncodingUTF8);
	PA_Unichar *dst = malloc(CFStringGetLength(cfstr));
	CFIndex index;
	CFStringGetBytes(cfstr, CFRangeMake(0, CFStringGetLength(cfstr)), kCFStringEncodingUTF16, 0, false, dst, CFStringGetLength(cfstr), &index);
	return dst;
}
开发者ID:jellehelsen,项目名称:CURL4D,代码行数:7,代码来源:CURL4D.c

示例11: UTF8toUTF16

bool UTF8toUTF16(const std::string &str, utf16_char *buf, unsigned int max_len)
{
	bool result = false;

	CFStringRef input = CFStringCreateWithCString(kCFAllocatorDefault, 
													str.c_str(),
													kCFStringEncodingUTF8);
	
	if(input)
	{
		CFIndex len = CFStringGetLength(input);
		
		if(len < max_len)
		{
			CFRange range = {0, len};
			
			CFIndex chars = CFStringGetBytes(input, range,
												kCFStringEncodingUTF16, '?', FALSE,
												(UInt8 *)buf, max_len * sizeof(utf16_char), NULL);
			
			result = (chars == len);
			
			buf[len] = '\0';
		}
		
		
		CFRelease(input);
	}
	
	
	return result;	
}
开发者ID:fnordware,项目名称:openexrPremiere,代码行数:32,代码来源:OpenEXR_UTF.cpp

示例12: set_str

static ST_Error set_str(ST_UserTextFrame *f, CFStringRef s, uint8_t **ptr,
                        uint32_t *sz) {
    CFIndex slen;
    CFIndex l;
    uint8_t *buf;
    void *tmp;

    /* 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(*ptr);
    *sz = slen;
    *ptr = buf;

    return ST_Error_None;
}
开发者ID:ljsebald,项目名称:SonatinaTag,代码行数:29,代码来源:UserTextFrame.c

示例13: CS_TRACE

void Caching_Stream::streamEndEncountered()
{
    if (m_fileOutput) {
        delete m_fileOutput, m_fileOutput = 0;
    }
    
    if (m_cacheable) {
        if (m_writable) {
            CS_TRACE("Successfully cached the stream\n");
            CS_TRACE_CFURL(m_fileUrl);
            
            // We only write the meta data if the stream was successfully streamed.
            // In that way we can use the meta data as an indicator that there is a file to stream.
            
            if (!m_cacheMetaDataWritten) {
                CFWriteStreamRef writeStream = CFWriteStreamCreateWithFile(kCFAllocatorDefault, m_metaDataUrl);
                
                if (writeStream) {
                    if (CFWriteStreamOpen(writeStream)) {
                        CFStringRef contentType = m_target->contentType();
                        
                        UInt8 buf[1024];
                        CFIndex usedBytes = 0;
                        
                        if (contentType) {
                            // It is possible that some streams don't provide a content type
                            CFStringGetBytes(contentType,
                                             CFRangeMake(0, CFStringGetLength(contentType)),
                                             kCFStringEncodingUTF8,
                                             '?',
                                             false,
                                             buf,
                                             1024,
                                             &usedBytes);
                        }
                        
                        if (usedBytes > 0) {
                            CS_TRACE("Writing the meta data\n");
                            CS_TRACE_CFSTRING(contentType);
                            
                            CFWriteStreamWrite(writeStream, buf, usedBytes);
                        }
                        
                        CFWriteStreamClose(writeStream);
                    }
                    
                    CFRelease(writeStream);
                }
                
                m_cacheable = false;
                m_writable  = false;
                m_useCache  = true;
                m_cacheMetaDataWritten = true;
            }
        }
    }
    if (m_delegate) {
        m_delegate->streamEndEncountered();
    }
}
开发者ID:joemcmahon,项目名称:FreeStreamer,代码行数:60,代码来源:caching_stream.cpp

示例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
}
开发者ID:AndreaMelle,项目名称:omnipreview,代码行数:29,代码来源:SDK_File.cpp

示例15: 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;
  }
}
开发者ID:Geal,项目名称:Squeak-VM,代码行数:27,代码来源:sqMacUnixFileInterface.c


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