home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / common / cstring.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  3.0 KB  |  121 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1997                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1998               *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.                  *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure             *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                              *
  10. *                                                                                       *
  11. *****************************************************************************************
  12. *
  13. * File CSTRING.C
  14. *
  15. * @author       Helena Shih
  16. *
  17. * Modification History:
  18. *
  19. *   Date        Name        Description
  20. *   6/18/98     hshih       Created
  21. *    09/08/98    stephen        Added include for ctype, for Mac Port
  22. *****************************************************************************************
  23. */
  24.  
  25.  
  26.  
  27. #ifndef _CSTRING
  28. #include "cstring.h"
  29. #endif
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <ctype.h>
  34.  
  35. char T_CString_toffst(char a) 
  36. {
  37.     if (a>0x39) return 0x37;
  38.     else return 0x30;
  39. }
  40.  
  41.  
  42. #define T_CString_itosOffset(a) a<=9?(0x30+a):(0x30+a+7)
  43.  
  44. char*
  45. T_CString_toLowerCase(char* str)
  46. {
  47.     uint32_t i=0;
  48.     while(str[i]) 
  49.         str[i++] = tolower(str[i]);
  50.     return str;
  51. }
  52.  
  53. char*
  54. T_CString_toUpperCase(char* str)
  55. {
  56.     uint32_t i=0;
  57.     while(str[i]) 
  58.         str[i++] = toupper(str[i]);
  59.     return str;
  60. }
  61.  
  62. /*Takes a int32_t and     fills in  a char* string with that number "radix"-based*/
  63.  
  64. void T_CString_integerToString(char* buffer, int32_t i, int32_t radix)
  65. {
  66.   int32_t length=0;
  67.   int32_t num = 0;
  68.   int8_t digit;
  69.   int32_t j;
  70.   char temp;
  71.   
  72.   while (i>radix)
  73.     {
  74.       num = i/radix;
  75.       digit = (int8_t)(i - num*radix);
  76.       buffer[length++] = (T_CString_itosOffset(digit));
  77.       i = num;
  78.     }
  79.   
  80.   buffer[length] = (T_CString_itosOffset(i));
  81.   buffer[length+1] = '\0';
  82.   
  83.   
  84.   /*Reverses the string*/
  85.   for (j=0 ; j<(length/2) + 1 ; j++)
  86.     {
  87.       temp = buffer[length - j];
  88.       buffer[length - j] = buffer[j];
  89.       buffer[j] = temp;
  90.     }
  91.   
  92.   return;
  93. }
  94.  
  95. #include <stdio.h>
  96.  
  97. int32_t
  98. T_CString_stringToInteger(const char *integerString, int32_t radix)
  99. {
  100.     
  101.   /*    int32_t     integer = 0;
  102.     int8_t      sign = (integerString[0]=='-')?(1):0;
  103.     uint32_t    i   = sign;
  104.     int8_t digit;*/
  105.     char *end;
  106.     return strtoul(integerString, &end, radix);
  107.       /*    for (;integerString[i];i++)
  108.     {
  109.         digit = toupper(integerString[i]) - T_CString_toffst((char)toupper(integerString[i]));
  110.         if ((digit<0)||(digit>=radix))  {
  111.             return 0;
  112.         }
  113.         integer = integer*radix + digit;
  114.     }
  115.     
  116.     if (sign) return (-1)*integer;
  117.     else return integer;*/
  118. }
  119.     
  120.  
  121.