cocos2d-x节点(ccUTF8.h)API

本文详细介绍了cocos2d-x中ccUTF8.h头文件提供的节点API,包括UTF-16到UTF-8的转换及字节数统计,对于cocos2d-x开发者具有参考价值。
摘要由CSDN通过智能技术生成

本文来自http://blog.csdn.net/runaying ,引用必须注明出处!

cocos2d-x节点(ccUTF8.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

UTF-16 转换为 UTF-8,统计写入/读取的字节数

///cocos2d-x-3.0alpha0/cocos2dx/support
//UTF-16 转换为 UTF-8,统计 写入/读取 的字节数
//
//  ccUTF8.h
//  cocos2dx
//
//  Created by James Chen on 2/27/13.
//

#ifndef __cocos2dx__ccUTF8__
#define __cocos2dx__ccUTF8__

#include "platform/CCPlatformMacros.h"
#include <vector>

NS_CC_BEGIN

CC_DLL int cc_wcslen(const unsigned short* str);

CC_DLL void cc_utf8_trim_ws(std::vector<unsigned short>* str);

/**
 * 该字符是否是空白字符。
 *
 * @param ch    Unicode字符
 * @returns     该字符是否是空白字符
 *
 * @see http://en.wikipedia.org/wiki/Whitespace_character#Unicode
 * */
CC_DLL bool isspace_unicode(unsigned short ch);

/**
 * Returns 字符中的字符串的长度。
 *
 * @param p     指向一个UTF-8编码字符串的开始
 * @param max   检查字节的最大数量。如果\ P max是小于0,则该字符串被假定为null结尾的。如果最大的\ p为0,\ PP不会被检查,我的是%NULL。
 *
 * @returns the length of the string in characters
 **/
CC_DLL long
cc_utf8_strlen (const char * p, int max);

/**
 * 寻找不等于给定的字符的最后一个字符。
 *
 * @param str   the string to be searched.
 * @param c    要搜索的字符.
 *
 * @returns the index of the last character that is not \p c.   //index最后一个字符不是 \p c
 * */
CC_DLL unsigned int cc_utf8_find_last_not_char(std::vector<unsigned short> str, unsigned short c);

CC_DLL std::vector<unsigned short> cc_utf16_vec_from_utf16_str(const unsigned short* str);

/**
 * Creates a utf8 string from a cstring.
 *
 * @param str_old   pointer to the start of a C string.
 *
 * @returns the newly created utf8 string.
 * */
CC_DLL unsigned short* cc_utf8_to_utf16(const char* str_old, int length = -1, int* rUtf16Size = NULL);

/**
 * Convert a string from UTF-16 to UTF-8. The result will be null terminated.
 *
 * @param str   a UTF-16 encoded string
 * @param len   the maximum length of \p str to use. If \p len < 0, then the
 *              string is null terminated.
 * @param items_read    读取到的本地存储的单词数,如果%NULL,那么%G_CONVERT_ERROR_PARTIAL_INPUT 将返回一个包含 \p str 的结尾字符,如果发生一个错误,无效的输入 index 储存在这里
 * @param items_written 写入到本地的 byte数,or %NULL.
 *                     这里存储的值不包括结尾的 null.
 *
 * @returns 个新分配的UTF-8字符串指针。这个值必须是
 *用free()释放。如果发生错误,%将返回NULL。
 **/
CC_DLL char *
cc_utf16_to_utf8 (const unsigned short  *str,
                  long             len,
                  long            *items_read,
                  long            *items_written);

NS_CC_END

#endif /* defined(__cocos2dx__ccUTF8__) */


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值