textwolf  0.2
charset_isolatin.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
10 
11 #ifndef __TEXTWOLF_CHARSET_ISOLATIN_HPP__
12 #define __TEXTWOLF_CHARSET_ISOLATIN_HPP__
13 #include "textwolf/char.hpp"
15 #include "textwolf/exception.hpp"
16 #include "textwolf/codepages.hpp"
17 #include <cstddef>
18 
19 namespace textwolf {
20 namespace charset {
21 
24 struct IsoLatin :public IsoLatinCodePage
25 {
26  enum {MaxChar=0xFFU};
27 
28  IsoLatin( const IsoLatin& o)
29  :IsoLatinCodePage(o){}
30  IsoLatin( unsigned int codePageIdx=1)
31  :IsoLatinCodePage(codePageIdx){}
32 
34  template <class Iterator>
35  static inline void skip( char*, unsigned int& bufpos, Iterator& itr)
36  {
37  if (bufpos==0)
38  {
39  ++itr;
40  ++bufpos;
41  }
42  }
43 
45  template <class Iterator>
46  static inline void fetchbytes( char* buf, unsigned int& bufpos, Iterator& itr)
47  {
48  if (bufpos==0)
49  {
50  buf[0] = *itr;
51  ++itr;
52  ++bufpos;
53  }
54  }
55 
57  template <class Iterator>
58  static inline signed char asciichar( char* buf, unsigned int& bufpos, Iterator& itr)
59  {
60  fetchbytes( buf, bufpos, itr);
61  return ((unsigned char)(buf[0])>127)?-1:buf[0];
62  }
63 
65  template <class Iterator>
66  inline UChar value( char* buf, unsigned int& bufpos, Iterator& itr) const
67  {
68  fetchbytes( buf, bufpos, itr);
69  return ucharcode( buf[0]);
70  }
71 
73  template <class Buffer_>
74  void print( UChar chr, Buffer_& buf) const
75  {
76  char chr_ = invcode( chr);
77  if (chr_ == 0)
78  {
79  char tb[ 32];
80  char* cc = tb;
81  Encoder::encode( chr, tb, sizeof(tb));
82  while (*cc) buf.push_back( *cc++);
83  }
84  else
85  {
86  buf.push_back( chr_);
87  }
88  }
89 
91  static inline bool is_equal( const IsoLatin& a, const IsoLatin& b)
92  {
93  return IsoLatinCodePage::is_equal( a, b);
94  }
95 };
96 
97 }//namespace
98 }//namespace
99 #endif
UChar value(char *buf, unsigned int &bufpos, Iterator &itr) const
See template<class Iterator>Interface::value(char*,unsigned int&,Iterator&)
Definition: charset_isolatin.hpp:66
UChar ucharcode(char ch) const
Get the unicode character representation of the character ch in this codepage.
Definition: codepages.hpp:119
static bool is_equal(const IsoLatinCodePage &a, const IsoLatinCodePage &b)
Evaluate if two code pages are equal.
Definition: codepages.hpp:144
IsoLatin(unsigned int codePageIdx=1)
Definition: charset_isolatin.hpp:30
static bool encode(UChar chr, char *bufptr, std::size_t bufsize)
Write the character 'chr' in encoded form as nul-terminated string to a buffer.
Definition: charset_interface.hpp:29
static void fetchbytes(char *buf, unsigned int &bufpos, Iterator &itr)
See template<class Iterator>Interface::fetchbytes(char*,unsigned int&,Iterator&)
Definition: charset_isolatin.hpp:46
char invcode(UChar ch) const
Get the character representation of a unicode character in this codepage.
Definition: codepages.hpp:128
uint32_t UChar
Unicode character type.
Definition: char.hpp:37
Character set IsoLatin-1,..IsoLatin-9 (ISO-8859-1,...ISO-8859-9)
Definition: charset_isolatin.hpp:24
Definition of unicode characters.
IsoLatin(const IsoLatin &o)
Definition: charset_isolatin.hpp:28
static signed char asciichar(char *buf, unsigned int &bufpos, Iterator &itr)
See template<class Iterator>Interface::asciichar(char*,unsigned int&,Iterator&)
Definition: charset_isolatin.hpp:58
Interface that describes what a character set encoding implementation has to define to be used as cha...
Definition of exceptions with containing error codes thrown by textwolf.
IsoLatin code page.
Definition: codepages.hpp:22
static bool is_equal(const IsoLatin &a, const IsoLatin &b)
See template<class Buffer>Interface::is_equal( const Interface&, const Interface&) ...
Definition: charset_isolatin.hpp:91
void print(UChar chr, Buffer_ &buf) const
See template<class Buffer>Interface::print(UChar,Buffer&)
Definition: charset_isolatin.hpp:74
Definition: charset_isolatin.hpp:26
static void skip(char *, unsigned int &bufpos, Iterator &itr)
See template<class Iterator>Interface::skip(char*,unsigned int&,Iterator&)
Definition: charset_isolatin.hpp:35
Definition of IsoLatin code pages.