KAVStrTranslate.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:3k
源码类别:

模拟服务器

开发平台:

C/C++

  1. //////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  FileName    :   KAVStrTranslate.h
  4. //  Version     :   1.0
  5. //  Creater     :   Freeway Chen
  6. //  Date        :   2001-5-9 11:35:56
  7. //  Comment     :   Kingsoft AntiVirus string translate header file
  8. //
  9. //////////////////////////////////////////////////////////////////////////////////////
  10. #ifndef _KAVSTRTRANSLATE_H
  11. #define _KAVSTRTRANSLATE_H
  12. int inline _IntToStr(int nNum, char *pszStr, int nDigitalNum)
  13. {
  14.     while (nDigitalNum)
  15.     {
  16.         pszStr[nDigitalNum - 1] = '0' + (nNum % 10);
  17.         
  18.         nNum /= 10;
  19.         
  20.         nDigitalNum--;
  21.     }
  22.     
  23.     return true;
  24. }
  25. int inline _IntToStr(int nNum, int nStrSize, char *pszStr)
  26. {
  27.     nStrSize--; // use for last '' char
  28.     nNum = nNum & 0x7fffffff;
  29.     int i = 0;
  30.     while (nStrSize > 0)
  31. {
  32.         pszStr[i] = '0' + (short)(nNum % 10);
  33.         nNum /= 10;
  34.         nStrSize--;
  35.         
  36.         i++;
  37.         if (nNum == 0)
  38.             break;
  39. }
  40.     pszStr[i] = '';
  41.     int j = 0;
  42.     while (j < (i / 2))
  43.     {
  44.         char ch = pszStr[j];
  45.         pszStr[j] = pszStr[i - j - 1];
  46.         pszStr[i - j - 1] = ch;
  47.         j++;
  48.     }
  49. return i;
  50. }
  51. int inline _StrToInt(char *pszStr)
  52. {
  53.     int i;
  54.     int nLen;
  55.     int nNum = 0;
  56.     nLen = strlen(pszStr);
  57.     for (i = 0; i < nLen; i++)
  58.     {
  59.         if (
  60.             (pszStr[i] >= '0') &&
  61.             (pszStr[i] <= '9')
  62.         )
  63.         {
  64.             nNum = nNum * 10 + (pszStr[i] - '0');
  65.         }
  66.         else
  67.             break;
  68.     }
  69.     return nNum;
  70. }
  71. /*
  72. unsigned inline _StrToUInt(char *pszStr)
  73. {
  74.     int i;
  75.     int nLen;
  76.     unsigned uNum = 0;
  77.     nLen = strlen(pszStr);
  78.     for (i = 0; i < nLen; i++)
  79.     {
  80.         if (
  81.             (pszStr[i] >= '0') &&
  82.             (pszStr[i] <= '9')
  83.         )
  84.         {
  85.             uNum = uNum * 10 + (pszStr[i] - '0');
  86.         }
  87.         else
  88.             break;
  89.     }
  90.     return uNum;
  91. }
  92. inline int _StrToInt(const char *nptr)
  93. {
  94.     int c;
  95.     long total;
  96.     int sign;
  97.     while (true)
  98.     {
  99.         if (
  100.             (*nptr != ' ') && 
  101.             (*nptr != 't')
  102.         )
  103.             break;
  104.         nptr++;
  105.     }
  106.     c = (int)(unsigned char)*nptr++;
  107.     sign = c;
  108.     if (c == '-' || c == '+')
  109.         c = (int)(unsigned char)*nptr++;
  110.     total = 0;
  111.     while ((c >= '0') && (c <= '9')) 
  112.     {
  113.         total = 10 * total + (c - '0');
  114.         c = (int)(unsigned char)*nptr++;
  115.     }
  116.     if (sign == '-')
  117.         return -total;
  118.     else
  119.         return total;   
  120. }
  121. */
  122. int inline _HexToStrRight(int nNum, int nStrSize, char *pszStr)
  123. {
  124.     static char chHexToChar[] = 
  125.     {
  126.         '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
  127.     };
  128.     nStrSize--;
  129.     pszStr[nStrSize] = '';
  130.     int nResidue = 0;
  131. while (nStrSize > 0)
  132. {
  133.         nResidue = nNum % 0x10;
  134.         
  135.         pszStr[nStrSize - 1] = chHexToChar[nResidue];
  136.         nNum /= 0x10;
  137.         nStrSize--;
  138. }
  139. return true;
  140. }
  141. #endif // _KAVSTRTRANSLATE_H