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
20#include <locale>
21#include <istream>
22#include <algorithm>
23
24_STLP_BEGIN_NAMESPACE
25_STLP_MOVE_TO_PRIV_NAMESPACE
26
27// __valid_grouping compares two strings, one representing the
28// group sizes encountered when reading an integer, and the other
29// representing the valid group sizes as returned by the numpunct
30// grouping() member function.  Both are interpreted right-to-left.
31// The grouping string is treated as if it were extended indefinitely
32// with its last value.  For a grouping to be valid, each term in
33// the first string must be equal to the corresponding term in the
34// second, except for the last, which must be less than or equal.
35
36// boris : this takes reversed first string !
37bool  _STLP_CALL
38__valid_grouping(const char * first1, const char * last1,
39                 const char * first2, const char * last2) {
40  if (first1 == last1 || first2 == last2) return true;
41
42  --last1; --last2;
43
44  while (first1 != last1) {
45    if (*last1 != *first2)
46      return false;
47    --last1;
48    if (first2 != last2) ++first2;
49  }
50
51  return *last1 <= *first2;
52}
53
54_STLP_DECLSPEC unsigned char _STLP_CALL __digit_val_table(unsigned __index) {
55  static const unsigned char __val_table[128] = {
56    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
57    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
58    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
59    0, 1, 2, 3, 4, 5, 6, 7, 8, 9,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
60    0xFF,10,11,12,13,14,15,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
61    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
62    0xFF,10,11,12,13,14,15,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
63    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
64  };
65
66  return __val_table[__index];
67}
68
69_STLP_DECLSPEC const char* _STLP_CALL __narrow_atoms()
70{ return "+-0xX"; }
71
72// index is actually a char
73
74#if !defined (_STLP_NO_WCHAR_T)
75
76// Similar, except return the character itself instead of the numeric
77// value.  Used for floating-point input.
78bool _STLP_CALL __get_fdigit(wchar_t& c, const wchar_t* digits) {
79  const wchar_t* p = find(digits, digits + 10, c);
80  if (p != digits + 10) {
81    c = (char)('0' + (p - digits));
82    return true;
83  }
84  else
85    return false;
86}
87
88bool _STLP_CALL __get_fdigit_or_sep(wchar_t& c, wchar_t sep,
89                                    const wchar_t * digits) {
90  if (c == sep) {
91    c = (char)',';
92    return true;
93  }
94  else
95    return __get_fdigit(c, digits);
96}
97
98#endif
99
100_STLP_MOVE_TO_STD_NAMESPACE
101
102#if !defined(_STLP_NO_FORCE_INSTANTIATE)
103//----------------------------------------------------------------------
104// Force instantiation of num_get<>
105template class _STLP_CLASS_DECLSPEC istreambuf_iterator<char, char_traits<char> >;
106// template class num_get<char, const char*>;
107template class num_get<char, istreambuf_iterator<char, char_traits<char> > >;
108
109#  if !defined (_STLP_NO_WCHAR_T)
110template class _STLP_CLASS_DECLSPEC  istreambuf_iterator<wchar_t, char_traits<wchar_t> >;
111template class num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
112// template class num_get<wchar_t, const wchar_t*>;
113#  endif
114#endif
115
116_STLP_END_NAMESPACE
117
118// Local Variables:
119// mode:C++
120// End:
121