Api-TextCodec.h
1/* Copyright (C) 2008 Marc Boris Duerner
2 SPDX-License-Identifier: LGPL-2.1-or-later WITH mif-exception
3*/
4
5#ifndef PT_API_TEXTCODEC_H
6#define PT_API_TEXTCODEC_H
7
8#include <Pt/Api.h>
9#include <Pt/Locale.h>
10#include <Pt/String.h>
11
12namespace Pt {
13
42template <typename CharT, typename ByteT>
43class TextCodec : public std::codecvt<T, B, Pt::MBState>
44{
45 public:
47 typedef CharT intern_type;
48
50 typedef ByteT extern_type;
51
53 typedef MBState state_type;
54
55 public:
61 TextCodec(std::size_t ref = 0);
62
64 result in(MBState& s,
65 const ByteT* fbeg, const ByteT* fend, const ByteT*& fnext,
66 CharT* tbeg, CharT* tend, CharT*& tnext) const;
67
69 result out(MBState& state,
70 const CharT* fbeg, const CharT* fend, const CharT*& fnext,
71 ByteT* tbeg, ByteT* tend, ByteT*& tnext) const;
72
74 result unshift(MBState& state,
75 ByteT* to, ByteT* to_end, ByteT*& to_next) const;
76
78 int encoding() const;
79
81 bool always_noconv() const;
82
84 int length(MBState& state,
85 const ByteT* from, const ByteT* end, std::size_t max) const;
86
88 int max_length() const;
89
90 public:
92 virtual ~TextCodec()
93 {}
94
96 std::size_t refs() const
97 { return _refs; }
98
99 private:
100 std::size_t _refs;
101};
102
103}
104
105#endif
MBState state_type
Conversion state type.
Definition Api-TextCodec.h:53
result unshift(MBState &state, ByteT *to, ByteT *to_end, ByteT *&to_next) const
Unshifts a character sequence.
int length(MBState &state, const ByteT *from, const ByteT *end, std::size_t max) const
Returns the number of the decoded characters.
int encoding() const
Returns the encoding rate.
CharT intern_type
Internal character type.
Definition Api-TextCodec.h:47
result in(MBState &s, const ByteT *fbeg, const ByteT *fend, const ByteT *&fnext, CharT *tbeg, CharT *tend, CharT *&tnext) const
Decodes a character sequence.
TextCodec(std::size_t ref=0)
Constructs with reference count.
bool always_noconv() const
Returns true if no conversion is required.
result out(MBState &state, const CharT *fbeg, const CharT *fend, const CharT *&fnext, ByteT *tbeg, ByteT *tend, ByteT *&tnext) const
Encodes a character sequence.
int max_length() const
Maximum length of an external sequence if one character is encoded.
virtual ~TextCodec()
Desctructor.
Definition Api-TextCodec.h:92
ByteT extern_type
External character type.
Definition Api-TextCodec.h:50
Core module.
Definition Allocator.h:33