Switch to unified view

a b/src/bincimapmime/convert.cc
1
/* -*- Mode: c++; -*- */
2
/*  --------------------------------------------------------------------
3
 *  Filename:
4
 *    convert.cc
5
 *  
6
 *  Description:
7
 *    Implementation of miscellaneous convertion functions.
8
 *  --------------------------------------------------------------------
9
 *  Copyright 2002-2004 Andreas Aardal Hanssen
10
 *
11
 *  This program is free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU General Public License
22
 *  along with this program; if not, write to the Free Software
23
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
24
 *  --------------------------------------------------------------------
25
 */
26
#ifdef HAVE_CONFIG_H
27
#include <config.h>
28
#endif
29
30
#include "convert.h"
31
#include <string>
32
33
using namespace ::std;
34
using namespace Binc;
35
36
//------------------------------------------------------------------------
37
BincStream::BincStream(void)
38
{
39
}
40
41
//------------------------------------------------------------------------
42
BincStream::~BincStream(void)
43
{
44
  clear();
45
}
46
47
//------------------------------------------------------------------------
48
string BincStream::popString(unsigned int size)
49
{
50
  if (size > nstr.length())
51
    size = nstr.length();
52
  string tmp = nstr.substr(0, size);
53
  nstr = nstr.substr(size);
54
  return tmp;
55
}
56
57
//------------------------------------------------------------------------
58
char BincStream::popChar(void)
59
{
60
  if (nstr.length() == 0)
61
    return '\0';
62
63
  char c = nstr[0];
64
  nstr = nstr.substr(1);
65
  return c;
66
}
67
68
//------------------------------------------------------------------------
69
void BincStream::unpopChar(char c)
70
{
71
  nstr = c + nstr;
72
}
73
74
//------------------------------------------------------------------------
75
void BincStream::unpopStr(const string &s)
76
{
77
  nstr = s + nstr;
78
}
79
80
//------------------------------------------------------------------------
81
const string &BincStream::str(void) const
82
{
83
  return nstr;
84
}
85
86
//------------------------------------------------------------------------
87
void BincStream::clear(void)
88
{
89
  nstr = "";
90
}
91
92
//------------------------------------------------------------------------
93
unsigned int BincStream::getSize(void) const
94
{
95
  return (unsigned int) nstr.length();
96
}
97
98
//------------------------------------------------------------------------
99
BincStream &BincStream::operator << (std::ostream&(*)(std::ostream&))
100
{
101
  nstr += "\r\n";
102
  return *this;
103
}
104
105
//------------------------------------------------------------------------
106
BincStream &BincStream::operator << (const string &t)
107
{
108
  nstr += t;
109
  return *this;
110
}
111
112
//------------------------------------------------------------------------
113
BincStream &BincStream::operator << (int t)
114
{
115
  nstr += toString(t);
116
  return *this;
117
}
118
119
//------------------------------------------------------------------------
120
BincStream &BincStream::operator << (unsigned int t)
121
{
122
  nstr += toString(t);
123
  return *this;
124
}
125
126
//------------------------------------------------------------------------
127
BincStream &BincStream::operator << (char t)
128
{
129
  nstr += t;
130
  return *this;
131
}