Latin1Codec.h
1/*
2 * Copyright (C) 2020 by Marc Boris Duerner
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * As a special exception, you may use this file as part of a free
10 * software library without restriction. Specifically, if other files
11 * instantiate templates or use macros or inline functions from this
12 * file, or you compile this file and link it with other files to
13 * produce an executable, this file does not by itself cause the
14 * resulting executable to be covered by the GNU General Public
15 * License. This exception does not however invalidate any other
16 * reasons why the executable file might be covered by the GNU Library
17 * General Public License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 * MA 02110-1301 USA
28 */
29
30#ifndef PT_LATIN1CODEC_H
31#define PT_LATIN1CODEC_H
32
33#include <Pt/Api.h>
34#include <Pt/TextCodec.h>
35
36namespace Pt {
37
40class PT_API Latin1Codec : public Pt::TextCodec<Pt::Char, char>
41{
42 public:
44 explicit Latin1Codec(std::size_t ref = 0);
45
47 virtual ~Latin1Codec();
48
49 // inheritdoc
50 virtual result do_in(Pt::MBState& s,
51 const char* from, const char* fromEnd, const char*& fromNext,
52 Pt::Char* to, Pt::Char* toEnd, Pt::Char*& toNext) const;
53
54 // inheritdoc
55 virtual result do_out(Pt::MBState& s, const Pt::Char* fromBegin,
56 const Pt::Char* fromEnd, const Pt::Char*& fromNext,
57 char* toBegin, char* toEnd, char*& toNext) const;
58
59 // inheritdoc
60 virtual bool do_always_noconv() const throw()
61 { return false; }
62
63 // inheritdoc
64 virtual int do_length(Pt::MBState& s, const char* fromBegin,
65 const char* fromEnd, std::size_t max) const
66 {
67 std::size_t avail = fromEnd - fromBegin;
68 return avail < max ? avail : max;
69 }
70
71 // inheritdoc
72 virtual int do_max_length() const throw()
73 { return 1; }
74
75 // inheritdoc
76 std::codecvt_base::result do_unshift(Pt::MBState&, char*, char*, char*&) const
77 { return std::codecvt_base::noconv; }
78
79 // inheritdoc
80 int do_encoding() const throw()
81 { return 1; }
82};
83
84} // namespace
85
86#endif
virtual ~Latin1Codec()
Destructor.
Latin1Codec(std::size_t ref=0)
Constructor.
Converts between character encodings.
Definition Api-TextCodec.h:44
Core module.
Definition Allocator.h:33
Unicode character type.
Definition String.h:67