MTK平台转换字符编码方式

如果我不想在ref_list.txt文件中加入我们的字符串字符,那么我们是否可以直接在代码里定义字符串呢?例如中文字符串,因为在代码里定义的中文字符串都是GB码的,而MTK系统对于字符函数API都只接受UNICODE编码的。

 

我们可以通过文件conversion.c文件中的函数mmi_chset_text_to_ucs2(.... )函数对GB编码的字符串进行转换;但是使用该函数是必须将宏__MMI_CHSET_GB2312__打开,否则转换后必定显示乱码;为什么会这样呢?我们看入下代码片断:

在conversion.c中的头部有如下代码片断:

#if defined(__MMI_CHSET_BIG5__)
mmi_chset_enum g_chset_text_encoding = MMI_CHSET_BIG5;
#elif defined(__MMI_CHSET_GB2312__)
mmi_chset_enum g_chset_text_encoding = MMI_CHSET_GB2312;
#else
mmi_chset_enum g_chset_text_encoding = MMI_CHSET_UTF8;
#endif

由此可见,如果我们不打开__MMI_CHSET_GB2312__宏,g_chset_text_encoding 就是不是MMI_CHSET_GB2312 值;而是其它值,则函数mmi_chset_text_to_ucs2(....)就不能对GB编码的字符串进行转换。

mmi_chset_text_to_ucs2(....)函数片断:

kal_int32 mmi_chset_text_to_ucs2(kal_uint8 *dest, kal_int32 dest_size, kal_uint8 *src)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return mmi_chset_convert(g_chset_text_encoding, MMI_CHSET_UCS2, (char*)src, (char*)dest, dest_size);
}
 

问题是我们如何打开宏__MMI_CHSET_GB2312__呢??????? 

我们来看看MKT的features配置文件——MMI_features.h中的片断。

#if defined(CFG_MMI_CHSET_GB2312) && (CFG_MMI_CHSET_GB2312 == __ON__) || /
 (defined(__MMI_LANG_CHSET_DEPENDENCE__) && defined(__MMI_LANG_SM_CHINESE__))
 #ifndef __MMI_CHSET_GB2312__
 #define __MMI_CHSET_GB2312__
 #endif
#endif

那么宏CFG_MMI_CHSET_GB2312又在哪里呢?????

我们看看文件MMI_features_switch.h代码片断如下:

/*
  Description: Turn on simple Chinese GB2312 charset
  Option: [__ON__, __OFF__, __AUTO__]
  Reference: SOP_Add_New_Charset_Conversion.doc
*/
#define CFG_MMI_CHSET_GB2312 (__AUTO__)

 

[疑问]在配置文件MMI_features_type.h中有如下定义

/* general on/off/auto type */
#define __ON__          (-1)
#define __OFF__         (-2)
#define __AUTO__        (-3)

其中__AUTO__ 不知道是什么意思??????


当然如果__MMI_CHSET_GB2312__没有被Enable,我们可以直接使用函数mmi_chset_convert()

该函数原形如下所示:

/*****************************************************************************
 * FUNCTION
 *  mmi_chset_convert
 * DESCRIPTION
 *  Convert string between 2 character sets. (will add the terminate character)
 * PARAMETERS
 *  src_type        [IN]        Charset type of source
 *  dest_type       [IN]        Charset type of destination
 *  src_buff        [IN]        Buffer stores source string
 *  dest_buff       [OUT]       Buffer stores destination string
 *  dest_size       [IN]        Size of destination buffer (bytes)
 * RETURNS
 *  Length of destination string, including null terminator. (bytes)
 *****************************************************************************/
kal_int32 mmi_chset_convert(
            mmi_chset_enum src_type,
            mmi_chset_enum dest_type,
            char *src_buff,
            char *dest_buff,
            kal_int32 dest_size);
使用方式如下:

  mmi_chset_convert(MMI_CHSET_GB2312,MMI_CHSET_UCS2,(char * )soure_string,(char *)destion_string,source_size);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值