詳解MTK系統(tǒng)中字符轉(zhuǎn)換問題
MTK系統(tǒng)中字符轉(zhuǎn)換問題是本文要介紹的內(nèi)容,主要是來了解并學習MTK中一些小案例的應(yīng)用,具體內(nèi)容來看本文詳解。如果我不想在ref_list.txt文件中加入我們的字符串字符,那么我們是否可以直接在代碼里定義字符串呢?例如中文字符串,因為在代碼里定義的中文字符串都是GB碼的,而MTK系統(tǒng)對于字符函數(shù)API都只接受UNICODE編碼的。
我們可以通過文件conversion.c文件中的函數(shù)mmi_chset_text_to_ucs2(.... )函數(shù)對GB編碼的字符串進行轉(zhuǎn)換;但是使用該函數(shù)是必須將宏__MMI_CHSET_GB2312__打開,否則轉(zhuǎn)換后必定顯示亂碼;為什么會這樣呢?我們看入下代碼片斷:
在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 值;而是其它值,則函數(shù)mmi_chset_text_to_ucs2(....)就不能對GB編碼的字符串進行轉(zhuǎn)換。
mmi_chset_text_to_ucs2(....)函數(shù)片斷:
- 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);
- }
問題是我們?nèi)绾未蜷_宏__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,我們可以直接使用函數(shù)mmi_chset_convert()
該函數(shù)原形如下所示:
- /*****************************************************************************
- * 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);
小結(jié):MTK系統(tǒng)中字符轉(zhuǎn)換問題的內(nèi)容介紹完了,希望通過本文的學習能對你有所幫助!