Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.3 KiB

  1. /***
  2. *wchtodig.c - Contains _wchartodigit function
  3. *
  4. * Copyright (c) 1989-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * _wchartodigit - convert wchar_t character to digit
  8. *
  9. *Revision History:
  10. * 08-01-00 GB Module Created
  11. *
  12. *******************************************************************************/
  13. #include <wchar.h>
  14. /***
  15. *_wchartodigit(wchar_t) converts unicode character to it's corrosponding digit
  16. *
  17. *Purpose:
  18. * Convert unicode character to it's corrosponding digit
  19. *
  20. *Entry:
  21. * ch char to convert
  22. *
  23. *Exit:
  24. * good result: int 0-9
  25. *
  26. * bad result: -1
  27. *
  28. *Exceptions:
  29. *
  30. *******************************************************************************/
  31. int _wchartodigit(wchar_t ch)
  32. {
  33. #define DIGIT_RANGE_TEST(zero) \
  34. if (ch < zero) \
  35. return -1; \
  36. if (ch < zero + 10) \
  37. { \
  38. return ch - zero; \
  39. }
  40. DIGIT_RANGE_TEST(0x0030) // 0030;DIGIT ZERO
  41. if (ch < 0xFF10) // FF10;FULLWIDTH DIGIT ZERO
  42. {
  43. DIGIT_RANGE_TEST(0x0660) // 0660;ARABIC-INDIC DIGIT ZERO
  44. DIGIT_RANGE_TEST(0x06F0) // 06F0;EXTENDED ARABIC-INDIC DIGIT ZERO
  45. DIGIT_RANGE_TEST(0x0966) // 0966;DEVANAGARI DIGIT ZERO
  46. DIGIT_RANGE_TEST(0x09E6) // 09E6;BENGALI DIGIT ZERO
  47. DIGIT_RANGE_TEST(0x0A66) // 0A66;GURMUKHI DIGIT ZERO
  48. DIGIT_RANGE_TEST(0x0AE6) // 0AE6;GUJARATI DIGIT ZERO
  49. DIGIT_RANGE_TEST(0x0B66) // 0B66;ORIYA DIGIT ZERO
  50. DIGIT_RANGE_TEST(0x0C66) // 0C66;TELUGU DIGIT ZERO
  51. DIGIT_RANGE_TEST(0x0CE6) // 0CE6;KANNADA DIGIT ZERO
  52. DIGIT_RANGE_TEST(0x0D66) // 0D66;MALAYALAM DIGIT ZERO
  53. DIGIT_RANGE_TEST(0x0E50) // 0E50;THAI DIGIT ZERO
  54. DIGIT_RANGE_TEST(0x0ED0) // 0ED0;LAO DIGIT ZERO
  55. DIGIT_RANGE_TEST(0x0F20) // 0F20;TIBETAN DIGIT ZERO
  56. DIGIT_RANGE_TEST(0x1040) // 1040;MYANMAR DIGIT ZERO
  57. DIGIT_RANGE_TEST(0x17E0) // 17E0;KHMER DIGIT ZERO
  58. DIGIT_RANGE_TEST(0x1810) // 1810;MONGOLIAN DIGIT ZERO
  59. return -1;
  60. }
  61. #undef DIGIT_RANGE_TEST
  62. // FF10;FULLWIDTH DIGIT ZERO
  63. if (ch < 0xFF10 + 10)
  64. {
  65. return ch - 0xFF10;
  66. }
  67. return -1;
  68. }