UCS2.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:39k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * UCS2.c
- *
- * Project:
- * --------
- * MAUI
- *
- * Description:
- * ------------
- * UCS2 utility
- *
- * Author:
- * -------
- * -------
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- /**
- * Copyright Notice
- * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
- * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
- * (It is illegal to remove this copyright notice from this software or any
- * portion of it)
- */
- /**********************************************************************************
- Filename: UCS2.c
- Author: Manish
- Date Created: Feb 5-2003
- Contains:
- **********************************************************************************/
- #include "PixtelDataTypes.h"
- #include "Ucs2dcl.h"
- #include "Ucs2prot.h"
- #include "Unicodexdcl.h"
- #include "string.h"
- #include "DebugInitDef.h"
- #ifndef MMI_ON_WIN32
- #include "app_str.h"
- #endif
- /*****************************************************************************
- * FUNCTION
- * UnicodeToUCS2Encoding
- * DESCRIPTION
- * convert unicode to UCS2 encoding
- * PARAMETERS
- * unicode [IN] Value to be encoded
- * charLength [OUT]
- * arrOut [OUT]
- * RETURNS
- * U8 -> Status
- *****************************************************************************/
- U8 UnicodeToUCS2Encoding(U16 unicode, U8 *charLength, U8 *arrOut)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (U8)app_unicode_to_ucs2encoding(
- (kal_uint16)unicode,
- (kal_uint8*)charLength,
- (kal_uint8*)arrOut);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 status = ST_SUCCESS;
- U8 index = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (arrOut != 0)
- {
- if (unicode < 256)
- {
- arrOut[index++] = *((U8*) (&unicode));
- arrOut[index] = 0;
- }
- else
- {
- arrOut[index++] = *((U8*) (&unicode));
- arrOut[index] = *(((U8*) (&unicode)) + 1);
- }
- *charLength = 2;
- }
- else
- {
- status = ST_FAILURE;
- }
- return status;
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2EncodingToUnicode
- * DESCRIPTION
- * convert UCS2 encoded scheme to unicode
- * PARAMETERS
- * pUnicode [IN] array containing UCS2 encoded characters
- * arr [IN] unicode equivalent
- * RETURNS
- * U8 -> Status
- *****************************************************************************/
- U8 UCS2EncodingToUnicode(PU16 pUnicode, PU8 arr)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (U8)app_ucs2encoding_to_unicode((kal_uint16 *)pUnicode, (kal_uint8*)arr);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 index = 0;
- U8 status = ST_SUCCESS;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if ((arr != NULL) && (pUnicode != NULL))
- {
- *((U8*) (pUnicode)) = arr[index++];
- *(((U8*) (pUnicode)) + 1) = arr[index];
- }
- else
- {
- status = ST_FAILURE;
- }
- return status;
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2Strlen
- * DESCRIPTION
- * Gives the length of UCS2 encoded string
- * PARAMETERS
- * arrOut [IN] array containing UCS2 encoded characters
- * RETURNS
- * U16 -> Status
- *****************************************************************************/
- S32 UCS2Strlen(const S8 *arrOut)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (S32)app_ucs2_strlen((const kal_int8 *)arrOut);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 nCount = 0;
- S32 nLength = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* Check for NULL character only at the odd no. of bytes
- assuming forst byte start from zero */
- if (arrOut)
- {
- while (arrOut[nCount] != 0 || arrOut[nCount + 1] != 0)
- {
- ++nLength;
- nCount += 2;
- }
- }
- return nLength; /* One is added to count 0th byte */
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2Strcpy
- * DESCRIPTION
- * copies the one UCS2 encoded string to other
- * PARAMETERS
- * strDestination [OUT] StrDest-> Destination array
- * strSource [IN]
- * RETURNS
- * PS8 -> pointer to destination string or NULL
- *****************************************************************************/
- S8 *UCS2Strcpy(S8 *strDestination, const S8 *strSource)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (S8*)app_ucs2_strcpy((kal_int8*)strDestination, (const kal_int8*)strSource);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 count = 1;
- S8 *temp = strDestination;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (strSource == NULL)
- {
- if (strDestination)
- {
- *(strDestination + count - 1) = ' ';
- *(strDestination + count) = ' ';
- }
- return temp;
- }
- if (strDestination == NULL || strSource == NULL)
- {
- return NULL;
- }
- while (!((*(strSource + count) == 0) && (*(strSource + count - 1) == 0)))
- {
- *(strDestination + count - 1) = *(strSource + count - 1);
- *(strDestination + count) = *(strSource + count);
- count += 2;
- }
- *(strDestination + count - 1) = ' ';
- *(strDestination + count) = ' ';
- return temp;
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2Strcmp
- * DESCRIPTION
- * compares two strings
- * PARAMETERS
- * string1 [IN] > first String
- * string2 [OUT] > Second String
- * RETURNS
- *
- *****************************************************************************/
- S32 UCS2Strcmp(const S8 *string1, const S8 *string2)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (S32)app_ucs2_strcmp((const kal_int8*)string1, (const kal_int8*)string2);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- while ((*string1 == *string2) && (*(string1 + 1) == *(string2 + 1)))
- {
- if ((*string1 == 0) && (*(string1 + 1) == 0))
- {
- return 0;
- }
- string1 += 2;
- string2 += 2;
- } /* End of while */
- /* The return value indicates the lexicographic relation of string1 to string2 */
- /* ie < 0 , > 0 and 0 */
- if (*string1 == *string2 && *(string1 + 1) != *(string2 + 1))
- {
- return (*(string1 + 1) - *(string2 + 1));
- }
- else
- {
- return (*string1 - *string2);
- }
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2Strncmp
- * DESCRIPTION
- * compares two strings
- *
- * In size pass no of characters not bytes
- * PARAMETERS
- * string1 [IN] > first String
- * string2 [OUT] > Second String
- * size [IN]
- * RETURNS
- *
- *****************************************************************************/
- /* MTK Added by Tim for solve a potential wrong answer when string1 and string2 are the same and less than "size" */
- S32 UCS2Strncmp(const S8 *string1, const S8 *string2, U32 size)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (S32)app_ucs2_strncmp(
- (const kal_int8*)string1,
- (const kal_int8*)string2,
- (kal_uint32)size);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U32 count = 0;
- U16 nStr1;
- U16 nStr2;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- size = size << 1; /* User is passing no of charcters not bytes */
- while (count < size)
- {
- nStr1 = (string1[1] << 8) | string1[0];
- nStr2 = (string2[1] << 8) | string2[0];
- if (nStr1 == 0 || nStr2 == 0 || nStr1 != nStr2)
- {
- return nStr1 - nStr2;
- }
- string1 += 2;
- string2 += 2;
- count += 2;
- }
- return 0;
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2Strncpy
- * DESCRIPTION
- * copies the one UCS2 encoded string to other
- *
- * In size pass no of characters not bytes
- * PARAMETERS
- * strDestination [OUT] StrDest-> Destination array
- * strSource [IN]
- * size [IN]
- * RETURNS
- * PS8 -> pointer to destination string or NULL
- *****************************************************************************/
- S8 *UCS2Strncpy(S8 *strDestination, const S8 *strSource, U32 size)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (S8*)app_ucs2_strncpy(
- (kal_int8*)strDestination,
- (const kal_int8*)strSource,
- (kal_uint32)size);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 count = 1;
- U32 count1 = 0;
- S8 *temp = strDestination;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- size = size * 2;
- MMI_ASSERT(!(strDestination == NULL));
- while (!((*(strSource + count) == 0) && (*(strSource + count - 1) == 0)) && (count1 < size))
- {
- *(strDestination + count - 1) = *(strSource + count - 1);
- *(strDestination + count) = *(strSource + count);
- count += 2;
- count1 += 2;
- }
- *(strDestination + count - 1) = ' ';
- *(strDestination + count) = ' ';
- return temp;
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2Strcat
- * DESCRIPTION
- *
- *
- * User has to ensure that enough space is
- * available in destination
- * PARAMETERS
- * strDestination [OUT]
- * strSource [IN]
- * RETURNS
- * PS8
- *****************************************************************************/
- S8 *UCS2Strcat(S8 *strDestination, const S8 *strSource)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (S8*)app_ucs2_strcat((kal_int8*)strDestination, (const kal_int8*)strSource);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S8 *dest = strDestination;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- dest = dest + UCS2Strlen(strDestination) * ENCODING_LENGTH;
- UCS2Strcpy(dest, strSource);
- return strDestination;
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2Strncat
- * DESCRIPTION
- *
- *
- * User has to ensure that enough space is
- * available in destination
- * PARAMETERS
- * strDestination [OUT]
- * strSource [IN]
- * size [IN]
- * RETURNS
- * PS8
- *****************************************************************************/
- S8 *UCS2Strncat(S8 *strDestination, const S8 *strSource, U32 size)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (S8*)app_ucs2_strncat(
- (kal_int8*)strDestination,
- (const kal_int8*)strSource,
- (kal_uint32)size);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S8 *dest = strDestination;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- dest = dest + UCS2Strlen(strDestination) * ENCODING_LENGTH;
- UCS2Strncpy(dest, strSource, size);
- return strDestination;
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2StrAppendChar
- * DESCRIPTION
- *
- *
- * User has to ensure that enough space is
- * available in destination
- * PARAMETERS
- * strDestination [OUT]
- * ch [IN]
- * RETURNS
- * PS8
- *****************************************************************************/
- S8 *UCS2StrAppendChar(S8 *strDestination, U16 ch)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (S8*)app_ucs2str_appendchar((kal_int8*)strDestination, (kal_uint16) ch);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S8 *dest = strDestination;
- U16 buffer[2];
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- dest = dest + UCS2Strlen(strDestination) * ENCODING_LENGTH;
- buffer[0] = ch;
- buffer[1] = 0;
- UCS2Strcpy(dest, (const S8*)buffer);
- return strDestination;
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2StrNAppendChar
- * DESCRIPTION
- *
- *
- * User has to ensure that enough space is
- * available in destination
- * PARAMETERS
- * strDestination [OUT]
- * ch [IN]
- * size [IN]
- * RETURNS
- * PS8
- *****************************************************************************/
- S8 *UCS2StrNAppendChar(S8 *strDestination, U16 ch, U32 size)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (S8*)app_ucs2str_n_appendchar(
- (kal_int8*)strDestination,
- (kal_uint16) ch,
- (kal_uint32)size);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S8 *dest = strDestination;
- U16 buffer[2];
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- dest = dest + UCS2Strlen(strDestination) * ENCODING_LENGTH;
- buffer[0] = ch;
- buffer[1] = 0;
- UCS2Strncpy(dest, (const S8*)buffer, size);
- return strDestination;
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2Strchr
- * DESCRIPTION
- * find the next chr 'c'
- * IMPACT
- * will not affect input strSrc, but return a pointer to point out the place.
- * PARAMETERS
- * strSrc [IN]
- * c [IN]
- * RETURNS
- *
- *****************************************************************************/
- S8 *UCS2Strchr(const S8 *strSrc, U16 c)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 *chr = (U16*) strSrc;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- do
- {
- if (*chr == c)
- {
- return (S8*) chr;
- }
- } while (*(++chr));
- return NULL;
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2StrTrimLeft
- * DESCRIPTION
- * skip over the TrimChars
- * PARAMETERS
- * strSrc [IN]
- * TrimChars [IN]
- * RETURNS
- *
- *****************************************************************************/
- S8 *UCS2StrTrimLeft(const S8 *strSrc, const S8 *TrimChars)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 *chr = (U16*) strSrc;
- S32 trim_length = UCS2Strlen(TrimChars);
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- while (*chr)
- {
- S32 i = 0;
- for (; i < trim_length; i++)
- {
- if (*chr == ((U16*) TrimChars)[i])
- {
- chr++;
- break;
- }
- }
- if (i == trim_length)
- {
- return (S8*) chr;
- }
- }
- return NULL;
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2StrGetStr
- * DESCRIPTION
- * search for the break_chars and store how many chars have been read over to reach
- * the desired break_char in read_length
- * PARAMETERS
- * strSrc [IN]
- * break_chars [IN]
- * read_length [?]
- * direction [IN] 1: sesarch forward ; -1: search backward.
- * RETURNS
- * 1: found the break_chars ; -1: searched over the whole strSrc and do not fing the break_chars
- *****************************************************************************/
- S32 UCS2StrGetStr(const S8 *strSrc, const S8 *break_chars, S32 *read_length, S16 direction)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 *src = (U16*) strSrc;
- S32 x = 0;
- S32 break_chars_length = UCS2Strlen(break_chars);
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- while (*src)
- {
- for (x = 0; x < break_chars_length; x++)
- {
- if (*src == ((U16*) break_chars)[x])
- {
- if (direction > 0)
- {
- *read_length = src - (U16*) strSrc;
- }
- else
- {
- *read_length = (U16*) strSrc - src;
- }
- return 1;
- }
- }
- src += direction;
- }
- return -1;
- }
- /*****************************************************************************
- * FUNCTION
- * UCS2StrGetNumInt
- * DESCRIPTION
- * to parse over a int number, including positive and negative signs (+,-).
- * PARAMETERS
- * strSrc [IN]
- * out_num [?] Is the parsed int number
- * read_length [?]
- * RETURNS
- * 1: parse successfully ; -1: parse number fail.
- *****************************************************************************/
- S32 UCS2StrGetNumInt(const S8 *strSrc, S32 *out_num, S32 *read_length)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- #define GETNUM(wchar_p) (*wchar_p - L'0')
- U16 *src = (U16*) strSrc;
- BOOL is_negative = FALSE;
- S32 num = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (*src == L'-')
- {
- is_negative = TRUE;
- src++;
- }
- if (*src == L'+')
- {
- src++;
- }
- if (GETNUM(src) < 0 || GETNUM(src) > 9)
- {
- return -1;
- }
- while (*src)
- {
- if (GETNUM(src) < 0 || GETNUM(src) > 9)
- {
- break;
- }
- num = num * 10 + GETNUM(src);
- src++;
- }
- *read_length = src - (U16*) strSrc;
- if (is_negative)
- {
- *out_num = -num;
- }
- else
- {
- *out_num = num;
- }
- return 1;
- }
- /*****************************************************************************
- * FUNCTION
- * AnsiiToUnicodeString
- * DESCRIPTION
- * Converts Ansii encode string to unicode
- *
- * Caller has to ensure that pOutBuffer
- * should be as large
- * PARAMETERS
- * pOutBuffer [OUT]
- * pInBuffer [IN]
- * RETURNS
- * U16
- *****************************************************************************/
- U16 AnsiiToUnicodeString(S8 *pOutBuffer, S8 *pInBuffer)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (U16)app_ansii_to_unicodestring((kal_int8*)pOutBuffer, (kal_int8*)pInBuffer);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 count = -1;
- U8 charLen = 0;
- U8 arrOut[2];
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- while (*pInBuffer != ' ')
- {
- UnicodeToUCS2Encoding((U16) * ((PU8) pInBuffer), &charLen, arrOut);
- // #ifdef MMI_ON_WIN32
- pOutBuffer[++count] = arrOut[0];
- pOutBuffer[++count] = arrOut[1];
- pInBuffer++;
- // #endif
- #ifdef __FOR_TESTING /* MMI_ON_HARDWARE_P */
- pOutBuffer[++count] = arrOut[1]; /* arrOut[0]; */
- pOutBuffer[++count] = arrOut[0]; /* arrOut[1]; */
- pInBuffer++;
- #endif /* __FOR_TESTING */
- }
- pOutBuffer[++count] = ' ';
- pOutBuffer[++count] = ' ';
- return count + 1;
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * AnsiiNToUnicodeString
- * DESCRIPTION
- * Converts N character Ansii encode string to unicode
- *
- * Caller has to ensure that pOutBuffer
- * should be as large
- * PARAMETERS
- * pOutBuffer [OUT]
- * pInBuffer [IN]
- * len [IN]
- * RETURNS
- * U16
- *****************************************************************************/
- U16 AnsiiNToUnicodeString(S8 *pOutBuffer, S8 *pInBuffer, U32 len)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (U16)app_ansii_n_to_unicodestring(
- (kal_int8*)pOutBuffer,
- (kal_int8*)pInBuffer,
- (kal_uint32)len);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 count = -1;
- U8 charLen = 0;
- U8 arrOut[2];
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- while (len)
- {
- UnicodeToUCS2Encoding((U16) * ((PU8) pInBuffer), &charLen, arrOut);
- // #ifdef MMI_ON_WIN32
- pOutBuffer[++count] = arrOut[0];
- pOutBuffer[++count] = arrOut[1];
- if (*pInBuffer == ' ')
- {
- break;
- }
- else
- {
- pInBuffer++;
- }
- // #endif
- #ifdef __FOR_TESTING /* MMI_ON_HARDWARE_P */
- pOutBuffer[++count] = arrOut[1]; /* arrOut[0]; */
- pOutBuffer[++count] = arrOut[0]; /* arrOut[1]; */
- pInBuffer++;
- #endif /* __FOR_TESTING */
- len--;
- }
- return count + 1;
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UnicodeToAnsii
- * DESCRIPTION
- * Converts Unicode encode string to Ascii
- *
- * Caller has to ensure that pOutBuffer
- * should be large enough
- * PARAMETERS
- * pOutBuffer [OUT]
- * pInBuffer [IN]
- * RETURNS
- * U16
- *****************************************************************************/
- U16 UnicodeToAnsii(S8 *pOutBuffer, S8 *pInBuffer)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (U16)app_unicode_to_ansii((kal_int8*)pOutBuffer,(kal_int8*)pInBuffer);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 count = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- while (!((*pInBuffer == 0) && (*(pInBuffer + 1) == 0)))
- {
- *pOutBuffer = *(pInBuffer);
- #ifdef __FOR_TESTING /* MMI_ON_HARDWARE_P */
- *pOutBuffer = *(pInBuffer + 1);
- #endif
- pInBuffer += 2;
- pOutBuffer++;
- count++;
- }
- *pOutBuffer = 0;
- return count;
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * UnicodeNToAnsii
- * DESCRIPTION
- * Converts N character Unicode encode string to Ascii
- *
- * Caller has to ensure that pOutBuffer
- * should be large enough
- * PARAMETERS
- * pOutBuffer [OUT]
- * pInBuffer [IN]
- * len [IN]
- * RETURNS
- * U16
- *****************************************************************************/
- U16 UnicodeNToAnsii(S8 *pOutBuffer, S8 *pInBuffer, U32 len)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* On the Target */
- return (U16)app_unicode_n_to_ansii(
- (kal_int8*)pOutBuffer,
- (kal_int8*)pInBuffer,
- (kal_uint32)len);
- #else
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 count = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- while ((len) && (!((*pInBuffer == 0) && (*(pInBuffer + 1) == 0))))
- {
- *pOutBuffer = *(pInBuffer);
- #ifdef __FOR_TESTING /* MMI_ON_HARDWARE_P */
- *pOutBuffer = *(pInBuffer + 1);
- #endif
- pInBuffer += 2;
- pOutBuffer++;
- count++;
- len -= 2;
- }
- return count;
- #endif
- }