1*e4b17023SJohn Marino // std::collate implementation details, generic version -*- C++ -*- 2*e4b17023SJohn Marino 3*e4b17023SJohn Marino // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 4*e4b17023SJohn Marino // Free Software Foundation, Inc. 5*e4b17023SJohn Marino // 6*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library. This library is free 7*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the 8*e4b17023SJohn Marino // terms of the GNU General Public License as published by the 9*e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option) 10*e4b17023SJohn Marino // any later version. 11*e4b17023SJohn Marino 12*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful, 13*e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of 14*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*e4b17023SJohn Marino // GNU General Public License for more details. 16*e4b17023SJohn Marino 17*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional 18*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version 19*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation. 20*e4b17023SJohn Marino 21*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and 22*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program; 23*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>. 25*e4b17023SJohn Marino 26*e4b17023SJohn Marino // 27*e4b17023SJohn Marino // ISO C++ 14882: 22.2.4.1.2 collate virtual functions 28*e4b17023SJohn Marino // 29*e4b17023SJohn Marino 30*e4b17023SJohn Marino // Written by Benjamin Kosnik <bkoz@redhat.com> 31*e4b17023SJohn Marino 32*e4b17023SJohn Marino #include <locale> 33*e4b17023SJohn Marino #include <cstring> 34*e4b17023SJohn Marino 35*e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default) 36*e4b17023SJohn Marino { 37*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION 38*e4b17023SJohn Marino 39*e4b17023SJohn Marino // These are basically extensions to char_traits, and perhaps should 40*e4b17023SJohn Marino // be put there instead of here. 41*e4b17023SJohn Marino template<> 42*e4b17023SJohn Marino int _M_compare(const char * __one,const char * __two) const43*e4b17023SJohn Marino collate<char>::_M_compare(const char* __one, 44*e4b17023SJohn Marino const char* __two) const throw() 45*e4b17023SJohn Marino { 46*e4b17023SJohn Marino int __cmp = strcoll(__one, __two); 47*e4b17023SJohn Marino return (__cmp >> (8 * sizeof (int) - 2)) | (__cmp != 0); 48*e4b17023SJohn Marino } 49*e4b17023SJohn Marino 50*e4b17023SJohn Marino template<> 51*e4b17023SJohn Marino size_t _M_transform(char * __to,const char * __from,size_t __n) const52*e4b17023SJohn Marino collate<char>::_M_transform(char* __to, const char* __from, 53*e4b17023SJohn Marino size_t __n) const throw() 54*e4b17023SJohn Marino { return strxfrm(__to, __from, __n); } 55*e4b17023SJohn Marino 56*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 57*e4b17023SJohn Marino template<> 58*e4b17023SJohn Marino int _M_compare(const wchar_t * __one,const wchar_t * __two) const59*e4b17023SJohn Marino collate<wchar_t>::_M_compare(const wchar_t* __one, 60*e4b17023SJohn Marino const wchar_t* __two) const throw() 61*e4b17023SJohn Marino { 62*e4b17023SJohn Marino int __cmp = wcscoll(__one, __two); 63*e4b17023SJohn Marino return (__cmp >> (8 * sizeof (int) - 2)) | (__cmp != 0); 64*e4b17023SJohn Marino } 65*e4b17023SJohn Marino 66*e4b17023SJohn Marino template<> 67*e4b17023SJohn Marino size_t _M_transform(wchar_t * __to,const wchar_t * __from,size_t __n) const68*e4b17023SJohn Marino collate<wchar_t>::_M_transform(wchar_t* __to, const wchar_t* __from, 69*e4b17023SJohn Marino size_t __n) const throw() 70*e4b17023SJohn Marino { return wcsxfrm(__to, __from, __n); } 71*e4b17023SJohn Marino #endif 72*e4b17023SJohn Marino 73*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION 74*e4b17023SJohn Marino } // namespace 75