📄 app_str.c
字号:
/*****************************************************************************
* 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:
* ---------
* app_str.c
*
* Project:
* --------
* Maui_Software
*
* Description:
* ------------
* string related utility
*
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* 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)
*/
#include "kal_non_specific_general_types.h"
#include "app_str.h"
#define ENCODING_LENGTH 2
/*****************************************************************************
* FUNCTION
* app_unicode_to_ucs2encoding
* DESCRIPTION
* convert unicode to UCS2 encoding
* PARAMETERS
* unicode [IN] Value to be encoded
* charLength [?]
* arrOut [?]
* array(?) [OUT] Of kal_uint8
* RETURNS
* kal_uint8 -> Status
*****************************************************************************/
kal_uint8 app_unicode_to_ucs2encoding(kal_uint16 unicode, kal_uint8 *charLength, kal_uint8 *arrOut)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint8 status = 1;
kal_uint8 index = 0;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (arrOut != 0)
{
if (unicode < 256)
{
arrOut[index++] = *((kal_uint8*) (&unicode));
arrOut[index] = 0;
}
else
{
arrOut[index++] = *((kal_uint8*) (&unicode));
arrOut[index] = *(((kal_uint8*) (&unicode)) + 1);
}
*charLength = 2;
}
else
{
status = 0;
}
#ifdef __FOR_TESTING /* MMI_ON_HARDWARE_P */
if (arrOut != 0)
{
if (unicode < 256)
{
arrOut[index++] = 0; /* *((kal_uint8*)(&unicode)); */
arrOut[index] = *((kal_uint8*) (&unicode));
}
else
{
arrOut[index++] = *(((kal_uint8*) (&unicode)) + 1); /* *((kal_uint8*)(&unicode)); */
arrOut[index] = *((kal_uint8*) (&unicode)); /* *(((kal_uint8*)(&unicode)) + 1); */
}
*charLength = 2;
}
else
{
status = 0;
}
#endif /* __FOR_TESTING */
return status;
}
/*****************************************************************************
* FUNCTION
* app_ucs2encoding_to_unicode
* DESCRIPTION
* convert UCS2 encoded scheme to unicode
* PARAMETERS
* pUnicode [?]
* arr [?]
* unicode(?) [OUT] Equivalent
* kal_int8(?) [IN] * -> array containing UCS2 encoded characters
* RETURNS
* kal_uint8 -> Status
*****************************************************************************/
kal_uint8 app_ucs2encoding_to_unicode(kal_uint16 *pUnicode, kal_uint8 *arr)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint8 index = 0;
kal_uint8 status = 1;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if ((arr != NULL) && (pUnicode != NULL))
{
*((kal_uint8*) (pUnicode)) = arr[index++];
*(((kal_uint8*) (pUnicode)) + 1) = arr[index];
}
else
{
status = 0;
}
#ifdef __FOR_TESTING /* MMI_ON_HARDWARE_P */
if ((arr != NULL) && (pUnicode != NULL))
{
*((kal_uint8*) (pUnicode)) = arr[index]; /* arr[index++]; */
*(((kal_uint8*) (pUnicode)) + 1) = arr[index++]; /* arr[index]; */
}
else
{
status = 0;
}
#endif /* __FOR_TESTING */
return status;
}
/*****************************************************************************
* FUNCTION
* app_ucs2_strlen
* DESCRIPTION
* Gives the length of UCS2 encoded string
* PARAMETERS
* arrOut [IN]
* array(?) [IN] Containing UCS2 encoded characters
* RETURNS
* kal_uint16 -> Status
*****************************************************************************/
kal_int32 app_ucs2_strlen(const kal_int8 *arrOut)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int32 nCount = 0;
kal_int32 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 */
}
/*****************************************************************************
* FUNCTION
* app_ucs2_strcmp
* DESCRIPTION
* compares two strings
* PARAMETERS
* string1 [IN] > first String
* string2 [OUT] > Second String
* RETURNS
*
*****************************************************************************/
kal_int32 app_ucs2_strcmp(const kal_int8 *string1, const kal_int8 *string2)
{
/*----------------------------------------------------------------*/
/* 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);
}
}
/*****************************************************************************
* FUNCTION
* app_ucs2_strcpy
* DESCRIPTION
* copies the one UCS2 encoded string to other
* PARAMETERS
* strDestination [?]
* strSource [IN]
* strDest(?) [OUT] > Destination array
* strSrc(?) [IN] > Source Array
* RETURNS
* kal_int8* -> pointer to destination string or NULL
*****************************************************************************/
kal_int8 *app_ucs2_strcpy(kal_int8 *strDestination, const kal_int8 *strSource)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint16 count = 1;
kal_int8 *temp = strDestination;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (strSource == NULL)
{
if (strDestination)
{
*(strDestination + count - 1) = '\0';
*(strDestination + count) = '\0';
}
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) = '\0';
*(strDestination + count) = '\0';
return temp;
}
/*****************************************************************************
* FUNCTION
* app_ucs2_strncmp
* 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" */
kal_int32 app_ucs2_strncmp(const kal_int8 *string1, const kal_int8 *string2, kal_uint32 size)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint32 count = 0;
kal_uint16 nStr1;
kal_uint16 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -