File: IdentityCodingSystem.cxx

package info (click to toggle)
opensp 1.5.2-15.2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,168 kB
  • sloc: cpp: 65,784; ansic: 17,124; sh: 11,193; xml: 2,704; makefile: 895; perl: 561; yacc: 288; sed: 16
file content (83 lines) | stat: -rw-r--r-- 1,646 bytes parent folder | download | duplicates (22)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 1994 James Clark
// See the file COPYING for copying permission.

#include "splib.h"
#include "IdentityCodingSystem.h"
#include <limits.h>

#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif

class IdentityDecoder : public Decoder {
public:
  size_t decode(Char *to, const char *from, size_t fromLen,
		const char **rest);
  Boolean convertOffset(unsigned long &offset) const;
};

class IdentityEncoder : public RecoveringEncoder {
public:
  IdentityEncoder();
  void output(const Char *, size_t, OutputByteStream *);
};

IdentityCodingSystem::IdentityCodingSystem()
{
}

Decoder *IdentityCodingSystem::makeDecoder() const
{
  return new IdentityDecoder;
}

Encoder *IdentityCodingSystem::makeEncoder() const
{
  return new IdentityEncoder;
}

Boolean IdentityCodingSystem::isIdentity() const
{
  return 1;
}

size_t IdentityDecoder::decode(Char *to, const char *from, size_t fromLen,
			       const char **rest)
{
  if (sizeof(Char) == sizeof(char) && from == (char *)to) {
    *rest = from + fromLen;
    return fromLen;
  }
  for (size_t n = fromLen; n > 0; n--)
    *to++ = (unsigned char)*from++; // zero extend
  *rest = from;
  return fromLen;
}

Boolean IdentityDecoder::convertOffset(unsigned long &) const
{
  return true;
}

IdentityEncoder::IdentityEncoder()
{
}

void IdentityEncoder::output(const Char *s, size_t n, OutputByteStream *sb)
{
  if (sizeof(Char) != sizeof(char)) {
    for (size_t i = 0; i < n; i++) {
      Char c = s[i];
      if (c > UCHAR_MAX)
	handleUnencodable(c, sb);
      else
	sb->sputc((unsigned char)c);
    }
  }
  else
    sb->sputn((const char *)s, n);
}

#ifdef SP_NAMESPACE
}
#endif