diff options
author | Benjamin Kosnik <bkoz@purist.soma.redhat.com> | 2000-08-16 04:12:51 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2000-08-16 04:12:51 +0000 |
commit | 63511623299e3fd5994f1f96d956e21bf380aa4f (patch) | |
tree | e19f71e078697043ffd4a59617c22e4290adf158 /libstdc++-v3/src/codecvt.cc | |
parent | fec1ce0a00615fde6d338965a44ebc12db3e1be4 (diff) | |
download | gcc-63511623299e3fd5994f1f96d956e21bf380aa4f.tar.gz |
codecvt.h: New file.
2000-08-15 Benjamin Kosnik <bkoz@purist.soma.redhat.com>
* bits/codecvt.h: New file.
* src/codecvt.cc: New file.
* bits/std_locale.h: Add include here.
* src/Makefile.am (headers): Add codecvt.h
(sources): Add codecvt.cc.
* src/Makefile.in: Regenerate.
* bits/locale_facets.h (codecvt): Re-implement. Rename _Codecvt to
__codecvt_abstract_base in an attempt to point some light this way...
Move __enc_traits and codecvt bits to codecvt.h.
* src/locale-inst.cc: Remove codecvt<wchar_t, wchar_t, mbstate_t>
explicit instantiation. Separate out codecvt instantations, simplify.
* src/locale.cc: Move codecvt bits to codecvt.cc
From-SVN: r35737
Diffstat (limited to 'libstdc++-v3/src/codecvt.cc')
-rw-r--r-- | libstdc++-v3/src/codecvt.cc | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/libstdc++-v3/src/codecvt.cc b/libstdc++-v3/src/codecvt.cc new file mode 100644 index 00000000000..c456b00334e --- /dev/null +++ b/libstdc++-v3/src/codecvt.cc @@ -0,0 +1,186 @@ +// Copyright (C) 2000 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// Written by Benjamin Kosnik <bkoz@cygnus.com> + +#include <bits/std_locale.h> + +namespace std { + + locale::id codecvt<char, char, mbstate_t>::id; + + codecvt<char, char, mbstate_t>:: + codecvt(size_t __refs) + : __codecvt_abstract_base<char, char, mbstate_t>(__refs) + { } + + codecvt<char, char, mbstate_t>:: + ~codecvt() { } + + codecvt_base::result + codecvt<char, char, mbstate_t>:: + do_out(state_type& /*__state*/, const intern_type* __from, + const intern_type* __from_end, const intern_type*& __from_next, + extern_type* __to, extern_type* __to_end, + extern_type*& __to_next) const + { + size_t __sizefrom = __from_end - __from; + size_t __sizeto = __to_end - __to; + size_t __length = __sizefrom <= __sizeto ? __sizefrom : __sizeto; + memcpy(__to, __from, __length); + __from_next = __from; + __to_next = __to; + return noconv; + } + + codecvt_base::result + codecvt<char, char, mbstate_t>:: + do_unshift(state_type& /*__state*/, extern_type* __to, + extern_type* /*__to_limit*/, extern_type*& __to_next) const + { + __to_next = __to; + return noconv; + } + + codecvt_base::result + codecvt<char, char, mbstate_t>:: + do_in(state_type& /*__state*/, const extern_type* __from, + const extern_type* __from_end, const extern_type*& __from_next, + intern_type* __to, intern_type* __to_end, + intern_type*& __to_next) const + { + size_t __sizefrom = __from_end - __from; + size_t __sizeto = __to_end - __to; + size_t __length = __sizefrom <= __sizeto ? __sizefrom : __sizeto; + memcpy(__to, __from, __length); + __from_next = __from; + __to_next = __to; + return noconv; + } + + int + codecvt<char, char, mbstate_t>:: + do_encoding() const throw() { return 1; } + + bool + codecvt<char, char, mbstate_t>:: + do_always_noconv() const throw() { return true; } + + int + codecvt<char, char, mbstate_t>:: + do_length (const state_type& /*__state*/, const extern_type* __from, + const extern_type* __end, size_t __max) const + { return (__max < size_t(__end - __from)) ? __max : __end - __from; } + + int + codecvt<char, char, mbstate_t>:: + do_max_length() const throw() { return 1; } + + codecvt_byname<char, char, mbstate_t>:: + codecvt_byname(const char* /*__s*/, size_t __refs) + : codecvt<char, char, mbstate_t>(__refs) { } + + codecvt_byname<char, char, mbstate_t>:: + ~codecvt_byname() { } + +#ifdef _GLIBCPP_USE_WCHAR_T + locale::id codecvt<wchar_t, char, mbstate_t>::id; + + codecvt<wchar_t, char, mbstate_t>:: + codecvt(size_t __refs) + : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs) { } + + codecvt<wchar_t, char, mbstate_t>:: + ~codecvt() { } + + codecvt_base::result + codecvt<wchar_t, char, mbstate_t>:: + do_out(state_type& /*__state*/, const intern_type* __from, + const intern_type* __from_end, const intern_type*& __from_next, + extern_type* __to, extern_type* __to_limit, + extern_type*& __to_next) const + { + for (; __from < __from_end && __to < __to_limit; ++__from, ++__to) + *__to = static_cast<char>(*__from); + __from_next = __from; __to_next = __to; + return __from == __from_end ? ok : partial; + } + + codecvt_base::result + codecvt<wchar_t, char, mbstate_t>:: + do_unshift (state_type& /*__state*/, extern_type* __to, + extern_type* /*__to_limit*/, extern_type*& __to_next) const + { + __to_next = __to; + return noconv; + } + + codecvt_base::result + codecvt<wchar_t, char, mbstate_t>:: + do_in(state_type& /*__state*/, const extern_type* __from, + const extern_type* __from_end, const extern_type*& __from_next, + intern_type* __to, intern_type* __to_limit, + intern_type*& __to_next) const + { + for (; __from < __from_end && __to < __to_limit; ++__from, ++__to) + *__to = static_cast<wchar_t>(*__from); + __from_next = __from; + __to_next = __to; + return __from == __from_end ? ok : partial; + } + + int + codecvt<wchar_t, char, mbstate_t>:: + do_encoding() const throw() + { return 1; } + + bool + codecvt<wchar_t, char, mbstate_t>:: + do_always_noconv() const throw() + { return false; } + + int + codecvt<wchar_t, char, mbstate_t>:: + do_length(const state_type& /*__state*/, const extern_type* __from, + const extern_type* __end, size_t __max) const + { return (__max < size_t(__end - __from)) ? __max : __end - __from; } + + int + codecvt<wchar_t, char, mbstate_t>::do_max_length() const throw() + { return 1; } + + codecvt_byname<wchar_t, char, mbstate_t>:: + codecvt_byname(const char* /*__s*/, size_t __refs) + : codecvt<wchar_t, char, mbstate_t> (__refs) { } + + codecvt_byname<wchar_t, char, mbstate_t>:: + ~codecvt_byname() { } +#endif // _GLIBCPP_USE_WCHAR_T + +} // namespace std + + |