110d565efSmrg // std::collate implementation details, DragonFly version -*- C++ -*-
210d565efSmrg 
3*ec02198aSmrg // Copyright (C) 2015-2020 Free Software Foundation, Inc.
410d565efSmrg //
510d565efSmrg // This file is part of the GNU ISO C++ Library.  This library is free
610d565efSmrg // software; you can redistribute it and/or modify it under the
710d565efSmrg // terms of the GNU General Public License as published by the
810d565efSmrg // Free Software Foundation; either version 3, or (at your option)
910d565efSmrg // any later version.
1010d565efSmrg 
1110d565efSmrg // This library is distributed in the hope that it will be useful,
1210d565efSmrg // but WITHOUT ANY WARRANTY; without even the implied warranty of
1310d565efSmrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1410d565efSmrg // GNU General Public License for more details.
1510d565efSmrg 
1610d565efSmrg // Under Section 7 of GPL version 3, you are granted additional
1710d565efSmrg // permissions described in the GCC Runtime Library Exception, version
1810d565efSmrg // 3.1, as published by the Free Software Foundation.
1910d565efSmrg 
2010d565efSmrg // You should have received a copy of the GNU General Public License and
2110d565efSmrg // a copy of the GCC Runtime Library Exception along with this program;
2210d565efSmrg // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
2310d565efSmrg // <http://www.gnu.org/licenses/>.
2410d565efSmrg 
2510d565efSmrg //
2610d565efSmrg // ISO C++ 14882: 22.2.4.1.2  collate virtual functions
2710d565efSmrg //
2810d565efSmrg 
2910d565efSmrg // Written by Benjamin Kosnik <bkoz@redhat.com>
3010d565efSmrg // Modified for DragonFly by John Marino <gnugcc@marino.st>
3110d565efSmrg 
3210d565efSmrg #include <locale>
3310d565efSmrg #include <cstring>
3410d565efSmrg 
3510d565efSmrg namespace std _GLIBCXX_VISIBILITY(default)
3610d565efSmrg {
3710d565efSmrg _GLIBCXX_BEGIN_NAMESPACE_VERSION
3810d565efSmrg 
3910d565efSmrg   // These are basically extensions to char_traits, and perhaps should
4010d565efSmrg   // be put there instead of here.
4110d565efSmrg   template<>
4210d565efSmrg     int
_M_compare(const char * __one,const char * __two) const4310d565efSmrg     collate<char>::_M_compare(const char* __one,
4410d565efSmrg 			      const char* __two) const throw()
4510d565efSmrg     {
4610d565efSmrg       int __cmp = strcoll_l(__one, __two, (locale_t)_M_c_locale_collate);
4710d565efSmrg       return (__cmp >> (8 * sizeof (int) - 2)) | (__cmp != 0);
4810d565efSmrg     }
4910d565efSmrg 
5010d565efSmrg   template<>
5110d565efSmrg     size_t
_M_transform(char * __to,const char * __from,size_t __n) const5210d565efSmrg     collate<char>::_M_transform(char* __to, const char* __from,
5310d565efSmrg 				size_t __n) const throw()
5410d565efSmrg     { return strxfrm_l(__to, __from, __n, (locale_t)_M_c_locale_collate); }
5510d565efSmrg 
5610d565efSmrg #ifdef _GLIBCXX_USE_WCHAR_T
5710d565efSmrg   template<>
5810d565efSmrg     int
_M_compare(const wchar_t * __one,const wchar_t * __two) const5910d565efSmrg     collate<wchar_t>::_M_compare(const wchar_t* __one,
6010d565efSmrg 				 const wchar_t* __two) const throw()
6110d565efSmrg     {
6210d565efSmrg       int __cmp = wcscoll_l(__one, __two, (locale_t)_M_c_locale_collate);
6310d565efSmrg       return (__cmp >> (8 * sizeof (int) - 2)) | (__cmp != 0);
6410d565efSmrg     }
6510d565efSmrg 
6610d565efSmrg   template<>
6710d565efSmrg     size_t
_M_transform(wchar_t * __to,const wchar_t * __from,size_t __n) const6810d565efSmrg     collate<wchar_t>::_M_transform(wchar_t* __to, const wchar_t* __from,
6910d565efSmrg 				   size_t __n) const throw()
7010d565efSmrg     { return wcsxfrm_l(__to, __from, __n, (locale_t)_M_c_locale_collate); }
7110d565efSmrg #endif
7210d565efSmrg 
7310d565efSmrg _GLIBCXX_END_NAMESPACE_VERSION
7410d565efSmrg } // namespace
75