197403Sobrien// std::collate implementation details, generic version -*- C++ -*- 297403Sobrien 3169691Skan// Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc. 497403Sobrien// 597403Sobrien// This file is part of the GNU ISO C++ Library. This library is free 697403Sobrien// software; you can redistribute it and/or modify it under the 797403Sobrien// terms of the GNU General Public License as published by the 897403Sobrien// Free Software Foundation; either version 2, or (at your option) 997403Sobrien// any later version. 1097403Sobrien 1197403Sobrien// This library is distributed in the hope that it will be useful, 1297403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of 1397403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1497403Sobrien// GNU General Public License for more details. 1597403Sobrien 1697403Sobrien// You should have received a copy of the GNU General Public License along 1797403Sobrien// with this library; see the file COPYING. If not, write to the Free 18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 1997403Sobrien// USA. 2097403Sobrien 2197403Sobrien// As a special exception, you may use this file as part of a free software 2297403Sobrien// library without restriction. Specifically, if other files instantiate 2397403Sobrien// templates or use macros or inline functions from this file, or you compile 2497403Sobrien// this file and link it with other files to produce an executable, this 2597403Sobrien// file does not by itself cause the resulting executable to be covered by 2697403Sobrien// the GNU General Public License. This exception does not however 2797403Sobrien// invalidate any other reasons why the executable file might be covered by 2897403Sobrien// the GNU General Public License. 2997403Sobrien 3097403Sobrien// 3197403Sobrien// ISO C++ 14882: 22.2.4.1.2 collate virtual functions 3297403Sobrien// 3397403Sobrien 3497403Sobrien// Written by Benjamin Kosnik <bkoz@redhat.com> 3597403Sobrien 3697403Sobrien#include <locale> 3797403Sobrien 38169691Skan_GLIBCXX_BEGIN_NAMESPACE(std) 39169691Skan 4097403Sobrien // These are basically extensions to char_traits, and perhaps should 4197403Sobrien // be put there instead of here. 4297403Sobrien template<> 4397403Sobrien int 4497403Sobrien collate<char>::_M_compare(const char* __one, const char* __two) const 4597403Sobrien { 4697403Sobrien int __cmp = strcoll(__one, __two); 4797403Sobrien return (__cmp >> (8 * sizeof (int) - 2)) | (__cmp != 0); 4897403Sobrien } 4997403Sobrien 5097403Sobrien template<> 5197403Sobrien size_t 5297403Sobrien collate<char>::_M_transform(char* __to, const char* __from, 5397403Sobrien size_t __n) const 5497403Sobrien { return strxfrm(__to, __from, __n); } 5597403Sobrien 56132720Skan#ifdef _GLIBCXX_USE_WCHAR_T 5797403Sobrien template<> 5897403Sobrien int 5997403Sobrien collate<wchar_t>::_M_compare(const wchar_t* __one, 6097403Sobrien const wchar_t* __two) const 6197403Sobrien { 6297403Sobrien int __cmp = wcscoll(__one, __two); 6397403Sobrien return (__cmp >> (8 * sizeof (int) - 2)) | (__cmp != 0); 6497403Sobrien } 6597403Sobrien 6697403Sobrien template<> 6797403Sobrien size_t 6897403Sobrien collate<wchar_t>::_M_transform(wchar_t* __to, const wchar_t* __from, 6997403Sobrien size_t __n) const 7097403Sobrien { return wcsxfrm(__to, __from, __n); } 7197403Sobrien#endif 72169691Skan 73169691Skan_GLIBCXX_END_NAMESPACE 74