/home/ntakagi/work/STLport-5.1.5/src/num_get.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 #include "stlport_prefix.h"
00019 
00020 #include <locale>
00021 #include <istream>
00022 #include <algorithm>
00023 
00024 _STLP_BEGIN_NAMESPACE
00025 _STLP_MOVE_TO_PRIV_NAMESPACE
00026 
00027 // __valid_grouping compares two strings, one representing the
00028 // group sizes encountered when reading an integer, and the other
00029 // representing the valid group sizes as returned by the numpunct
00030 // grouping() member function.  Both are interpreted right-to-left.
00031 // The grouping string is treated as if it were extended indefinitely
00032 // with its last value.  For a grouping to be valid, each term in
00033 // the first string must be equal to the corresponding term in the
00034 // second, except for the last, which must be less than or equal.
00035 
00036 // boris : this takes reversed first string !
00037 bool  _STLP_CALL
00038 __valid_grouping(const char * first1, const char * last1,
00039                  const char * first2, const char * last2) {
00040   if (first1 == last1 || first2 == last2) return true;
00041 
00042   --last1; --last2;
00043 
00044   while (first1 != last1) {
00045     if (*last1 != *first2)
00046       return false;
00047     --last1;
00048     if (first2 != last2) ++first2;
00049   }
00050 
00051   return *last1 <= *first2;
00052 }
00053 
00054 _STLP_DECLSPEC unsigned char _STLP_CALL __digit_val_table(unsigned __index) {
00055   static const unsigned char __val_table[128] = {
00056     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
00057     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
00058     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
00059     0, 1, 2, 3, 4, 5, 6, 7, 8, 9,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
00060     0xFF,10,11,12,13,14,15,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
00061     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
00062     0xFF,10,11,12,13,14,15,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
00063     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
00064   };
00065 
00066   return __val_table[__index];
00067 }
00068 
00069 _STLP_DECLSPEC const char* _STLP_CALL __narrow_atoms()
00070 { return "+-0xX"; }
00071 
00072 // index is actually a char
00073 
00074 #if !defined (_STLP_NO_WCHAR_T)
00075 
00076 // Similar, except return the character itself instead of the numeric
00077 // value.  Used for floating-point input.
00078 bool _STLP_CALL __get_fdigit(wchar_t& c, const wchar_t* digits) {
00079   const wchar_t* p = find(digits, digits + 10, c);
00080   if (p != digits + 10) {
00081     c = (char)('0' + (p - digits));
00082     return true;
00083   }
00084   else
00085     return false;
00086 }
00087 
00088 bool _STLP_CALL __get_fdigit_or_sep(wchar_t& c, wchar_t sep,
00089                                     const wchar_t * digits) {
00090   if (c == sep) {
00091     c = (char)',';
00092     return true;
00093   }
00094   else
00095     return __get_fdigit(c, digits);
00096 }
00097 
00098 #endif
00099 
00100 _STLP_MOVE_TO_STD_NAMESPACE
00101 
00102 #if !defined(_STLP_NO_FORCE_INSTANTIATE)
00103 //----------------------------------------------------------------------
00104 // Force instantiation of of num_get<>
00105 template class _STLP_CLASS_DECLSPEC istreambuf_iterator<char, char_traits<char> >;
00106 // template class num_get<char, const char*>;
00107 template class num_get<char, istreambuf_iterator<char, char_traits<char> > >;
00108 
00109 #  if !defined (_STLP_NO_WCHAR_T)
00110 template class _STLP_CLASS_DECLSPEC  istreambuf_iterator<wchar_t, char_traits<wchar_t> >;
00111 template class num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
00112 // template class num_get<wchar_t, const wchar_t*>;
00113 #  endif
00114 #endif
00115 
00116 _STLP_END_NAMESPACE
00117 
00118 // Local Variables:
00119 // mode:C++
00120 // End:



Generated on Mon Mar 10 15:32:17 2008 by  doxygen 1.5.1