00001 // Locale support -*- C++ -*- 00002 00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 00004 // 2006, 2007, 2008, 2009, 2010 00005 // Free Software Foundation, Inc. 00006 // 00007 // This file is part of the GNU ISO C++ Library. This library is free 00008 // software; you can redistribute it and/or modify it under the 00009 // terms of the GNU General Public License as published by the 00010 // Free Software Foundation; either version 3, or (at your option) 00011 // any later version. 00012 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 00018 // Under Section 7 of GPL version 3, you are granted additional 00019 // permissions described in the GCC Runtime Library Exception, version 00020 // 3.1, as published by the Free Software Foundation. 00021 00022 // You should have received a copy of the GNU General Public License and 00023 // a copy of the GCC Runtime Library Exception along with this program; 00024 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00025 // <http://www.gnu.org/licenses/>. 00026 00027 /** @file locale_facets.h 00028 * This is an internal header file, included by other library headers. 00029 * You should not attempt to use it directly. 00030 */ 00031 00032 // 00033 // ISO C++ 14882: 22.1 Locales 00034 // 00035 00036 #ifndef _LOCALE_FACETS_H 00037 #define _LOCALE_FACETS_H 1 00038 00039 #pragma GCC system_header 00040 00041 #include <cwctype> // For wctype_t 00042 #include <cctype> 00043 #include <bits/ctype_base.h> 00044 #include <iosfwd> 00045 #include <bits/ios_base.h> // For ios_base, ios_base::iostate 00046 #include <streambuf> 00047 #include <bits/cpp_type_traits.h> 00048 #include <ext/type_traits.h> 00049 #include <ext/numeric_traits.h> 00050 #include <bits/streambuf_iterator.h> 00051 00052 _GLIBCXX_BEGIN_NAMESPACE(std) 00053 00054 // NB: Don't instantiate required wchar_t facets if no wchar_t support. 00055 #ifdef _GLIBCXX_USE_WCHAR_T 00056 # define _GLIBCXX_NUM_FACETS 28 00057 #else 00058 # define _GLIBCXX_NUM_FACETS 14 00059 #endif 00060 00061 // Convert string to numeric value of type _Tp and store results. 00062 // NB: This is specialized for all required types, there is no 00063 // generic definition. 00064 template<typename _Tp> 00065 void 00066 __convert_to_v(const char*, _Tp&, ios_base::iostate&, 00067 const __c_locale&) throw(); 00068 00069 // Explicit specializations for required types. 00070 template<> 00071 void 00072 __convert_to_v(const char*, float&, ios_base::iostate&, 00073 const __c_locale&) throw(); 00074 00075 template<> 00076 void 00077 __convert_to_v(const char*, double&, ios_base::iostate&, 00078 const __c_locale&) throw(); 00079 00080 template<> 00081 void 00082 __convert_to_v(const char*, long double&, ios_base::iostate&, 00083 const __c_locale&) throw(); 00084 00085 // NB: __pad is a struct, rather than a function, so it can be 00086 // partially-specialized. 00087 template<typename _CharT, typename _Traits> 00088 struct __pad 00089 { 00090 static void 00091 _S_pad(ios_base& __io, _CharT __fill, _CharT* __news, 00092 const _CharT* __olds, streamsize __newlen, streamsize __oldlen); 00093 }; 00094 00095 // Used by both numeric and monetary facets. 00096 // Inserts "group separator" characters into an array of characters. 00097 // It's recursive, one iteration per group. It moves the characters 00098 // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this 00099 // only with __gsize != 0. 00100 template<typename _CharT> 00101 _CharT* 00102 __add_grouping(_CharT* __s, _CharT __sep, 00103 const char* __gbeg, size_t __gsize, 00104 const _CharT* __first, const _CharT* __last); 00105 00106 // This template permits specializing facet output code for 00107 // ostreambuf_iterator. For ostreambuf_iterator, sputn is 00108 // significantly more efficient than incrementing iterators. 00109 template<typename _CharT> 00110 inline 00111 ostreambuf_iterator<_CharT> 00112 __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len) 00113 { 00114 __s._M_put(__ws, __len); 00115 return __s; 00116 } 00117 00118 // This is the unspecialized form of the template. 00119 template<typename _CharT, typename _OutIter> 00120 inline 00121 _OutIter 00122 __write(_OutIter __s, const _CharT* __ws, int __len) 00123 { 00124 for (int __j = 0; __j < __len; __j++, ++__s) 00125 *__s = __ws[__j]; 00126 return __s; 00127 } 00128 00129 00130 // 22.2.1.1 Template class ctype 00131 // Include host and configuration specific ctype enums for ctype_base. 00132 00133 /** 00134 * @brief Common base for ctype facet 00135 * 00136 * This template class provides implementations of the public functions 00137 * that forward to the protected virtual functions. 00138 * 00139 * This template also provides abstract stubs for the protected virtual 00140 * functions. 00141 */ 00142 template<typename _CharT> 00143 class __ctype_abstract_base : public locale::facet, public ctype_base 00144 { 00145 public: 00146 // Types: 00147 /// Typedef for the template parameter 00148 typedef _CharT char_type; 00149 00150 /** 00151 * @brief Test char_type classification. 00152 * 00153 * This function finds a mask M for @a c and compares it to mask @a m. 00154 * It does so by returning the value of ctype<char_type>::do_is(). 00155 * 00156 * @param c The char_type to compare the mask of. 00157 * @param m The mask to compare against. 00158 * @return (M & m) != 0. 00159 */ 00160 bool 00161 is(mask __m, char_type __c) const 00162 { return this->do_is(__m, __c); } 00163 00164 /** 00165 * @brief Return a mask array. 00166 * 00167 * This function finds the mask for each char_type in the range [lo,hi) 00168 * and successively writes it to vec. vec must have as many elements 00169 * as the char array. It does so by returning the value of 00170 * ctype<char_type>::do_is(). 00171 * 00172 * @param lo Pointer to start of range. 00173 * @param hi Pointer to end of range. 00174 * @param vec Pointer to an array of mask storage. 00175 * @return @a hi. 00176 */ 00177 const char_type* 00178 is(const char_type *__lo, const char_type *__hi, mask *__vec) const 00179 { return this->do_is(__lo, __hi, __vec); } 00180 00181 /** 00182 * @brief Find char_type matching a mask 00183 * 00184 * This function searches for and returns the first char_type c in 00185 * [lo,hi) for which is(m,c) is true. It does so by returning 00186 * ctype<char_type>::do_scan_is(). 00187 * 00188 * @param m The mask to compare against. 00189 * @param lo Pointer to start of range. 00190 * @param hi Pointer to end of range. 00191 * @return Pointer to matching char_type if found, else @a hi. 00192 */ 00193 const char_type* 00194 scan_is(mask __m, const char_type* __lo, const char_type* __hi) const 00195 { return this->do_scan_is(__m, __lo, __hi); } 00196 00197 /** 00198 * @brief Find char_type not matching a mask 00199 * 00200 * This function searches for and returns the first char_type c in 00201 * [lo,hi) for which is(m,c) is false. It does so by returning 00202 * ctype<char_type>::do_scan_not(). 00203 * 00204 * @param m The mask to compare against. 00205 * @param lo Pointer to first char in range. 00206 * @param hi Pointer to end of range. 00207 * @return Pointer to non-matching char if found, else @a hi. 00208 */ 00209 const char_type* 00210 scan_not(mask __m, const char_type* __lo, const char_type* __hi) const 00211 { return this->do_scan_not(__m, __lo, __hi); } 00212 00213 /** 00214 * @brief Convert to uppercase. 00215 * 00216 * This function converts the argument to uppercase if possible. 00217 * If not possible (for example, '2'), returns the argument. It does 00218 * so by returning ctype<char_type>::do_toupper(). 00219 * 00220 * @param c The char_type to convert. 00221 * @return The uppercase char_type if convertible, else @a c. 00222 */ 00223 char_type 00224 toupper(char_type __c) const 00225 { return this->do_toupper(__c); } 00226 00227 /** 00228 * @brief Convert array to uppercase. 00229 * 00230 * This function converts each char_type in the range [lo,hi) to 00231 * uppercase if possible. Other elements remain untouched. It does so 00232 * by returning ctype<char_type>:: do_toupper(lo, hi). 00233 * 00234 * @param lo Pointer to start of range. 00235 * @param hi Pointer to end of range. 00236 * @return @a hi. 00237 */ 00238 const char_type* 00239 toupper(char_type *__lo, const char_type* __hi) const 00240 { return this->do_toupper(__lo, __hi); } 00241 00242 /** 00243 * @brief Convert to lowercase. 00244 * 00245 * This function converts the argument to lowercase if possible. If 00246 * not possible (for example, '2'), returns the argument. It does so 00247 * by returning ctype<char_type>::do_tolower(c). 00248 * 00249 * @param c The char_type to convert. 00250 * @return The lowercase char_type if convertible, else @a c. 00251 */ 00252 char_type 00253 tolower(char_type __c) const 00254 { return this->do_tolower(__c); } 00255 00256 /** 00257 * @brief Convert array to lowercase. 00258 * 00259 * This function converts each char_type in the range [lo,hi) to 00260 * lowercase if possible. Other elements remain untouched. It does so 00261 * by returning ctype<char_type>:: do_tolower(lo, hi). 00262 * 00263 * @param lo Pointer to start of range. 00264 * @param hi Pointer to end of range. 00265 * @return @a hi. 00266 */ 00267 const char_type* 00268 tolower(char_type* __lo, const char_type* __hi) const 00269 { return this->do_tolower(__lo, __hi); } 00270 00271 /** 00272 * @brief Widen char to char_type 00273 * 00274 * This function converts the char argument to char_type using the 00275 * simplest reasonable transformation. It does so by returning 00276 * ctype<char_type>::do_widen(c). 00277 * 00278 * Note: this is not what you want for codepage conversions. See 00279 * codecvt for that. 00280 * 00281 * @param c The char to convert. 00282 * @return The converted char_type. 00283 */ 00284 char_type 00285 widen(char __c) const 00286 { return this->do_widen(__c); } 00287 00288 /** 00289 * @brief Widen array to char_type 00290 * 00291 * This function converts each char in the input to char_type using the 00292 * simplest reasonable transformation. It does so by returning 00293 * ctype<char_type>::do_widen(c). 00294 * 00295 * Note: this is not what you want for codepage conversions. See 00296 * codecvt for that. 00297 * 00298 * @param lo Pointer to start of range. 00299 * @param hi Pointer to end of range. 00300 * @param to Pointer to the destination array. 00301 * @return @a hi. 00302 */ 00303 const char* 00304 widen(const char* __lo, const char* __hi, char_type* __to) const 00305 { return this->do_widen(__lo, __hi, __to); } 00306 00307 /** 00308 * @brief Narrow char_type to char 00309 * 00310 * This function converts the char_type to char using the simplest 00311 * reasonable transformation. If the conversion fails, dfault is 00312 * returned instead. It does so by returning 00313 * ctype<char_type>::do_narrow(c). 00314 * 00315 * Note: this is not what you want for codepage conversions. See 00316 * codecvt for that. 00317 * 00318 * @param c The char_type to convert. 00319 * @param dfault Char to return if conversion fails. 00320 * @return The converted char. 00321 */ 00322 char 00323 narrow(char_type __c, char __dfault) const 00324 { return this->do_narrow(__c, __dfault); } 00325 00326 /** 00327 * @brief Narrow array to char array 00328 * 00329 * This function converts each char_type in the input to char using the 00330 * simplest reasonable transformation and writes the results to the 00331 * destination array. For any char_type in the input that cannot be 00332 * converted, @a dfault is used instead. It does so by returning 00333 * ctype<char_type>::do_narrow(lo, hi, dfault, to). 00334 * 00335 * Note: this is not what you want for codepage conversions. See 00336 * codecvt for that. 00337 * 00338 * @param lo Pointer to start of range. 00339 * @param hi Pointer to end of range. 00340 * @param dfault Char to use if conversion fails. 00341 * @param to Pointer to the destination array. 00342 * @return @a hi. 00343 */ 00344 const char_type* 00345 narrow(const char_type* __lo, const char_type* __hi, 00346 char __dfault, char *__to) const 00347 { return this->do_narrow(__lo, __hi, __dfault, __to); } 00348 00349 protected: 00350 explicit 00351 __ctype_abstract_base(size_t __refs = 0): facet(__refs) { } 00352 00353 virtual 00354 ~__ctype_abstract_base() { } 00355 00356 /** 00357 * @brief Test char_type classification. 00358 * 00359 * This function finds a mask M for @a c and compares it to mask @a m. 00360 * 00361 * do_is() is a hook for a derived facet to change the behavior of 00362 * classifying. do_is() must always return the same result for the 00363 * same input. 00364 * 00365 * @param c The char_type to find the mask of. 00366 * @param m The mask to compare against. 00367 * @return (M & m) != 0. 00368 */ 00369 virtual bool 00370 do_is(mask __m, char_type __c) const = 0; 00371 00372 /** 00373 * @brief Return a mask array. 00374 * 00375 * This function finds the mask for each char_type in the range [lo,hi) 00376 * and successively writes it to vec. vec must have as many elements 00377 * as the input. 00378 * 00379 * do_is() is a hook for a derived facet to change the behavior of 00380 * classifying. do_is() must always return the same result for the 00381 * same input. 00382 * 00383 * @param lo Pointer to start of range. 00384 * @param hi Pointer to end of range. 00385 * @param vec Pointer to an array of mask storage. 00386 * @return @a hi. 00387 */ 00388 virtual const char_type* 00389 do_is(const char_type* __lo, const char_type* __hi, 00390 mask* __vec) const = 0; 00391 00392 /** 00393 * @brief Find char_type matching mask 00394 * 00395 * This function searches for and returns the first char_type c in 00396 * [lo,hi) for which is(m,c) is true. 00397 * 00398 * do_scan_is() is a hook for a derived facet to change the behavior of 00399 * match searching. do_is() must always return the same result for the 00400 * same input. 00401 * 00402 * @param m The mask to compare against. 00403 * @param lo Pointer to start of range. 00404 * @param hi Pointer to end of range. 00405 * @return Pointer to a matching char_type if found, else @a hi. 00406 */ 00407 virtual const char_type* 00408 do_scan_is(mask __m, const char_type* __lo, 00409 const char_type* __hi) const = 0; 00410 00411 /** 00412 * @brief Find char_type not matching mask 00413 * 00414 * This function searches for and returns a pointer to the first 00415 * char_type c of [lo,hi) for which is(m,c) is false. 00416 * 00417 * do_scan_is() is a hook for a derived facet to change the behavior of 00418 * match searching. do_is() must always return the same result for the 00419 * same input. 00420 * 00421 * @param m The mask to compare against. 00422 * @param lo Pointer to start of range. 00423 * @param hi Pointer to end of range. 00424 * @return Pointer to a non-matching char_type if found, else @a hi. 00425 */ 00426 virtual const char_type* 00427 do_scan_not(mask __m, const char_type* __lo, 00428 const char_type* __hi) const = 0; 00429 00430 /** 00431 * @brief Convert to uppercase. 00432 * 00433 * This virtual function converts the char_type argument to uppercase 00434 * if possible. If not possible (for example, '2'), returns the 00435 * argument. 00436 * 00437 * do_toupper() is a hook for a derived facet to change the behavior of 00438 * uppercasing. do_toupper() must always return the same result for 00439 * the same input. 00440 * 00441 * @param c The char_type to convert. 00442 * @return The uppercase char_type if convertible, else @a c. 00443 */ 00444 virtual char_type 00445 do_toupper(char_type) const = 0; 00446 00447 /** 00448 * @brief Convert array to uppercase. 00449 * 00450 * This virtual function converts each char_type in the range [lo,hi) 00451 * to uppercase if possible. Other elements remain untouched. 00452 * 00453 * do_toupper() is a hook for a derived facet to change the behavior of 00454 * uppercasing. do_toupper() must always return the same result for 00455 * the same input. 00456 * 00457 * @param lo Pointer to start of range. 00458 * @param hi Pointer to end of range. 00459 * @return @a hi. 00460 */ 00461 virtual const char_type* 00462 do_toupper(char_type* __lo, const char_type* __hi) const = 0; 00463 00464 /** 00465 * @brief Convert to lowercase. 00466 * 00467 * This virtual function converts the argument to lowercase if 00468 * possible. If not possible (for example, '2'), returns the argument. 00469 * 00470 * do_tolower() is a hook for a derived facet to change the behavior of 00471 * lowercasing. do_tolower() must always return the same result for 00472 * the same input. 00473 * 00474 * @param c The char_type to convert. 00475 * @return The lowercase char_type if convertible, else @a c. 00476 */ 00477 virtual char_type 00478 do_tolower(char_type) const = 0; 00479 00480 /** 00481 * @brief Convert array to lowercase. 00482 * 00483 * This virtual function converts each char_type in the range [lo,hi) 00484 * to lowercase if possible. Other elements remain untouched. 00485 * 00486 * do_tolower() is a hook for a derived facet to change the behavior of 00487 * lowercasing. do_tolower() must always return the same result for 00488 * the same input. 00489 * 00490 * @param lo Pointer to start of range. 00491 * @param hi Pointer to end of range. 00492 * @return @a hi. 00493 */ 00494 virtual const char_type* 00495 do_tolower(char_type* __lo, const char_type* __hi) const = 0; 00496 00497 /** 00498 * @brief Widen char 00499 * 00500 * This virtual function converts the char to char_type using the 00501 * simplest reasonable transformation. 00502 * 00503 * do_widen() is a hook for a derived facet to change the behavior of 00504 * widening. do_widen() must always return the same result for the 00505 * same input. 00506 * 00507 * Note: this is not what you want for codepage conversions. See 00508 * codecvt for that. 00509 * 00510 * @param c The char to convert. 00511 * @return The converted char_type 00512 */ 00513 virtual char_type 00514 do_widen(char) const = 0; 00515 00516 /** 00517 * @brief Widen char array 00518 * 00519 * This function converts each char in the input to char_type using the 00520 * simplest reasonable transformation. 00521 * 00522 * do_widen() is a hook for a derived facet to change the behavior of 00523 * widening. do_widen() must always return the same result for the 00524 * same input. 00525 * 00526 * Note: this is not what you want for codepage conversions. See 00527 * codecvt for that. 00528 * 00529 * @param lo Pointer to start range. 00530 * @param hi Pointer to end of range. 00531 * @param to Pointer to the destination array. 00532 * @return @a hi. 00533 */ 00534 virtual const char* 00535 do_widen(const char* __lo, const char* __hi, 00536 char_type* __dest) const = 0; 00537 00538 /** 00539 * @brief Narrow char_type to char 00540 * 00541 * This virtual function converts the argument to char using the 00542 * simplest reasonable transformation. If the conversion fails, dfault 00543 * is returned instead. 00544 * 00545 * do_narrow() is a hook for a derived facet to change the behavior of 00546 * narrowing. do_narrow() must always return the same result for the 00547 * same input. 00548 * 00549 * Note: this is not what you want for codepage conversions. See 00550 * codecvt for that. 00551 * 00552 * @param c The char_type to convert. 00553 * @param dfault Char to return if conversion fails. 00554 * @return The converted char. 00555 */ 00556 virtual char 00557 do_narrow(char_type, char __dfault) const = 0; 00558 00559 /** 00560 * @brief Narrow char_type array to char 00561 * 00562 * This virtual function converts each char_type in the range [lo,hi) to 00563 * char using the simplest reasonable transformation and writes the 00564 * results to the destination array. For any element in the input that 00565 * cannot be converted, @a dfault is used instead. 00566 * 00567 * do_narrow() is a hook for a derived facet to change the behavior of 00568 * narrowing. do_narrow() must always return the same result for the 00569 * same input. 00570 * 00571 * Note: this is not what you want for codepage conversions. See 00572 * codecvt for that. 00573 * 00574 * @param lo Pointer to start of range. 00575 * @param hi Pointer to end of range. 00576 * @param dfault Char to use if conversion fails. 00577 * @param to Pointer to the destination array. 00578 * @return @a hi. 00579 */ 00580 virtual const char_type* 00581 do_narrow(const char_type* __lo, const char_type* __hi, 00582 char __dfault, char* __dest) const = 0; 00583 }; 00584 00585 /** 00586 * @brief Primary class template ctype facet. 00587 * @ingroup locales 00588 * 00589 * This template class defines classification and conversion functions for 00590 * character sets. It wraps cctype functionality. Ctype gets used by 00591 * streams for many I/O operations. 00592 * 00593 * This template provides the protected virtual functions the developer 00594 * will have to replace in a derived class or specialization to make a 00595 * working facet. The public functions that access them are defined in 00596 * __ctype_abstract_base, to allow for implementation flexibility. See 00597 * ctype<wchar_t> for an example. The functions are documented in 00598 * __ctype_abstract_base. 00599 * 00600 * Note: implementations are provided for all the protected virtual 00601 * functions, but will likely not be useful. 00602 */ 00603 template<typename _CharT> 00604 class ctype : public __ctype_abstract_base<_CharT> 00605 { 00606 public: 00607 // Types: 00608 typedef _CharT char_type; 00609 typedef typename __ctype_abstract_base<_CharT>::mask mask; 00610 00611 /// The facet id for ctype<char_type> 00612 static locale::id id; 00613 00614 explicit 00615 ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { } 00616 00617 protected: 00618 virtual 00619 ~ctype(); 00620 00621 virtual bool 00622 do_is(mask __m, char_type __c) const; 00623 00624 virtual const char_type* 00625 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const; 00626 00627 virtual const char_type* 00628 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const; 00629 00630 virtual const char_type* 00631 do_scan_not(mask __m, const char_type* __lo, 00632 const char_type* __hi) const; 00633 00634 virtual char_type 00635 do_toupper(char_type __c) const; 00636 00637 virtual const char_type* 00638 do_toupper(char_type* __lo, const char_type* __hi) const; 00639 00640 virtual char_type 00641 do_tolower(char_type __c) const; 00642 00643 virtual const char_type* 00644 do_tolower(char_type* __lo, const char_type* __hi) const; 00645 00646 virtual char_type 00647 do_widen(char __c) const; 00648 00649 virtual const char* 00650 do_widen(const char* __lo, const char* __hi, char_type* __dest) const; 00651 00652 virtual char 00653 do_narrow(char_type, char __dfault) const; 00654 00655 virtual const char_type* 00656 do_narrow(const char_type* __lo, const char_type* __hi, 00657 char __dfault, char* __dest) const; 00658 }; 00659 00660 template<typename _CharT> 00661 locale::id ctype<_CharT>::id; 00662 00663 /** 00664 * @brief The ctype<char> specialization. 00665 * @ingroup locales 00666 * 00667 * This class defines classification and conversion functions for 00668 * the char type. It gets used by char streams for many I/O 00669 * operations. The char specialization provides a number of 00670 * optimizations as well. 00671 */ 00672 template<> 00673 class ctype<char> : public locale::facet, public ctype_base 00674 { 00675 public: 00676 // Types: 00677 /// Typedef for the template parameter char. 00678 typedef char char_type; 00679 00680 protected: 00681 // Data Members: 00682 __c_locale _M_c_locale_ctype; 00683 bool _M_del; 00684 __to_type _M_toupper; 00685 __to_type _M_tolower; 00686 const mask* _M_table; 00687 mutable char _M_widen_ok; 00688 mutable char _M_widen[1 + static_cast<unsigned char>(-1)]; 00689 mutable char _M_narrow[1 + static_cast<unsigned char>(-1)]; 00690 mutable char _M_narrow_ok; // 0 uninitialized, 1 init, 00691 // 2 memcpy can't be used 00692 00693 public: 00694 /// The facet id for ctype<char> 00695 static locale::id id; 00696 /// The size of the mask table. It is SCHAR_MAX + 1. 00697 static const size_t table_size = 1 + static_cast<unsigned char>(-1); 00698 00699 /** 00700 * @brief Constructor performs initialization. 00701 * 00702 * This is the constructor provided by the standard. 00703 * 00704 * @param table If non-zero, table is used as the per-char mask. 00705 * Else classic_table() is used. 00706 * @param del If true, passes ownership of table to this facet. 00707 * @param refs Passed to the base facet class. 00708 */ 00709 explicit 00710 ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0); 00711 00712 /** 00713 * @brief Constructor performs static initialization. 00714 * 00715 * This constructor is used to construct the initial C locale facet. 00716 * 00717 * @param cloc Handle to C locale data. 00718 * @param table If non-zero, table is used as the per-char mask. 00719 * @param del If true, passes ownership of table to this facet. 00720 * @param refs Passed to the base facet class. 00721 */ 00722 explicit 00723 ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false, 00724 size_t __refs = 0); 00725 00726 /** 00727 * @brief Test char classification. 00728 * 00729 * This function compares the mask table[c] to @a m. 00730 * 00731 * @param c The char to compare the mask of. 00732 * @param m The mask to compare against. 00733 * @return True if m & table[c] is true, false otherwise. 00734 */ 00735 inline bool 00736 is(mask __m, char __c) const; 00737 00738 /** 00739 * @brief Return a mask array. 00740 * 00741 * This function finds the mask for each char in the range [lo, hi) and 00742 * successively writes it to vec. vec must have as many elements as 00743 * the char array. 00744 * 00745 * @param lo Pointer to start of range. 00746 * @param hi Pointer to end of range. 00747 * @param vec Pointer to an array of mask storage. 00748 * @return @a hi. 00749 */ 00750 inline const char* 00751 is(const char* __lo, const char* __hi, mask* __vec) const; 00752 00753 /** 00754 * @brief Find char matching a mask 00755 * 00756 * This function searches for and returns the first char in [lo,hi) for 00757 * which is(m,char) is true. 00758 * 00759 * @param m The mask to compare against. 00760 * @param lo Pointer to start of range. 00761 * @param hi Pointer to end of range. 00762 * @return Pointer to a matching char if found, else @a hi. 00763 */ 00764 inline const char* 00765 scan_is(mask __m, const char* __lo, const char* __hi) const; 00766 00767 /** 00768 * @brief Find char not matching a mask 00769 * 00770 * This function searches for and returns a pointer to the first char 00771 * in [lo,hi) for which is(m,char) is false. 00772 * 00773 * @param m The mask to compare against. 00774 * @param lo Pointer to start of range. 00775 * @param hi Pointer to end of range. 00776 * @return Pointer to a non-matching char if found, else @a hi. 00777 */ 00778 inline const char* 00779 scan_not(mask __m, const char* __lo, const char* __hi) const; 00780 00781 /** 00782 * @brief Convert to uppercase. 00783 * 00784 * This function converts the char argument to uppercase if possible. 00785 * If not possible (for example, '2'), returns the argument. 00786 * 00787 * toupper() acts as if it returns ctype<char>::do_toupper(c). 00788 * do_toupper() must always return the same result for the same input. 00789 * 00790 * @param c The char to convert. 00791 * @return The uppercase char if convertible, else @a c. 00792 */ 00793 char_type 00794 toupper(char_type __c) const 00795 { return this->do_toupper(__c); } 00796 00797 /** 00798 * @brief Convert array to uppercase. 00799 * 00800 * This function converts each char in the range [lo,hi) to uppercase 00801 * if possible. Other chars remain untouched. 00802 * 00803 * toupper() acts as if it returns ctype<char>:: do_toupper(lo, hi). 00804 * do_toupper() must always return the same result for the same input. 00805 * 00806 * @param lo Pointer to first char in range. 00807 * @param hi Pointer to end of range. 00808 * @return @a hi. 00809 */ 00810 const char_type* 00811 toupper(char_type *__lo, const char_type* __hi) const 00812 { return this->do_toupper(__lo, __hi); } 00813 00814 /** 00815 * @brief Convert to lowercase. 00816 * 00817 * This function converts the char argument to lowercase if possible. 00818 * If not possible (for example, '2'), returns the argument. 00819 * 00820 * tolower() acts as if it returns ctype<char>::do_tolower(c). 00821 * do_tolower() must always return the same result for the same input. 00822 * 00823 * @param c The char to convert. 00824 * @return The lowercase char if convertible, else @a c. 00825 */ 00826 char_type 00827 tolower(char_type __c) const 00828 { return this->do_tolower(__c); } 00829 00830 /** 00831 * @brief Convert array to lowercase. 00832 * 00833 * This function converts each char in the range [lo,hi) to lowercase 00834 * if possible. Other chars remain untouched. 00835 * 00836 * tolower() acts as if it returns ctype<char>:: do_tolower(lo, hi). 00837 * do_tolower() must always return the same result for the same input. 00838 * 00839 * @param lo Pointer to first char in range. 00840 * @param hi Pointer to end of range. 00841 * @return @a hi. 00842 */ 00843 const char_type* 00844 tolower(char_type* __lo, const char_type* __hi) const 00845 { return this->do_tolower(__lo, __hi); } 00846 00847 /** 00848 * @brief Widen char 00849 * 00850 * This function converts the char to char_type using the simplest 00851 * reasonable transformation. For an underived ctype<char> facet, the 00852 * argument will be returned unchanged. 00853 * 00854 * This function works as if it returns ctype<char>::do_widen(c). 00855 * do_widen() must always return the same result for the same input. 00856 * 00857 * Note: this is not what you want for codepage conversions. See 00858 * codecvt for that. 00859 * 00860 * @param c The char to convert. 00861 * @return The converted character. 00862 */ 00863 char_type 00864 widen(char __c) const 00865 { 00866 if (_M_widen_ok) 00867 return _M_widen[static_cast<unsigned char>(__c)]; 00868 this->_M_widen_init(); 00869 return this->do_widen(__c); 00870 } 00871 00872 /** 00873 * @brief Widen char array 00874 * 00875 * This function converts each char in the input to char using the 00876 * simplest reasonable transformation. For an underived ctype<char> 00877 * facet, the argument will be copied unchanged. 00878 * 00879 * This function works as if it returns ctype<char>::do_widen(c). 00880 * do_widen() must always return the same result for the same input. 00881 * 00882 * Note: this is not what you want for codepage conversions. See 00883 * codecvt for that. 00884 * 00885 * @param lo Pointer to first char in range. 00886 * @param hi Pointer to end of range. 00887 * @param to Pointer to the destination array. 00888 * @return @a hi. 00889 */ 00890 const char* 00891 widen(const char* __lo, const char* __hi, char_type* __to) const 00892 { 00893 if (_M_widen_ok == 1) 00894 { 00895 __builtin_memcpy(__to, __lo, __hi - __lo); 00896 return __hi; 00897 } 00898 if (!_M_widen_ok) 00899 _M_widen_init(); 00900 return this->do_widen(__lo, __hi, __to); 00901 } 00902 00903 /** 00904 * @brief Narrow char 00905 * 00906 * This function converts the char to char using the simplest 00907 * reasonable transformation. If the conversion fails, dfault is 00908 * returned instead. For an underived ctype<char> facet, @a c 00909 * will be returned unchanged. 00910 * 00911 * This function works as if it returns ctype<char>::do_narrow(c). 00912 * do_narrow() must always return the same result for the same input. 00913 * 00914 * Note: this is not what you want for codepage conversions. See 00915 * codecvt for that. 00916 * 00917 * @param c The char to convert. 00918 * @param dfault Char to return if conversion fails. 00919 * @return The converted character. 00920 */ 00921 char 00922 narrow(char_type __c, char __dfault) const 00923 { 00924 if (_M_narrow[static_cast<unsigned char>(__c)]) 00925 return _M_narrow[static_cast<unsigned char>(__c)]; 00926 const char __t = do_narrow(__c, __dfault); 00927 if (__t != __dfault) 00928 _M_narrow[static_cast<unsigned char>(__c)] = __t; 00929 return __t; 00930 } 00931 00932 /** 00933 * @brief Narrow char array 00934 * 00935 * This function converts each char in the input to char using the 00936 * simplest reasonable transformation and writes the results to the 00937 * destination array. For any char in the input that cannot be 00938 * converted, @a dfault is used instead. For an underived ctype<char> 00939 * facet, the argument will be copied unchanged. 00940 * 00941 * This function works as if it returns ctype<char>::do_narrow(lo, hi, 00942 * dfault, to). do_narrow() must always return the same result for the 00943 * same input. 00944 * 00945 * Note: this is not what you want for codepage conversions. See 00946 * codecvt for that. 00947 * 00948 * @param lo Pointer to start of range. 00949 * @param hi Pointer to end of range. 00950 * @param dfault Char to use if conversion fails. 00951 * @param to Pointer to the destination array. 00952 * @return @a hi. 00953 */ 00954 const char_type* 00955 narrow(const char_type* __lo, const char_type* __hi, 00956 char __dfault, char *__to) const 00957 { 00958 if (__builtin_expect(_M_narrow_ok == 1, true)) 00959 { 00960 __builtin_memcpy(__to, __lo, __hi - __lo); 00961 return __hi; 00962 } 00963 if (!_M_narrow_ok) 00964 _M_narrow_init(); 00965 return this->do_narrow(__lo, __hi, __dfault, __to); 00966 } 00967 00968 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00969 // DR 695. ctype<char>::classic_table() not accessible. 00970 /// Returns a pointer to the mask table provided to the constructor, or 00971 /// the default from classic_table() if none was provided. 00972 const mask* 00973 table() const throw() 00974 { return _M_table; } 00975 00976 /// Returns a pointer to the C locale mask table. 00977 static const mask* 00978 classic_table() throw(); 00979 protected: 00980 00981 /** 00982 * @brief Destructor. 00983 * 00984 * This function deletes table() if @a del was true in the 00985 * constructor. 00986 */ 00987 virtual 00988 ~ctype(); 00989 00990 /** 00991 * @brief Convert to uppercase. 00992 * 00993 * This virtual function converts the char argument to uppercase if 00994 * possible. If not possible (for example, '2'), returns the argument. 00995 * 00996 * do_toupper() is a hook for a derived facet to change the behavior of 00997 * uppercasing. do_toupper() must always return the same result for 00998 * the same input. 00999 * 01000 * @param c The char to convert. 01001 * @return The uppercase char if convertible, else @a c. 01002 */ 01003 virtual char_type 01004 do_toupper(char_type) const; 01005 01006 /** 01007 * @brief Convert array to uppercase. 01008 * 01009 * This virtual function converts each char in the range [lo,hi) to 01010 * uppercase if possible. Other chars remain untouched. 01011 * 01012 * do_toupper() is a hook for a derived facet to change the behavior of 01013 * uppercasing. do_toupper() must always return the same result for 01014 * the same input. 01015 * 01016 * @param lo Pointer to start of range. 01017 * @param hi Pointer to end of range. 01018 * @return @a hi. 01019 */ 01020 virtual const char_type* 01021 do_toupper(char_type* __lo, const char_type* __hi) const; 01022 01023 /** 01024 * @brief Convert to lowercase. 01025 * 01026 * This virtual function converts the char argument to lowercase if 01027 * possible. If not possible (for example, '2'), returns the argument. 01028 * 01029 * do_tolower() is a hook for a derived facet to change the behavior of 01030 * lowercasing. do_tolower() must always return the same result for 01031 * the same input. 01032 * 01033 * @param c The char to convert. 01034 * @return The lowercase char if convertible, else @a c. 01035 */ 01036 virtual char_type 01037 do_tolower(char_type) const; 01038 01039 /** 01040 * @brief Convert array to lowercase. 01041 * 01042 * This virtual function converts each char in the range [lo,hi) to 01043 * lowercase if possible. Other chars remain untouched. 01044 * 01045 * do_tolower() is a hook for a derived facet to change the behavior of 01046 * lowercasing. do_tolower() must always return the same result for 01047 * the same input. 01048 * 01049 * @param lo Pointer to first char in range. 01050 * @param hi Pointer to end of range. 01051 * @return @a hi. 01052 */ 01053 virtual const char_type* 01054 do_tolower(char_type* __lo, const char_type* __hi) const; 01055 01056 /** 01057 * @brief Widen char 01058 * 01059 * This virtual function converts the char to char using the simplest 01060 * reasonable transformation. For an underived ctype<char> facet, the 01061 * argument will be returned unchanged. 01062 * 01063 * do_widen() is a hook for a derived facet to change the behavior of 01064 * widening. do_widen() must always return the same result for the 01065 * same input. 01066 * 01067 * Note: this is not what you want for codepage conversions. See 01068 * codecvt for that. 01069 * 01070 * @param c The char to convert. 01071 * @return The converted character. 01072 */ 01073 virtual char_type 01074 do_widen(char __c) const 01075 { return __c; } 01076 01077 /** 01078 * @brief Widen char array 01079 * 01080 * This function converts each char in the range [lo,hi) to char using 01081 * the simplest reasonable transformation. For an underived 01082 * ctype<char> facet, the argument will be copied unchanged. 01083 * 01084 * do_widen() is a hook for a derived facet to change the behavior of 01085 * widening. do_widen() must always return the same result for the 01086 * same input. 01087 * 01088 * Note: this is not what you want for codepage conversions. See 01089 * codecvt for that. 01090 * 01091 * @param lo Pointer to start of range. 01092 * @param hi Pointer to end of range. 01093 * @param to Pointer to the destination array. 01094 * @return @a hi. 01095 */ 01096 virtual const char* 01097 do_widen(const char* __lo, const char* __hi, char_type* __dest) const 01098 { 01099 __builtin_memcpy(__dest, __lo, __hi - __lo); 01100 return __hi; 01101 } 01102 01103 /** 01104 * @brief Narrow char 01105 * 01106 * This virtual function converts the char to char using the simplest 01107 * reasonable transformation. If the conversion fails, dfault is 01108 * returned instead. For an underived ctype<char> facet, @a c will be 01109 * returned unchanged. 01110 * 01111 * do_narrow() is a hook for a derived facet to change the behavior of 01112 * narrowing. do_narrow() must always return the same result for the 01113 * same input. 01114 * 01115 * Note: this is not what you want for codepage conversions. See 01116 * codecvt for that. 01117 * 01118 * @param c The char to convert. 01119 * @param dfault Char to return if conversion fails. 01120 * @return The converted char. 01121 */ 01122 virtual char 01123 do_narrow(char_type __c, char) const 01124 { return __c; } 01125 01126 /** 01127 * @brief Narrow char array to char array 01128 * 01129 * This virtual function converts each char in the range [lo,hi) to 01130 * char using the simplest reasonable transformation and writes the 01131 * results to the destination array. For any char in the input that 01132 * cannot be converted, @a dfault is used instead. For an underived 01133 * ctype<char> facet, the argument will be copied unchanged. 01134 * 01135 * do_narrow() is a hook for a derived facet to change the behavior of 01136 * narrowing. do_narrow() must always return the same result for the 01137 * same input. 01138 * 01139 * Note: this is not what you want for codepage conversions. See 01140 * codecvt for that. 01141 * 01142 * @param lo Pointer to start of range. 01143 * @param hi Pointer to end of range. 01144 * @param dfault Char to use if conversion fails. 01145 * @param to Pointer to the destination array. 01146 * @return @a hi. 01147 */ 01148 virtual const char_type* 01149 do_narrow(const char_type* __lo, const char_type* __hi, 01150 char, char* __dest) const 01151 { 01152 __builtin_memcpy(__dest, __lo, __hi - __lo); 01153 return __hi; 01154 } 01155 01156 private: 01157 void _M_narrow_init() const; 01158 void _M_widen_init() const; 01159 }; 01160 01161 #ifdef _GLIBCXX_USE_WCHAR_T 01162 /** 01163 * @brief The ctype<wchar_t> specialization. 01164 * @ingroup locales 01165 * 01166 * This class defines classification and conversion functions for the 01167 * wchar_t type. It gets used by wchar_t streams for many I/O operations. 01168 * The wchar_t specialization provides a number of optimizations as well. 01169 * 01170 * ctype<wchar_t> inherits its public methods from 01171 * __ctype_abstract_base<wchar_t>. 01172 */ 01173 template<> 01174 class ctype<wchar_t> : public __ctype_abstract_base<wchar_t> 01175 { 01176 public: 01177 // Types: 01178 /// Typedef for the template parameter wchar_t. 01179 typedef wchar_t char_type; 01180 typedef wctype_t __wmask_type; 01181 01182 protected: 01183 __c_locale _M_c_locale_ctype; 01184 01185 // Pre-computed narrowed and widened chars. 01186 bool _M_narrow_ok; 01187 char _M_narrow[128]; 01188 wint_t _M_widen[1 + static_cast<unsigned char>(-1)]; 01189 01190 // Pre-computed elements for do_is. 01191 mask _M_bit[16]; 01192 __wmask_type _M_wmask[16]; 01193 01194 public: 01195 // Data Members: 01196 /// The facet id for ctype<wchar_t> 01197 static locale::id id; 01198 01199 /** 01200 * @brief Constructor performs initialization. 01201 * 01202 * This is the constructor provided by the standard. 01203 * 01204 * @param refs Passed to the base facet class. 01205 */ 01206 explicit 01207 ctype(size_t __refs = 0); 01208 01209 /** 01210 * @brief Constructor performs static initialization. 01211 * 01212 * This constructor is used to construct the initial C locale facet. 01213 * 01214 * @param cloc Handle to C locale data. 01215 * @param refs Passed to the base facet class. 01216 */ 01217 explicit 01218 ctype(__c_locale __cloc, size_t __refs = 0); 01219 01220 protected: 01221 __wmask_type 01222 _M_convert_to_wmask(const mask __m) const throw(); 01223 01224 /// Destructor 01225 virtual 01226 ~ctype(); 01227 01228 /** 01229 * @brief Test wchar_t classification. 01230 * 01231 * This function finds a mask M for @a c and compares it to mask @a m. 01232 * 01233 * do_is() is a hook for a derived facet to change the behavior of 01234 * classifying. do_is() must always return the same result for the 01235 * same input. 01236 * 01237 * @param c The wchar_t to find the mask of. 01238 * @param m The mask to compare against. 01239 * @return (M & m) != 0. 01240 */ 01241 virtual bool 01242 do_is(mask __m, char_type __c) const; 01243 01244 /** 01245 * @brief Return a mask array. 01246 * 01247 * This function finds the mask for each wchar_t in the range [lo,hi) 01248 * and successively writes it to vec. vec must have as many elements 01249 * as the input. 01250 * 01251 * do_is() is a hook for a derived facet to change the behavior of 01252 * classifying. do_is() must always return the same result for the 01253 * same input. 01254 * 01255 * @param lo Pointer to start of range. 01256 * @param hi Pointer to end of range. 01257 * @param vec Pointer to an array of mask storage. 01258 * @return @a hi. 01259 */ 01260 virtual const char_type* 01261 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const; 01262 01263 /** 01264 * @brief Find wchar_t matching mask 01265 * 01266 * This function searches for and returns the first wchar_t c in 01267 * [lo,hi) for which is(m,c) is true. 01268 * 01269 * do_scan_is() is a hook for a derived facet to change the behavior of 01270 * match searching. do_is() must always return the same result for the 01271 * same input. 01272 * 01273 * @param m The mask to compare against. 01274 * @param lo Pointer to start of range. 01275 * @param hi Pointer to end of range. 01276 * @return Pointer to a matching wchar_t if found, else @a hi. 01277 */ 01278 virtual const char_type* 01279 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const; 01280 01281 /** 01282 * @brief Find wchar_t not matching mask 01283 * 01284 * This function searches for and returns a pointer to the first 01285 * wchar_t c of [lo,hi) for which is(m,c) is false. 01286 * 01287 * do_scan_is() is a hook for a derived facet to change the behavior of 01288 * match searching. do_is() must always return the same result for the 01289 * same input. 01290 * 01291 * @param m The mask to compare against. 01292 * @param lo Pointer to start of range. 01293 * @param hi Pointer to end of range. 01294 * @return Pointer to a non-matching wchar_t if found, else @a hi. 01295 */ 01296 virtual const char_type* 01297 do_scan_not(mask __m, const char_type* __lo, 01298 const char_type* __hi) const; 01299 01300 /** 01301 * @brief Convert to uppercase. 01302 * 01303 * This virtual function converts the wchar_t argument to uppercase if 01304 * possible. If not possible (for example, '2'), returns the argument. 01305 * 01306 * do_toupper() is a hook for a derived facet to change the behavior of 01307 * uppercasing. do_toupper() must always return the same result for 01308 * the same input. 01309 * 01310 * @param c The wchar_t to convert. 01311 * @return The uppercase wchar_t if convertible, else @a c. 01312 */ 01313 virtual char_type 01314 do_toupper(char_type) const; 01315 01316 /** 01317 * @brief Convert array to uppercase. 01318 * 01319 * This virtual function converts each wchar_t in the range [lo,hi) to 01320 * uppercase if possible. Other elements remain untouched. 01321 * 01322 * do_toupper() is a hook for a derived facet to change the behavior of 01323 * uppercasing. do_toupper() must always return the same result for 01324 * the same input. 01325 * 01326 * @param lo Pointer to start of range. 01327 * @param hi Pointer to end of range. 01328 * @return @a hi. 01329 */ 01330 virtual const char_type* 01331 do_toupper(char_type* __lo, const char_type* __hi) const; 01332 01333 /** 01334 * @brief Convert to lowercase. 01335 * 01336 * This virtual function converts the argument to lowercase if 01337 * possible. If not possible (for example, '2'), returns the argument. 01338 * 01339 * do_tolower() is a hook for a derived facet to change the behavior of 01340 * lowercasing. do_tolower() must always return the same result for 01341 * the same input. 01342 * 01343 * @param c The wchar_t to convert. 01344 * @return The lowercase wchar_t if convertible, else @a c. 01345 */ 01346 virtual char_type 01347 do_tolower(char_type) const; 01348 01349 /** 01350 * @brief Convert array to lowercase. 01351 * 01352 * This virtual function converts each wchar_t in the range [lo,hi) to 01353 * lowercase if possible. Other elements remain untouched. 01354 * 01355 * do_tolower() is a hook for a derived facet to change the behavior of 01356 * lowercasing. do_tolower() must always return the same result for 01357 * the same input. 01358 * 01359 * @param lo Pointer to start of range. 01360 * @param hi Pointer to end of range. 01361 * @return @a hi. 01362 */ 01363 virtual const char_type* 01364 do_tolower(char_type* __lo, const char_type* __hi) const; 01365 01366 /** 01367 * @brief Widen char to wchar_t 01368 * 01369 * This virtual function converts the char to wchar_t using the 01370 * simplest reasonable transformation. For an underived ctype<wchar_t> 01371 * facet, the argument will be cast to wchar_t. 01372 * 01373 * do_widen() is a hook for a derived facet to change the behavior of 01374 * widening. do_widen() must always return the same result for the 01375 * same input. 01376 * 01377 * Note: this is not what you want for codepage conversions. See 01378 * codecvt for that. 01379 * 01380 * @param c The char to convert. 01381 * @return The converted wchar_t. 01382 */ 01383 virtual char_type 01384 do_widen(char) const; 01385 01386 /** 01387 * @brief Widen char array to wchar_t array 01388 * 01389 * This function converts each char in the input to wchar_t using the 01390 * simplest reasonable transformation. For an underived ctype<wchar_t> 01391 * facet, the argument will be copied, casting each element to wchar_t. 01392 * 01393 * do_widen() is a hook for a derived facet to change the behavior of 01394 * widening. do_widen() must always return the same result for the 01395 * same input. 01396 * 01397 * Note: this is not what you want for codepage conversions. See 01398 * codecvt for that. 01399 * 01400 * @param lo Pointer to start range. 01401 * @param hi Pointer to end of range. 01402 * @param to Pointer to the destination array. 01403 * @return @a hi. 01404 */ 01405 virtual const char* 01406 do_widen(const char* __lo, const char* __hi, char_type* __dest) const; 01407 01408 /** 01409 * @brief Narrow wchar_t to char 01410 * 01411 * This virtual function converts the argument to char using 01412 * the simplest reasonable transformation. If the conversion 01413 * fails, dfault is returned instead. For an underived 01414 * ctype<wchar_t> facet, @a c will be cast to char and 01415 * returned. 01416 * 01417 * do_narrow() is a hook for a derived facet to change the 01418 * behavior of narrowing. do_narrow() must always return the 01419 * same result for the same input. 01420 * 01421 * Note: this is not what you want for codepage conversions. See 01422 * codecvt for that. 01423 * 01424 * @param c The wchar_t to convert. 01425 * @param dfault Char to return if conversion fails. 01426 * @return The converted char. 01427 */ 01428 virtual char 01429 do_narrow(char_type, char __dfault) const; 01430 01431 /** 01432 * @brief Narrow wchar_t array to char array 01433 * 01434 * This virtual function converts each wchar_t in the range [lo,hi) to 01435 * char using the simplest reasonable transformation and writes the 01436 * results to the destination array. For any wchar_t in the input that 01437 * cannot be converted, @a dfault is used instead. For an underived 01438 * ctype<wchar_t> facet, the argument will be copied, casting each 01439 * element to char. 01440 * 01441 * do_narrow() is a hook for a derived facet to change the behavior of 01442 * narrowing. do_narrow() must always return the same result for the 01443 * same input. 01444 * 01445 * Note: this is not what you want for codepage conversions. See 01446 * codecvt for that. 01447 * 01448 * @param lo Pointer to start of range. 01449 * @param hi Pointer to end of range. 01450 * @param dfault Char to use if conversion fails. 01451 * @param to Pointer to the destination array. 01452 * @return @a hi. 01453 */ 01454 virtual const char_type* 01455 do_narrow(const char_type* __lo, const char_type* __hi, 01456 char __dfault, char* __dest) const; 01457 01458 // For use at construction time only. 01459 void 01460 _M_initialize_ctype() throw(); 01461 }; 01462 #endif //_GLIBCXX_USE_WCHAR_T 01463 01464 /// class ctype_byname [22.2.1.2]. 01465 template<typename _CharT> 01466 class ctype_byname : public ctype<_CharT> 01467 { 01468 public: 01469 typedef typename ctype<_CharT>::mask mask; 01470 01471 explicit 01472 ctype_byname(const char* __s, size_t __refs = 0); 01473 01474 protected: 01475 virtual 01476 ~ctype_byname() { }; 01477 }; 01478 01479 /// 22.2.1.4 Class ctype_byname specializations. 01480 template<> 01481 class ctype_byname<char> : public ctype<char> 01482 { 01483 public: 01484 explicit 01485 ctype_byname(const char* __s, size_t __refs = 0); 01486 01487 protected: 01488 virtual 01489 ~ctype_byname(); 01490 }; 01491 01492 #ifdef _GLIBCXX_USE_WCHAR_T 01493 template<> 01494 class ctype_byname<wchar_t> : public ctype<wchar_t> 01495 { 01496 public: 01497 explicit 01498 ctype_byname(const char* __s, size_t __refs = 0); 01499 01500 protected: 01501 virtual 01502 ~ctype_byname(); 01503 }; 01504 #endif 01505 01506 _GLIBCXX_END_NAMESPACE 01507 01508 // Include host and configuration specific ctype inlines. 01509 #include <bits/ctype_inline.h> 01510 01511 _GLIBCXX_BEGIN_NAMESPACE(std) 01512 01513 // 22.2.2 The numeric category. 01514 class __num_base 01515 { 01516 public: 01517 // NB: Code depends on the order of _S_atoms_out elements. 01518 // Below are the indices into _S_atoms_out. 01519 enum 01520 { 01521 _S_ominus, 01522 _S_oplus, 01523 _S_ox, 01524 _S_oX, 01525 _S_odigits, 01526 _S_odigits_end = _S_odigits + 16, 01527 _S_oudigits = _S_odigits_end, 01528 _S_oudigits_end = _S_oudigits + 16, 01529 _S_oe = _S_odigits + 14, // For scientific notation, 'e' 01530 _S_oE = _S_oudigits + 14, // For scientific notation, 'E' 01531 _S_oend = _S_oudigits_end 01532 }; 01533 01534 // A list of valid numeric literals for output. This array 01535 // contains chars that will be passed through the current locale's 01536 // ctype<_CharT>.widen() and then used to render numbers. 01537 // For the standard "C" locale, this is 01538 // "-+xX0123456789abcdef0123456789ABCDEF". 01539 static const char* _S_atoms_out; 01540 01541 // String literal of acceptable (narrow) input, for num_get. 01542 // "-+xX0123456789abcdefABCDEF" 01543 static const char* _S_atoms_in; 01544 01545 enum 01546 { 01547 _S_iminus, 01548 _S_iplus, 01549 _S_ix, 01550 _S_iX, 01551 _S_izero, 01552 _S_ie = _S_izero + 14, 01553 _S_iE = _S_izero + 20, 01554 _S_iend = 26 01555 }; 01556 01557 // num_put 01558 // Construct and return valid scanf format for floating point types. 01559 static void 01560 _S_format_float(const ios_base& __io, char* __fptr, char __mod) throw(); 01561 }; 01562 01563 template<typename _CharT> 01564 struct __numpunct_cache : public locale::facet 01565 { 01566 const char* _M_grouping; 01567 size_t _M_grouping_size; 01568 bool _M_use_grouping; 01569 const _CharT* _M_truename; 01570 size_t _M_truename_size; 01571 const _CharT* _M_falsename; 01572 size_t _M_falsename_size; 01573 _CharT _M_decimal_point; 01574 _CharT _M_thousands_sep; 01575 01576 // A list of valid numeric literals for output: in the standard 01577 // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF". 01578 // This array contains the chars after having been passed 01579 // through the current locale's ctype<_CharT>.widen(). 01580 _CharT _M_atoms_out[__num_base::_S_oend]; 01581 01582 // A list of valid numeric literals for input: in the standard 01583 // "C" locale, this is "-+xX0123456789abcdefABCDEF" 01584 // This array contains the chars after having been passed 01585 // through the current locale's ctype<_CharT>.widen(). 01586 _CharT _M_atoms_in[__num_base::_S_iend]; 01587 01588 bool _M_allocated; 01589 01590 __numpunct_cache(size_t __refs = 0) 01591 : facet(__refs), _M_grouping(0), _M_grouping_size(0), 01592 _M_use_grouping(false), 01593 _M_truename(0), _M_truename_size(0), _M_falsename(0), 01594 _M_falsename_size(0), _M_decimal_point(_CharT()), 01595 _M_thousands_sep(_CharT()), _M_allocated(false) 01596 { } 01597 01598 ~__numpunct_cache(); 01599 01600 void 01601 _M_cache(const locale& __loc); 01602 01603 private: 01604 __numpunct_cache& 01605 operator=(const __numpunct_cache&); 01606 01607 explicit 01608 __numpunct_cache(const __numpunct_cache&); 01609 }; 01610 01611 template<typename _CharT> 01612 __numpunct_cache<_CharT>::~__numpunct_cache() 01613 { 01614 if (_M_allocated) 01615 { 01616 delete [] _M_grouping; 01617 delete [] _M_truename; 01618 delete [] _M_falsename; 01619 } 01620 } 01621 01622 /** 01623 * @brief Primary class template numpunct. 01624 * @ingroup locales 01625 * 01626 * This facet stores several pieces of information related to printing and 01627 * scanning numbers, such as the decimal point character. It takes a 01628 * template parameter specifying the char type. The numpunct facet is 01629 * used by streams for many I/O operations involving numbers. 01630 * 01631 * The numpunct template uses protected virtual functions to provide the 01632 * actual results. The public accessors forward the call to the virtual 01633 * functions. These virtual functions are hooks for developers to 01634 * implement the behavior they require from a numpunct facet. 01635 */ 01636 template<typename _CharT> 01637 class numpunct : public locale::facet 01638 { 01639 public: 01640 // Types: 01641 //@{ 01642 /// Public typedefs 01643 typedef _CharT char_type; 01644 typedef basic_string<_CharT> string_type; 01645 //@} 01646 typedef __numpunct_cache<_CharT> __cache_type; 01647 01648 protected: 01649 __cache_type* _M_data; 01650 01651 public: 01652 /// Numpunct facet id. 01653 static locale::id id; 01654 01655 /** 01656 * @brief Numpunct constructor. 01657 * 01658 * @param refs Refcount to pass to the base class. 01659 */ 01660 explicit 01661 numpunct(size_t __refs = 0) 01662 : facet(__refs), _M_data(0) 01663 { _M_initialize_numpunct(); } 01664 01665 /** 01666 * @brief Internal constructor. Not for general use. 01667 * 01668 * This is a constructor for use by the library itself to set up the 01669 * predefined locale facets. 01670 * 01671 * @param cache __numpunct_cache object. 01672 * @param refs Refcount to pass to the base class. 01673 */ 01674 explicit 01675 numpunct(__cache_type* __cache, size_t __refs = 0) 01676 : facet(__refs), _M_data(__cache) 01677 { _M_initialize_numpunct(); } 01678 01679 /** 01680 * @brief Internal constructor. Not for general use. 01681 * 01682 * This is a constructor for use by the library itself to set up new 01683 * locales. 01684 * 01685 * @param cloc The C locale. 01686 * @param refs Refcount to pass to the base class. 01687 */ 01688 explicit 01689 numpunct(__c_locale __cloc, size_t __refs = 0) 01690 : facet(__refs), _M_data(0) 01691 { _M_initialize_numpunct(__cloc); } 01692 01693 /** 01694 * @brief Return decimal point character. 01695 * 01696 * This function returns a char_type to use as a decimal point. It 01697 * does so by returning returning 01698 * numpunct<char_type>::do_decimal_point(). 01699 * 01700 * @return @a char_type representing a decimal point. 01701 */ 01702 char_type 01703 decimal_point() const 01704 { return this->do_decimal_point(); } 01705 01706 /** 01707 * @brief Return thousands separator character. 01708 * 01709 * This function returns a char_type to use as a thousands 01710 * separator. It does so by returning returning 01711 * numpunct<char_type>::do_thousands_sep(). 01712 * 01713 * @return char_type representing a thousands separator. 01714 */ 01715 char_type 01716 thousands_sep() const 01717 { return this->do_thousands_sep(); } 01718 01719 /** 01720 * @brief Return grouping specification. 01721 * 01722 * This function returns a string representing groupings for the 01723 * integer part of a number. Groupings indicate where thousands 01724 * separators should be inserted in the integer part of a number. 01725 * 01726 * Each char in the return string is interpret as an integer 01727 * rather than a character. These numbers represent the number 01728 * of digits in a group. The first char in the string 01729 * represents the number of digits in the least significant 01730 * group. If a char is negative, it indicates an unlimited 01731 * number of digits for the group. If more chars from the 01732 * string are required to group a number, the last char is used 01733 * repeatedly. 01734 * 01735 * For example, if the grouping() returns "\003\002" and is 01736 * applied to the number 123456789, this corresponds to 01737 * 12,34,56,789. Note that if the string was "32", this would 01738 * put more than 50 digits into the least significant group if 01739 * the character set is ASCII. 01740 * 01741 * The string is returned by calling 01742 * numpunct<char_type>::do_grouping(). 01743 * 01744 * @return string representing grouping specification. 01745 */ 01746 string 01747 grouping() const 01748 { return this->do_grouping(); } 01749 01750 /** 01751 * @brief Return string representation of bool true. 01752 * 01753 * This function returns a string_type containing the text 01754 * representation for true bool variables. It does so by calling 01755 * numpunct<char_type>::do_truename(). 01756 * 01757 * @return string_type representing printed form of true. 01758 */ 01759 string_type 01760 truename() const 01761 { return this->do_truename(); } 01762 01763 /** 01764 * @brief Return string representation of bool false. 01765 * 01766 * This function returns a string_type containing the text 01767 * representation for false bool variables. It does so by calling 01768 * numpunct<char_type>::do_falsename(). 01769 * 01770 * @return string_type representing printed form of false. 01771 */ 01772 string_type 01773 falsename() const 01774 { return this->do_falsename(); } 01775 01776 protected: 01777 /// Destructor. 01778 virtual 01779 ~numpunct(); 01780 01781 /** 01782 * @brief Return decimal point character. 01783 * 01784 * Returns a char_type to use as a decimal point. This function is a 01785 * hook for derived classes to change the value returned. 01786 * 01787 * @return @a char_type representing a decimal point. 01788 */ 01789 virtual char_type 01790 do_decimal_point() const 01791 { return _M_data->_M_decimal_point; } 01792 01793 /** 01794 * @brief Return thousands separator character. 01795 * 01796 * Returns a char_type to use as a thousands separator. This function 01797 * is a hook for derived classes to change the value returned. 01798 * 01799 * @return @a char_type representing a thousands separator. 01800 */ 01801 virtual char_type 01802 do_thousands_sep() const 01803 { return _M_data->_M_thousands_sep; } 01804 01805 /** 01806 * @brief Return grouping specification. 01807 * 01808 * Returns a string representing groupings for the integer part of a 01809 * number. This function is a hook for derived classes to change the 01810 * value returned. @see grouping() for details. 01811 * 01812 * @return String representing grouping specification. 01813 */ 01814 virtual string 01815 do_grouping() const 01816 { return _M_data->_M_grouping; } 01817 01818 /** 01819 * @brief Return string representation of bool true. 01820 * 01821 * Returns a string_type containing the text representation for true 01822 * bool variables. This function is a hook for derived classes to 01823 * change the value returned. 01824 * 01825 * @return string_type representing printed form of true. 01826 */ 01827 virtual string_type 01828 do_truename() const 01829 { return _M_data->_M_truename; } 01830 01831 /** 01832 * @brief Return string representation of bool false. 01833 * 01834 * Returns a string_type containing the text representation for false 01835 * bool variables. This function is a hook for derived classes to 01836 * change the value returned. 01837 * 01838 * @return string_type representing printed form of false. 01839 */ 01840 virtual string_type 01841 do_falsename() const 01842 { return _M_data->_M_falsename; } 01843 01844 // For use at construction time only. 01845 void 01846 _M_initialize_numpunct(__c_locale __cloc = 0); 01847 }; 01848 01849 template<typename _CharT> 01850 locale::id numpunct<_CharT>::id; 01851 01852 template<> 01853 numpunct<char>::~numpunct(); 01854 01855 template<> 01856 void 01857 numpunct<char>::_M_initialize_numpunct(__c_locale __cloc); 01858 01859 #ifdef _GLIBCXX_USE_WCHAR_T 01860 template<> 01861 numpunct<wchar_t>::~numpunct(); 01862 01863 template<> 01864 void 01865 numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc); 01866 #endif 01867 01868 /// class numpunct_byname [22.2.3.2]. 01869 template<typename _CharT> 01870 class numpunct_byname : public numpunct<_CharT> 01871 { 01872 public: 01873 typedef _CharT char_type; 01874 typedef basic_string<_CharT> string_type; 01875 01876 explicit 01877 numpunct_byname(const char* __s, size_t __refs = 0) 01878 : numpunct<_CharT>(__refs) 01879 { 01880 if (__builtin_strcmp(__s, "C") != 0 01881 && __builtin_strcmp(__s, "POSIX") != 0) 01882 { 01883 __c_locale __tmp; 01884 this->_S_create_c_locale(__tmp, __s); 01885 this->_M_initialize_numpunct(__tmp); 01886 this->_S_destroy_c_locale(__tmp); 01887 } 01888 } 01889 01890 protected: 01891 virtual 01892 ~numpunct_byname() { } 01893 }; 01894 01895 _GLIBCXX_BEGIN_LDBL_NAMESPACE 01896 01897 /** 01898 * @brief Primary class template num_get. 01899 * @ingroup locales 01900 * 01901 * This facet encapsulates the code to parse and return a number 01902 * from a string. It is used by the istream numeric extraction 01903 * operators. 01904 * 01905 * The num_get template uses protected virtual functions to provide the 01906 * actual results. The public accessors forward the call to the virtual 01907 * functions. These virtual functions are hooks for developers to 01908 * implement the behavior they require from the num_get facet. 01909 */ 01910 template<typename _CharT, typename _InIter> 01911 class num_get : public locale::facet 01912 { 01913 public: 01914 // Types: 01915 //@{ 01916 /// Public typedefs 01917 typedef _CharT char_type; 01918 typedef _InIter iter_type; 01919 //@} 01920 01921 /// Numpunct facet id. 01922 static locale::id id; 01923 01924 /** 01925 * @brief Constructor performs initialization. 01926 * 01927 * This is the constructor provided by the standard. 01928 * 01929 * @param refs Passed to the base facet class. 01930 */ 01931 explicit 01932 num_get(size_t __refs = 0) : facet(__refs) { } 01933 01934 /** 01935 * @brief Numeric parsing. 01936 * 01937 * Parses the input stream into the bool @a v. It does so by calling 01938 * num_get::do_get(). 01939 * 01940 * If ios_base::boolalpha is set, attempts to read 01941 * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets 01942 * @a v to true or false if successful. Sets err to 01943 * ios_base::failbit if reading the string fails. Sets err to 01944 * ios_base::eofbit if the stream is emptied. 01945 * 01946 * If ios_base::boolalpha is not set, proceeds as with reading a long, 01947 * except if the value is 1, sets @a v to true, if the value is 0, sets 01948 * @a v to false, and otherwise set err to ios_base::failbit. 01949 * 01950 * @param in Start of input stream. 01951 * @param end End of input stream. 01952 * @param io Source of locale and flags. 01953 * @param err Error flags to set. 01954 * @param v Value to format and insert. 01955 * @return Iterator after reading. 01956 */ 01957 iter_type 01958 get(iter_type __in, iter_type __end, ios_base& __io, 01959 ios_base::iostate& __err, bool& __v) const 01960 { return this->do_get(__in, __end, __io, __err, __v); } 01961 01962 //@{ 01963 /** 01964 * @brief Numeric parsing. 01965 * 01966 * Parses the input stream into the integral variable @a v. It does so 01967 * by calling num_get::do_get(). 01968 * 01969 * Parsing is affected by the flag settings in @a io. 01970 * 01971 * The basic parse is affected by the value of io.flags() & 01972 * ios_base::basefield. If equal to ios_base::oct, parses like the 01973 * scanf %o specifier. Else if equal to ios_base::hex, parses like %X 01974 * specifier. Else if basefield equal to 0, parses like the %i 01975 * specifier. Otherwise, parses like %d for signed and %u for unsigned 01976 * types. The matching type length modifier is also used. 01977 * 01978 * Digit grouping is interpreted according to numpunct::grouping() and 01979 * numpunct::thousands_sep(). If the pattern of digit groups isn't 01980 * consistent, sets err to ios_base::failbit. 01981 * 01982 * If parsing the string yields a valid value for @a v, @a v is set. 01983 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered. 01984 * Sets err to ios_base::eofbit if the stream is emptied. 01985 * 01986 * @param in Start of input stream. 01987 * @param end End of input stream. 01988 * @param io Source of locale and flags. 01989 * @param err Error flags to set. 01990 * @param v Value to format and insert. 01991 * @return Iterator after reading. 01992 */ 01993 iter_type 01994 get(iter_type __in, iter_type __end, ios_base& __io, 01995 ios_base::iostate& __err, long& __v) const 01996 { return this->do_get(__in, __end, __io, __err, __v); } 01997 01998 iter_type 01999 get(iter_type __in, iter_type __end, ios_base& __io, 02000 ios_base::iostate& __err, unsigned short& __v) const 02001 { return this->do_get(__in, __end, __io, __err, __v); } 02002 02003 iter_type 02004 get(iter_type __in, iter_type __end, ios_base& __io, 02005 ios_base::iostate& __err, unsigned int& __v) const 02006 { return this->do_get(__in, __end, __io, __err, __v); } 02007 02008 iter_type 02009 get(iter_type __in, iter_type __end, ios_base& __io, 02010 ios_base::iostate& __err, unsigned long& __v) const 02011 { return this->do_get(__in, __end, __io, __err, __v); } 02012 02013 #ifdef _GLIBCXX_USE_LONG_LONG 02014 iter_type 02015 get(iter_type __in, iter_type __end, ios_base& __io, 02016 ios_base::iostate& __err, long long& __v) const 02017 { return this->do_get(__in, __end, __io, __err, __v); } 02018 02019 iter_type 02020 get(iter_type __in, iter_type __end, ios_base& __io, 02021 ios_base::iostate& __err, unsigned long long& __v) const 02022 { return this->do_get(__in, __end, __io, __err, __v); } 02023 #endif 02024 //@} 02025 02026 //@{ 02027 /** 02028 * @brief Numeric parsing. 02029 * 02030 * Parses the input stream into the integral variable @a v. It does so 02031 * by calling num_get::do_get(). 02032 * 02033 * The input characters are parsed like the scanf %g specifier. The 02034 * matching type length modifier is also used. 02035 * 02036 * The decimal point character used is numpunct::decimal_point(). 02037 * Digit grouping is interpreted according to numpunct::grouping() and 02038 * numpunct::thousands_sep(). If the pattern of digit groups isn't 02039 * consistent, sets err to ios_base::failbit. 02040 * 02041 * If parsing the string yields a valid value for @a v, @a v is set. 02042 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered. 02043 * Sets err to ios_base::eofbit if the stream is emptied. 02044 * 02045 * @param in Start of input stream. 02046 * @param end End of input stream. 02047 * @param io Source of locale and flags. 02048 * @param err Error flags to set. 02049 * @param v Value to format and insert. 02050 * @return Iterator after reading. 02051 */ 02052 iter_type 02053 get(iter_type __in, iter_type __end, ios_base& __io, 02054 ios_base::iostate& __err, float& __v) const 02055 { return this->do_get(__in, __end, __io, __err, __v); } 02056 02057 iter_type 02058 get(iter_type __in, iter_type __end, ios_base& __io, 02059 ios_base::iostate& __err, double& __v) const 02060 { return this->do_get(__in, __end, __io, __err, __v); } 02061 02062 iter_type 02063 get(iter_type __in, iter_type __end, ios_base& __io, 02064 ios_base::iostate& __err, long double& __v) const 02065 { return this->do_get(__in, __end, __io, __err, __v); } 02066 //@} 02067 02068 /** 02069 * @brief Numeric parsing. 02070 * 02071 * Parses the input stream into the pointer variable @a v. It does so 02072 * by calling num_get::do_get(). 02073 * 02074 * The input characters are parsed like the scanf %p specifier. 02075 * 02076 * Digit grouping is interpreted according to numpunct::grouping() and 02077 * numpunct::thousands_sep(). If the pattern of digit groups isn't 02078 * consistent, sets err to ios_base::failbit. 02079 * 02080 * Note that the digit grouping effect for pointers is a bit ambiguous 02081 * in the standard and shouldn't be relied on. See DR 344. 02082 * 02083 * If parsing the string yields a valid value for @a v, @a v is set. 02084 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered. 02085 * Sets err to ios_base::eofbit if the stream is emptied. 02086 * 02087 * @param in Start of input stream. 02088 * @param end End of input stream. 02089 * @param io Source of locale and flags. 02090 * @param err Error flags to set. 02091 * @param v Value to format and insert. 02092 * @return Iterator after reading. 02093 */ 02094 iter_type 02095 get(iter_type __in, iter_type __end, ios_base& __io, 02096 ios_base::iostate& __err, void*& __v) const 02097 { return this->do_get(__in, __end, __io, __err, __v); } 02098 02099 protected: 02100 /// Destructor. 02101 virtual ~num_get() { } 02102 02103 iter_type 02104 _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&, 02105 string&) const; 02106 02107 template<typename _ValueT> 02108 iter_type 02109 _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&, 02110 _ValueT&) const; 02111 02112 template<typename _CharT2> 02113 typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, int>::__type 02114 _M_find(const _CharT2*, size_t __len, _CharT2 __c) const 02115 { 02116 int __ret = -1; 02117 if (__len <= 10) 02118 { 02119 if (__c >= _CharT2('0') && __c < _CharT2(_CharT2('0') + __len)) 02120 __ret = __c - _CharT2('0'); 02121 } 02122 else 02123 { 02124 if (__c >= _CharT2('0') && __c <= _CharT2('9')) 02125 __ret = __c - _CharT2('0'); 02126 else if (__c >= _CharT2('a') && __c <= _CharT2('f')) 02127 __ret = 10 + (__c - _CharT2('a')); 02128 else if (__c >= _CharT2('A') && __c <= _CharT2('F')) 02129 __ret = 10 + (__c - _CharT2('A')); 02130 } 02131 return __ret; 02132 } 02133 02134 template<typename _CharT2> 02135 typename __gnu_cxx::__enable_if<!__is_char<_CharT2>::__value, 02136 int>::__type 02137 _M_find(const _CharT2* __zero, size_t __len, _CharT2 __c) const 02138 { 02139 int __ret = -1; 02140 const char_type* __q = char_traits<_CharT2>::find(__zero, __len, __c); 02141 if (__q) 02142 { 02143 __ret = __q - __zero; 02144 if (__ret > 15) 02145 __ret -= 6; 02146 } 02147 return __ret; 02148 } 02149 02150 //@{ 02151 /** 02152 * @brief Numeric parsing. 02153 * 02154 * Parses the input stream into the variable @a v. This function is a 02155 * hook for derived classes to change the value returned. @see get() 02156 * for more details. 02157 * 02158 * @param in Start of input stream. 02159 * @param end End of input stream. 02160 * @param io Source of locale and flags. 02161 * @param err Error flags to set. 02162 * @param v Value to format and insert. 02163 * @return Iterator after reading. 02164 */ 02165 virtual iter_type 02166 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const; 02167 02168 virtual iter_type 02169 do_get(iter_type __beg, iter_type __end, ios_base& __io, 02170 ios_base::iostate& __err, long& __v) const 02171 { return _M_extract_int(__beg, __end, __io, __err, __v); } 02172 02173 virtual iter_type 02174 do_get(iter_type __beg, iter_type __end, ios_base& __io, 02175 ios_base::iostate& __err, unsigned short& __v) const 02176 { return _M_extract_int(__beg, __end, __io, __err, __v); } 02177 02178 virtual iter_type 02179 do_get(iter_type __beg, iter_type __end, ios_base& __io, 02180 ios_base::iostate& __err, unsigned int& __v) const 02181 { return _M_extract_int(__beg, __end, __io, __err, __v); } 02182 02183 virtual iter_type 02184 do_get(iter_type __beg, iter_type __end, ios_base& __io, 02185 ios_base::iostate& __err, unsigned long& __v) const 02186 { return _M_extract_int(__beg, __end, __io, __err, __v); } 02187 02188 #ifdef _GLIBCXX_USE_LONG_LONG 02189 virtual iter_type 02190 do_get(iter_type __beg, iter_type __end, ios_base& __io, 02191 ios_base::iostate& __err, long long& __v) const 02192 { return _M_extract_int(__beg, __end, __io, __err, __v); } 02193 02194 virtual iter_type 02195 do_get(iter_type __beg, iter_type __end, ios_base& __io, 02196 ios_base::iostate& __err, unsigned long long& __v) const 02197 { return _M_extract_int(__beg, __end, __io, __err, __v); } 02198 #endif 02199 02200 virtual iter_type 02201 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 02202 float&) const; 02203 02204 virtual iter_type 02205 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 02206 double&) const; 02207 02208 // XXX GLIBCXX_ABI Deprecated 02209 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 02210 virtual iter_type 02211 __do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 02212 double&) const; 02213 #else 02214 virtual iter_type 02215 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 02216 long double&) const; 02217 #endif 02218 02219 virtual iter_type 02220 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 02221 void*&) const; 02222 02223 // XXX GLIBCXX_ABI Deprecated 02224 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 02225 virtual iter_type 02226 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 02227 long double&) const; 02228 #endif 02229 //@} 02230 }; 02231 02232 template<typename _CharT, typename _InIter> 02233 locale::id num_get<_CharT, _InIter>::id; 02234 02235 02236 /** 02237 * @brief Primary class template num_put. 02238 * @ingroup locales 02239 * 02240 * This facet encapsulates the code to convert a number to a string. It is 02241 * used by the ostream numeric insertion operators. 02242 * 02243 * The num_put template uses protected virtual functions to provide the 02244 * actual results. The public accessors forward the call to the virtual 02245 * functions. These virtual functions are hooks for developers to 02246 * implement the behavior they require from the num_put facet. 02247 */ 02248 template<typename _CharT, typename _OutIter> 02249 class num_put : public locale::facet 02250 { 02251 public: 02252 // Types: 02253 //@{ 02254 /// Public typedefs 02255 typedef _CharT char_type; 02256 typedef _OutIter iter_type; 02257 //@} 02258 02259 /// Numpunct facet id. 02260 static locale::id id; 02261 02262 /** 02263 * @brief Constructor performs initialization. 02264 * 02265 * This is the constructor provided by the standard. 02266 * 02267 * @param refs Passed to the base facet class. 02268 */ 02269 explicit 02270 num_put(size_t __refs = 0) : facet(__refs) { } 02271 02272 /** 02273 * @brief Numeric formatting. 02274 * 02275 * Formats the boolean @a v and inserts it into a stream. It does so 02276 * by calling num_put::do_put(). 02277 * 02278 * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or 02279 * ctype<CharT>::falsename(). Otherwise formats @a v as an int. 02280 * 02281 * @param s Stream to write to. 02282 * @param io Source of locale and flags. 02283 * @param fill Char_type to use for filling. 02284 * @param v Value to format and insert. 02285 * @return Iterator after writing. 02286 */ 02287 iter_type 02288 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const 02289 { return this->do_put(__s, __f, __fill, __v); } 02290 02291 //@{ 02292 /** 02293 * @brief Numeric formatting. 02294 * 02295 * Formats the integral value @a v and inserts it into a 02296 * stream. It does so by calling num_put::do_put(). 02297 * 02298 * Formatting is affected by the flag settings in @a io. 02299 * 02300 * The basic format is affected by the value of io.flags() & 02301 * ios_base::basefield. If equal to ios_base::oct, formats like the 02302 * printf %o specifier. Else if equal to ios_base::hex, formats like 02303 * %x or %X with ios_base::uppercase unset or set respectively. 02304 * Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu 02305 * for unsigned values. Note that if both oct and hex are set, neither 02306 * will take effect. 02307 * 02308 * If ios_base::showpos is set, '+' is output before positive values. 02309 * If ios_base::showbase is set, '0' precedes octal values (except 0) 02310 * and '0[xX]' precedes hex values. 02311 * 02312 * Thousands separators are inserted according to numpunct::grouping() 02313 * and numpunct::thousands_sep(). The decimal point character used is 02314 * numpunct::decimal_point(). 02315 * 02316 * If io.width() is non-zero, enough @a fill characters are inserted to 02317 * make the result at least that wide. If 02318 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is 02319 * padded at the end. If ios_base::internal, then padding occurs 02320 * immediately after either a '+' or '-' or after '0x' or '0X'. 02321 * Otherwise, padding occurs at the beginning. 02322 * 02323 * @param s Stream to write to. 02324 * @param io Source of locale and flags. 02325 * @param fill Char_type to use for filling. 02326 * @param v Value to format and insert. 02327 * @return Iterator after writing. 02328 */ 02329 iter_type 02330 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const 02331 { return this->do_put(__s, __f, __fill, __v); } 02332 02333 iter_type 02334 put(iter_type __s, ios_base& __f, char_type __fill, 02335 unsigned long __v) const 02336 { return this->do_put(__s, __f, __fill, __v); } 02337 02338 #ifdef _GLIBCXX_USE_LONG_LONG 02339 iter_type 02340 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const 02341 { return this->do_put(__s, __f, __fill, __v); } 02342 02343 iter_type 02344 put(iter_type __s, ios_base& __f, char_type __fill, 02345 unsigned long long __v) const 02346 { return this->do_put(__s, __f, __fill, __v); } 02347 #endif 02348 //@} 02349 02350 //@{ 02351 /** 02352 * @brief Numeric formatting. 02353 * 02354 * Formats the floating point value @a v and inserts it into a stream. 02355 * It does so by calling num_put::do_put(). 02356 * 02357 * Formatting is affected by the flag settings in @a io. 02358 * 02359 * The basic format is affected by the value of io.flags() & 02360 * ios_base::floatfield. If equal to ios_base::fixed, formats like the 02361 * printf %f specifier. Else if equal to ios_base::scientific, formats 02362 * like %e or %E with ios_base::uppercase unset or set respectively. 02363 * Otherwise, formats like %g or %G depending on uppercase. Note that 02364 * if both fixed and scientific are set, the effect will also be like 02365 * %g or %G. 02366 * 02367 * The output precision is given by io.precision(). This precision is 02368 * capped at numeric_limits::digits10 + 2 (different for double and 02369 * long double). The default precision is 6. 02370 * 02371 * If ios_base::showpos is set, '+' is output before positive values. 02372 * If ios_base::showpoint is set, a decimal point will always be 02373 * output. 02374 * 02375 * Thousands separators are inserted according to numpunct::grouping() 02376 * and numpunct::thousands_sep(). The decimal point character used is 02377 * numpunct::decimal_point(). 02378 * 02379 * If io.width() is non-zero, enough @a fill characters are inserted to 02380 * make the result at least that wide. If 02381 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is 02382 * padded at the end. If ios_base::internal, then padding occurs 02383 * immediately after either a '+' or '-' or after '0x' or '0X'. 02384 * Otherwise, padding occurs at the beginning. 02385 * 02386 * @param s Stream to write to. 02387 * @param io Source of locale and flags. 02388 * @param fill Char_type to use for filling. 02389 * @param v Value to format and insert. 02390 * @return Iterator after writing. 02391 */ 02392 iter_type 02393 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const 02394 { return this->do_put(__s, __f, __fill, __v); } 02395 02396 iter_type 02397 put(iter_type __s, ios_base& __f, char_type __fill, 02398 long double __v) const 02399 { return this->do_put(__s, __f, __fill, __v); } 02400 //@} 02401 02402 /** 02403 * @brief Numeric formatting. 02404 * 02405 * Formats the pointer value @a v and inserts it into a stream. It 02406 * does so by calling num_put::do_put(). 02407 * 02408 * This function formats @a v as an unsigned long with ios_base::hex 02409 * and ios_base::showbase set. 02410 * 02411 * @param s Stream to write to. 02412 * @param io Source of locale and flags. 02413 * @param fill Char_type to use for filling. 02414 * @param v Value to format and insert. 02415 * @return Iterator after writing. 02416 */ 02417 iter_type 02418 put(iter_type __s, ios_base& __f, char_type __fill, 02419 const void* __v) const 02420 { return this->do_put(__s, __f, __fill, __v); } 02421 02422 protected: 02423 template<typename _ValueT> 02424 iter_type 02425 _M_insert_float(iter_type, ios_base& __io, char_type __fill, 02426 char __mod, _ValueT __v) const; 02427 02428 void 02429 _M_group_float(const char* __grouping, size_t __grouping_size, 02430 char_type __sep, const char_type* __p, char_type* __new, 02431 char_type* __cs, int& __len) const; 02432 02433 template<typename _ValueT> 02434 iter_type 02435 _M_insert_int(iter_type, ios_base& __io, char_type __fill, 02436 _ValueT __v) const; 02437 02438 void 02439 _M_group_int(const char* __grouping, size_t __grouping_size, 02440 char_type __sep, ios_base& __io, char_type* __new, 02441 char_type* __cs, int& __len) const; 02442 02443 void 02444 _M_pad(char_type __fill, streamsize __w, ios_base& __io, 02445 char_type* __new, const char_type* __cs, int& __len) const; 02446 02447 /// Destructor. 02448 virtual 02449 ~num_put() { }; 02450 02451 //@{ 02452 /** 02453 * @brief Numeric formatting. 02454 * 02455 * These functions do the work of formatting numeric values and 02456 * inserting them into a stream. This function is a hook for derived 02457 * classes to change the value returned. 02458 * 02459 * @param s Stream to write to. 02460 * @param io Source of locale and flags. 02461 * @param fill Char_type to use for filling. 02462 * @param v Value to format and insert. 02463 * @return Iterator after writing. 02464 */ 02465 virtual iter_type 02466 do_put(iter_type, ios_base&, char_type __fill, bool __v) const; 02467 02468 virtual iter_type 02469 do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const 02470 { return _M_insert_int(__s, __io, __fill, __v); } 02471 02472 virtual iter_type 02473 do_put(iter_type __s, ios_base& __io, char_type __fill, 02474 unsigned long __v) const 02475 { return _M_insert_int(__s, __io, __fill, __v); } 02476 02477 #ifdef _GLIBCXX_USE_LONG_LONG 02478 virtual iter_type 02479 do_put(iter_type __s, ios_base& __io, char_type __fill, 02480 long long __v) const 02481 { return _M_insert_int(__s, __io, __fill, __v); } 02482 02483 virtual iter_type 02484 do_put(iter_type __s, ios_base& __io, char_type __fill, 02485 unsigned long long __v) const 02486 { return _M_insert_int(__s, __io, __fill, __v); } 02487 #endif 02488 02489 virtual iter_type 02490 do_put(iter_type, ios_base&, char_type __fill, double __v) const; 02491 02492 // XXX GLIBCXX_ABI Deprecated 02493 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 02494 virtual iter_type 02495 __do_put(iter_type, ios_base&, char_type __fill, double __v) const; 02496 #else 02497 virtual iter_type 02498 do_put(iter_type, ios_base&, char_type __fill, long double __v) const; 02499 #endif 02500 02501 virtual iter_type 02502 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const; 02503 02504 // XXX GLIBCXX_ABI Deprecated 02505 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 02506 virtual iter_type 02507 do_put(iter_type, ios_base&, char_type __fill, long double __v) const; 02508 #endif 02509 //@} 02510 }; 02511 02512 template <typename _CharT, typename _OutIter> 02513 locale::id num_put<_CharT, _OutIter>::id; 02514 02515 _GLIBCXX_END_LDBL_NAMESPACE 02516 02517 // Subclause convenience interfaces, inlines. 02518 // NB: These are inline because, when used in a loop, some compilers 02519 // can hoist the body out of the loop; then it's just as fast as the 02520 // C is*() function. 02521 02522 /// Convenience interface to ctype.is(ctype_base::space, __c). 02523 template<typename _CharT> 02524 inline bool 02525 isspace(_CharT __c, const locale& __loc) 02526 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); } 02527 02528 /// Convenience interface to ctype.is(ctype_base::print, __c). 02529 template<typename _CharT> 02530 inline bool 02531 isprint(_CharT __c, const locale& __loc) 02532 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); } 02533 02534 /// Convenience interface to ctype.is(ctype_base::cntrl, __c). 02535 template<typename _CharT> 02536 inline bool 02537 iscntrl(_CharT __c, const locale& __loc) 02538 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); } 02539 02540 /// Convenience interface to ctype.is(ctype_base::upper, __c). 02541 template<typename _CharT> 02542 inline bool 02543 isupper(_CharT __c, const locale& __loc) 02544 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); } 02545 02546 /// Convenience interface to ctype.is(ctype_base::lower, __c). 02547 template<typename _CharT> 02548 inline bool 02549 islower(_CharT __c, const locale& __loc) 02550 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); } 02551 02552 /// Convenience interface to ctype.is(ctype_base::alpha, __c). 02553 template<typename _CharT> 02554 inline bool 02555 isalpha(_CharT __c, const locale& __loc) 02556 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); } 02557 02558 /// Convenience interface to ctype.is(ctype_base::digit, __c). 02559 template<typename _CharT> 02560 inline bool 02561 isdigit(_CharT __c, const locale& __loc) 02562 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); } 02563 02564 /// Convenience interface to ctype.is(ctype_base::punct, __c). 02565 template<typename _CharT> 02566 inline bool 02567 ispunct(_CharT __c, const locale& __loc) 02568 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); } 02569 02570 /// Convenience interface to ctype.is(ctype_base::xdigit, __c). 02571 template<typename _CharT> 02572 inline bool 02573 isxdigit(_CharT __c, const locale& __loc) 02574 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); } 02575 02576 /// Convenience interface to ctype.is(ctype_base::alnum, __c). 02577 template<typename _CharT> 02578 inline bool 02579 isalnum(_CharT __c, const locale& __loc) 02580 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); } 02581 02582 /// Convenience interface to ctype.is(ctype_base::graph, __c). 02583 template<typename _CharT> 02584 inline bool 02585 isgraph(_CharT __c, const locale& __loc) 02586 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); } 02587 02588 /// Convenience interface to ctype.toupper(__c). 02589 template<typename _CharT> 02590 inline _CharT 02591 toupper(_CharT __c, const locale& __loc) 02592 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); } 02593 02594 /// Convenience interface to ctype.tolower(__c). 02595 template<typename _CharT> 02596 inline _CharT 02597 tolower(_CharT __c, const locale& __loc) 02598 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); } 02599 02600 _GLIBCXX_END_NAMESPACE 02601 02602 #ifndef _GLIBCXX_EXPORT_TEMPLATE 02603 # include <bits/locale_facets.tcc> 02604 #endif 02605 02606 #endif