/** * @brief 替换错误信息里面的KEY 值 * * @param[in] * * @retval */ int ReplaceKeyValueMsg(char *sErrMsg, map<string,string> m_pKeyValue) { char *pBeg=NULL; char *pEnd=NULL; char szBuf[2048] = {0}; char szReturn[2048] = {0}; strcpy(szBuf,sErrMsg); char *pBuf = szBuf;
while(1) { int length = 0; char szKey[32] = {0}; char szValue[32] = {0}; pBeg = strchr(pBuf,'['); if(NULL == pBeg) { break; } pEnd = strchr(pBeg,']'); if(NULL == pEnd) { break; }
length=pEnd-pBeg-1;
strncat(szReturn,pBuf,pBeg-pBuf+1); strncpy(szKey,pBeg+1,length); //查找KEY 值对应的VALUE map<string,string>::iterator iter = m_pKeyValue.find(szKey); if (iter != m_pKeyValue.end()) { strcpy(szValue,iter->second.c_str()); strcat(szReturn,szValue); } else { strcat(szReturn,szKey); } strcat(szReturn,"]");
pBuf = pEnd+1; }
strcat(szReturn,pBuf); strcpy(sErrMsg,szReturn); return CRM_SUCC; }