📄 dcw_pb_api.c
字号:
}
/****************************************************************************
* Function name : DCW_PB_spellToShortSpell
* Description : 提取spell编码的首字母编码
* Param : inStr: 字符串1,IN
* outStr: 字符串2,OUT
* Return : None
* Author: : *************
* Note : None
*****************************************************************************/
void DCW_PB_spellToShortSpell(T_PB_M_STRING *inStrPtr, T_PB_S_STRING *outStrPtr)
{
int16 i;
int16 len;
uint16 value;
len = inStrPtr->len / 2;
if(len == 0)
{
return;
}
outStrPtr->len = 0;
for(i = 0; i < len; i++)
{
value = ((inStrPtr->array[i * 2] << 8) + (inStrPtr->array[i * 2 + 1]));
/* 取首字母*/
outStrPtr->array[i] = DCW_PB_getSpellPrimacyLetter(value);
outStrPtr->len++;
}
}
/****************************************************************************
* Function name : DCW_PB_getLetterSpell
* Description : 由一个ucs2编码转化为一个spell编码
* Param : value: 一个ucs2编码
* Return : 一个spell编码
* Author: : *************
* Note : None
*****************************************************************************/
uint16 DCW_PB_getLetterSpell(uint16 value)
{
uint8 high;
uint8 low;
int16 base;
uint16 startPos;
uint16 endPos;
uint16 midPos;
T_PB_UCS2_SPELL_SN *ptr;
high = (uint8)(value>> 8);
low = (uint8)(value);
if(high == 0x00)
{ /* ACSII编码 */
ptr= (T_PB_UCS2_SPELL_SN *)g_pb_ucs2_spell_sn_table[0].tablePtr;
startPos = 0;
endPos = g_pb_ucs2_spell_sn_table[0].tableSize;
}
else if(high == 0x32)
{ /* 特殊编码 */
ptr= (T_PB_UCS2_SPELL_SN *)g_pb_ucs2_spell_sn_table[1].tablePtr;
startPos = 0;
endPos = g_pb_ucs2_spell_sn_table[1].tableSize;
}
else
{ /* 汉字编码 */
if(high < 0x4E || high > 0x9F)
{
return DCW_PB_DEFAULT_ERROR_WORD;
}
base = high - 0x4E + 2;
ptr= (T_PB_UCS2_SPELL_SN *)g_pb_ucs2_spell_sn_table[base].tablePtr;
startPos = 0;
endPos = g_pb_ucs2_spell_sn_table[base].tableSize;
}
if(endPos == 0)
{
return DCW_PB_DEFAULT_ERROR_WORD;
}
/* 二分查找 */
while(startPos < endPos)
{
midPos = (startPos + endPos)/2;
if(value < ptr[midPos].ucs2)
{
endPos = midPos;
}
else if(value > ptr[midPos].ucs2)
{
startPos = midPos + 1;
}
else
{
return ptr[midPos].spell;
}
}
return DCW_PB_DEFAULT_ERROR_WORD;
}
/****************************************************************************
* Function name : DCW_PB_getSpellPrimacyLetter
* Description : 取spell编码的首字母编码
* Param : value: 一个spell编码
* Return : 首字母编码
* Author: : *************
* Note : None
*****************************************************************************/
uint8 DCW_PB_getSpellPrimacyLetter(uint16 value)
{
uint16 startPos = 0;
uint16 endPos = 26;
uint16 midPos;
uint8 pos;
while(startPos < endPos)
{
midPos = (startPos + endPos)/2;
if(value < g_pb_letter_spell[midPos])
{
endPos = midPos;
}
else if(value > g_pb_letter_spell[midPos])
{
startPos = midPos + 1;
}
else
{
return (uint8)('A' + midPos);
}
}
if(endPos == 0)
{
// 非字母的ASCII编码
return 0x00;
}
else
{
return (uint8)('A' + endPos - 1);
}
}
/****************************************************************************
* Function name : DCW_PB_twoSplitSearch
* Description : 对一个关键字在一个列表里进行查找
* Param : startPos 查找开始的位置
endPos 查找结束的位置
keyInfo 查找的关键字信息
(*compare) 比较的方法
searchInfo 返回的查找信息
* Return : None
* Author: : *************
* Note : None
*****************************************************************************/
void DCW_PB_twoSplitSearch(uint16 startPos,uint16 endPos,void *keyInfo,
int8 (*comparePtr)(void *,int16),T_PB_SEARCH_RETURN_INFO *searchInfoPtr)
{
uint16 midPos;
int8 ret = 0;
SCI_ASSERT(keyInfo != PNULL);
SCI_ASSERT(searchInfoPtr != PNULL);
if(startPos == endPos)
{
searchInfoPtr->equal = FALSE;
searchInfoPtr->pos = startPos;
return;
}
while(startPos < endPos)
{
midPos = (startPos + endPos)/2;
ret = (*comparePtr)(keyInfo, midPos);
if(ret < 0)
{
endPos = midPos;
}
else if(ret > 0)
{
startPos = midPos + 1;
}
else
{
startPos = midPos;
endPos = midPos;
}
}
if(ret == 0)
{
searchInfoPtr->equal = TRUE;
searchInfoPtr->pos = startPos;
}
else
{
searchInfoPtr->equal = FALSE;
searchInfoPtr->pos = startPos;
}
}
/****************************************************************************
* Function name : DCW_PB_compareNvRecord
* Description : 在nv记录列表里查找某一条记录的比较方法
* Param : keyInfo 查找的关键字信息
comparePos 与nv记录列表里的那一条进行比较
* Return : int8 0:相等
1:包含
2:大于
-1:被包含
-2:小于
* Author: : *************
* Note : None
*****************************************************************************/
int8 DCW_PB_compareNvRecord(void *keyInfoPtr,int16 comparePos)
{
T_PB_M_STRING *namePtr;
SCI_TRACE_LOW("\r\n--DCW_PB_compareNvRecord----%d,%d", comparePos,g_pb.nv.usedRecord);
SCI_ASSERT(comparePos >= 0 && comparePos < g_pb.nv.usedRecord);
namePtr = (T_PB_M_STRING *)keyInfoPtr;
return DCW_PB_compareByChar(namePtr->array, g_pb.nv.recordPtr[comparePos].innerName.array,
namePtr->len, g_pb.nv.recordPtr[comparePos].innerName.len);
}
/****************************************************************************
* Function name : DCW_PB_compareSimRecord
* Description : 在sim记录列表里查找某一条记录的比较方法
* Param : keyInfo 查找的关键字信息
comparePos 与sim记录列表里的那一条进行比较
* Return : int 0:相等
1:包含
2:大于
-1:被包含
-2:小于
* Author: : *************
* Note : None
*****************************************************************************/
int8 DCW_PB_compareSimRecord(void *keyInfoPtr,int16 comparePos)
{
T_PB_M_STRING *namePtr;
SCI_ASSERT(comparePos >= 0 && comparePos < g_pb.sim.usedRecord);
namePtr = (T_PB_M_STRING *)keyInfoPtr;
return DCW_PB_compareByChar(namePtr->array,g_pb.sim.recordPtr[comparePos].innerName.array,
namePtr->len,g_pb.sim.recordPtr[comparePos].innerName.len);
}
int8 DCW_PB_compareFastRecord(void *keyInfoPtr,int16 comparePos)
{
uint16 pos;
T_PB_S_STRING *pShortNameDst;
T_PB_S_STRING *pShortNameSrc;
SCI_ASSERT(comparePos >= 0 && comparePos < g_pb.operate.fastSearchInfo.addrManager.amount);
pShortNameSrc = (T_PB_S_STRING *)keyInfoPtr;
pShortNameDst = DCW_PB_getFastSearchShortName(comparePos);
return DCW_PB_compareByChar(pShortNameSrc->array, pShortNameDst->array,
pShortNameSrc->len, pShortNameDst->len);
}
/****************************************************************************
* Function name : DCW_PB_comparePhoneNumber
* Description :
* Param :
* Return :
* Author: : *************
* Note : None
*****************************************************************************/
int8 DCW_PB_comparePhoneNumber(void *keyInfoPtr,int16 comparePos)
{
T_PB_SEARCH_NUMBER_ITEM *itemPtr;
SCI_ASSERT(comparePos >= 0 && comparePos < g_pb.numSearchList.count);
itemPtr= (T_PB_SEARCH_NUMBER_ITEM *)keyInfoPtr;
if(itemPtr->cmpNum.high > g_pb.numSearchList.ptr[comparePos].cmpNum.high)
{
return 1;
}
else if(itemPtr->cmpNum.high < g_pb.numSearchList.ptr[comparePos].cmpNum.high)
{
return -1;
}
else if(itemPtr->cmpNum.low > g_pb.numSearchList.ptr[comparePos].cmpNum.low)
{
return 1;
}
else if(itemPtr->cmpNum.low < g_pb.numSearchList.ptr[comparePos].cmpNum.low)
{
return -1;
}
else if(itemPtr->cmpNum.len > g_pb.numSearchList.ptr[comparePos].cmpNum.len)
{
return 1;
}
else if(itemPtr->cmpNum.len > g_pb.numSearchList.ptr[comparePos].cmpNum.len)
{
return -1;
}
else
{
if(itemPtr->type != g_pb.numSearchList.ptr[comparePos].type)
{
if(itemPtr->type == PHONEBOOK_SIM_STORAGE)
{
return -1;
}
else
{
return 1;
}
}
else
{
if(itemPtr->id < g_pb.numSearchList.ptr[comparePos].id)
{
return -1;
}
else if(itemPtr->id > g_pb.numSearchList.ptr[comparePos].id)
{
return 1;
}
else
{
if(itemPtr->offset < g_pb.numSearchList.ptr[comparePos].offset)
{
return -1;
}
else if(itemPtr->offset > g_pb.numSearchList.ptr[comparePos].offset)
{
return 1;
}
else
{
return 0;
}
}
}
}
}
/****************************************************************************
* Function name : DCW_PB_compareByChar
* Description : 字符比较
* Param : src :字符串1
dst :字符串2
srcLen:字符串1的长度
dstLen:字符串2的长度
* Return : int 0:相等
1:包含
2:大于
-1:被包含
-2:小于
* Author: : *************
* Note : None
*****************************************************************************/
int8 DCW_PB_compareByChar(uint8 *srcPtr, uint8 *dstPtr, uint8 srcLen, uint8 dstLen)
{
uint8 i = 0;
while(i < srcLen && i < dstLen)
{
if(srcPtr[i] > dstPtr[i])
{
return 2;
}
else if(srcPtr[i] < dstPtr[i])
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -