num_get.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 1999
  3. * Silicon Graphics Computer Systems, Inc.
  4. *
  5. * Copyright (c) 1999
  6. * Boris Fomitchev
  7. *
  8. * This material is provided "as is", with absolutely no warranty expressed
  9. * or implied. Any use is at your own risk.
  10. *
  11. * Permission to use or copy this software for any purpose is hereby granted
  12. * without fee, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. *
  17. */
  18. #include "stlport_prefix.h"
  19. #include <locale>
  20. #include <istream>
  21. #include <algorithm>
  22. _STLP_BEGIN_NAMESPACE
  23. _STLP_MOVE_TO_PRIV_NAMESPACE
  24. // __valid_grouping compares two strings, one representing the
  25. // group sizes encountered when reading an integer, and the other
  26. // representing the valid group sizes as returned by the numpunct
  27. // grouping() member function. Both are interpreted right-to-left.
  28. // The grouping string is treated as if it were extended indefinitely
  29. // with its last value. For a grouping to be valid, each term in
  30. // the first string must be equal to the corresponding term in the
  31. // second, except for the last, which must be less than or equal.
  32. // boris : this takes reversed first string !
  33. bool _STLP_CALL
  34. __valid_grouping(const char * first1, const char * last1,
  35. const char * first2, const char * last2) {
  36. if (first1 == last1 || first2 == last2) return true;
  37. --last1; --last2;
  38. while (first1 != last1) {
  39. if (*last1 != *first2)
  40. return false;
  41. --last1;
  42. if (first2 != last2) ++first2;
  43. }
  44. return *last1 <= *first2;
  45. }
  46. _STLP_DECLSPEC unsigned char _STLP_CALL __digit_val_table(unsigned __index) {
  47. static const unsigned char __val_table[128] = {
  48. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  49. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  50. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  51. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  52. 0xFF,10,11,12,13,14,15,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  53. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  54. 0xFF,10,11,12,13,14,15,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  55. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  56. };
  57. return __val_table[__index];
  58. }
  59. _STLP_DECLSPEC const char* _STLP_CALL __narrow_atoms()
  60. { return "+-0xX"; }
  61. // index is actually a char
  62. #if !defined (_STLP_NO_WCHAR_T)
  63. // Similar, except return the character itself instead of the numeric
  64. // value. Used for floating-point input.
  65. bool _STLP_CALL __get_fdigit(wchar_t& c, const wchar_t* digits) {
  66. const wchar_t* p = find(digits, digits + 10, c);
  67. if (p != digits + 10) {
  68. c = (char)('0' + (p - digits));
  69. return true;
  70. }
  71. else
  72. return false;
  73. }
  74. bool _STLP_CALL __get_fdigit_or_sep(wchar_t& c, wchar_t sep,
  75. const wchar_t * digits) {
  76. if (c == sep) {
  77. c = (char)',';
  78. return true;
  79. }
  80. else
  81. return __get_fdigit(c, digits);
  82. }
  83. #endif
  84. _STLP_MOVE_TO_STD_NAMESPACE
  85. #if !defined(_STLP_NO_FORCE_INSTANTIATE)
  86. //----------------------------------------------------------------------
  87. // Force instantiation of num_get<>
  88. template class _STLP_CLASS_DECLSPEC istreambuf_iterator<char, char_traits<char> >;
  89. // template class num_get<char, const char*>;
  90. template class num_get<char, istreambuf_iterator<char, char_traits<char> > >;
  91. # if !defined (_STLP_NO_WCHAR_T)
  92. template class _STLP_CLASS_DECLSPEC istreambuf_iterator<wchar_t, char_traits<wchar_t> >;
  93. template class num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
  94. // template class num_get<wchar_t, const wchar_t*>;
  95. # endif
  96. #endif
  97. _STLP_END_NAMESPACE
  98. // Local Variables:
  99. // mode:C++
  100. // End: