1
/***************************************************************************
2
copyright : (C) 2002-2005 by Stefano Barbato
3
email : stefano@codesink.org
5
$Id: other_codecs.h,v 1.12 2005/02/23 10:26:15 tat Exp $
6
***************************************************************************/
8
/***************************************************************************
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. *
15
***************************************************************************/
16
#ifndef _MIMETIC_CODEC_OTHER_CODECS_H_
17
#define _MIMETIC_CODEC_OTHER_CODECS_H_
18
#include <mimetic/codec/codec_base.h>
23
/// Pass through codec. Copies input to output
28
struct NullCodec: public unbuffered_codec, public chainable_codec<NullCodec>
30
template<typename OutIt>
31
void process(char c, OutIt& out)
35
const char* name() const
41
/// Converts input chars to upper case
46
struct ToUpperCase: public unbuffered_codec, public chainable_codec<ToUpperCase>
48
template<typename OutIt>
49
void process(char c, OutIt& out)
51
enum { offset = 'A' - 'a' };
52
if(c >= 'a' && c <= 'z')
57
const char* name() const
63
/// Converts input chars to lower case
68
struct ToLowerCase: public unbuffered_codec, public chainable_codec<ToLowerCase>
70
template<typename OutIt>
71
void process(char c, OutIt& out)
73
enum { offset = 'a' - 'A' };
74
if(c >= 'A' && c <= 'Z')
79
const char* name() const
86
/// Converts any LF (\\n) to CRLF (\\r\\n)
91
struct Lf2CrLf: public unbuffered_codec, public chainable_codec<Lf2CrLf>
93
template<typename OutIt>
94
void process(char c, OutIt& out)
96
enum { LF = 0xA, CR = 0xD };
104
const char* name() const
110
/// Inserts a new line if the input line is too long
115
struct MaxLineLen: public unbuffered_codec, public chainable_codec<MaxLineLen>
118
: m_max(0), m_written(0)
122
: m_max(m), m_written(0)
125
template<typename OutIt>
126
void process(char c, OutIt& out)
128
enum { cr = 0xD, lf = 0xA };
129
if(m_max && m_written++ == m_max)
138
const char* name() const
143
unsigned int m_max, m_written;
147
template<typename OutIt>
148
struct oiterator_wrapper:
149
public unbuffered_codec,
150
public chainable_codec<oiterator_wrapper<OutIt> >
152
oiterator_wrapper(): m_pOut(0)
155
oiterator_wrapper(OutIt& out): m_pOut(&out)
158
template<typename OutIt2>
159
void process(char c, OutIt2& out)
161
**m_pOut = c; ++(*m_pOut);
164
const char* name() const
166
return "oiterator_wrapper";