/[debian]/mimetic/branches/upstream/current/mimetic/codec/other_codecs.h
ViewVC logotype

Contents of /mimetic/branches/upstream/current/mimetic/codec/other_codecs.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (show annotations)
Sat Feb 25 16:49:20 2006 UTC (15 years, 6 months ago) by gregoa
File MIME type: text/plain
File size: 3995 byte(s)
[svn-inject] Installing original source of mimetic
1 /***************************************************************************
2 copyright : (C) 2002-2005 by Stefano Barbato
3 email : stefano@codesink.org
4
5 $Id: other_codecs.h,v 1.12 2005/02/23 10:26:15 tat Exp $
6 ***************************************************************************/
7
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16 #ifndef _MIMETIC_CODEC_OTHER_CODECS_H_
17 #define _MIMETIC_CODEC_OTHER_CODECS_H_
18 #include <mimetic/codec/codec_base.h>
19
20 namespace mimetic
21 {
22
23 /// Pass through codec. Copies input to output
24 /*!
25
26 \sa encode decode
27 */
28 struct NullCodec: public unbuffered_codec, public chainable_codec<NullCodec>
29 {
30 template<typename OutIt>
31 void process(char c, OutIt& out)
32 {
33 *out = c; ++out;
34 }
35 const char* name() const
36 {
37 return "NullCodec";
38 }
39 };
40
41 /// Converts input chars to upper case
42 /*!
43
44 \sa encode decode
45 */
46 struct ToUpperCase: public unbuffered_codec, public chainable_codec<ToUpperCase>
47 {
48 template<typename OutIt>
49 void process(char c, OutIt& out)
50 {
51 enum { offset = 'A' - 'a' };
52 if(c >= 'a' && c <= 'z')
53 c += offset;
54 *out = c;
55 ++out;
56 }
57 const char* name() const
58 {
59 return "ToUpperCase";
60 }
61 };
62
63 /// Converts input chars to lower case
64 /*!
65
66 \sa encode decode
67 */
68 struct ToLowerCase: public unbuffered_codec, public chainable_codec<ToLowerCase>
69 {
70 template<typename OutIt>
71 void process(char c, OutIt& out)
72 {
73 enum { offset = 'a' - 'A' };
74 if(c >= 'A' && c <= 'Z')
75 c += offset;
76 *out = c;
77 ++out;
78 }
79 const char* name() const
80 {
81 return "ToLowerCase";
82 }
83 };
84
85
86 /// Converts any LF (\\n) to CRLF (\\r\\n)
87 /*!
88
89 \sa encode decode
90 */
91 struct Lf2CrLf: public unbuffered_codec, public chainable_codec<Lf2CrLf>
92 {
93 template<typename OutIt>
94 void process(char c, OutIt& out)
95 {
96 enum { LF = 0xA, CR = 0xD };
97 if(c == LF)
98 {
99 *out = CR; ++out;
100 *out = LF; ++out;
101 } else
102 *out = c; ++out;
103 }
104 const char* name() const
105 {
106 return "Lf2CrLf";
107 }
108 };
109
110 /// Inserts a new line if the input line is too long
111 /*!
112
113 \sa encode decode
114 */
115 struct MaxLineLen: public unbuffered_codec, public chainable_codec<MaxLineLen>
116 {
117 MaxLineLen()
118 : m_max(0), m_written(0)
119 {
120 }
121 MaxLineLen(uint m)
122 : m_max(m), m_written(0)
123 {
124 }
125 template<typename OutIt>
126 void process(char c, OutIt& out)
127 {
128 enum { cr = 0xD, lf = 0xA };
129 if(m_max && m_written++ == m_max)
130 {
131 *out = cr; ++out;
132 *out = lf; ++out;
133 m_written = 1;
134 }
135 *out = c;
136 ++out;
137 }
138 const char* name() const
139 {
140 return "MaxLineLen";
141 }
142 private:
143 unsigned int m_max, m_written;
144 };
145
146 // internal
147 template<typename OutIt>
148 struct oiterator_wrapper:
149 public unbuffered_codec,
150 public chainable_codec<oiterator_wrapper<OutIt> >
151 {
152 oiterator_wrapper(): m_pOut(0)
153 {
154 }
155 oiterator_wrapper(OutIt& out): m_pOut(&out)
156 {
157 }
158 template<typename OutIt2>
159 void process(char c, OutIt2& out)
160 {
161 **m_pOut = c; ++(*m_pOut);
162 *out = c; ++out;
163 }
164 const char* name() const
165 {
166 return "oiterator_wrapper";
167 }
168 private:
169 OutIt* m_pOut;
170 };
171
172
173 }
174 #endif

  ViewVC Help
Powered by ViewVC 1.1.26