"Fossies" - the Fresh Open Source Software Archive

Member "OpenSP-1.5.2/lib/IdentityCodingSystem.cxx" (21 Jul 2005, 1646 Bytes) of package /linux/misc/old/OpenSP-1.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "IdentityCodingSystem.cxx" see the Fossies "Dox" file reference documentation.

    1 // Copyright (c) 1994 James Clark
    2 // See the file COPYING for copying permission.
    3 
    4 #include "splib.h"
    5 #include "IdentityCodingSystem.h"
    6 #include <limits.h>
    7 
    8 #ifdef SP_NAMESPACE
    9 namespace SP_NAMESPACE {
   10 #endif
   11 
   12 class IdentityDecoder : public Decoder {
   13 public:
   14   size_t decode(Char *to, const char *from, size_t fromLen,
   15         const char **rest);
   16   Boolean convertOffset(unsigned long &offset) const;
   17 };
   18 
   19 class IdentityEncoder : public RecoveringEncoder {
   20 public:
   21   IdentityEncoder();
   22   void output(const Char *, size_t, OutputByteStream *);
   23 };
   24 
   25 IdentityCodingSystem::IdentityCodingSystem()
   26 {
   27 }
   28 
   29 Decoder *IdentityCodingSystem::makeDecoder() const
   30 {
   31   return new IdentityDecoder;
   32 }
   33 
   34 Encoder *IdentityCodingSystem::makeEncoder() const
   35 {
   36   return new IdentityEncoder;
   37 }
   38 
   39 Boolean IdentityCodingSystem::isIdentity() const
   40 {
   41   return 1;
   42 }
   43 
   44 size_t IdentityDecoder::decode(Char *to, const char *from, size_t fromLen,
   45                    const char **rest)
   46 {
   47   if (sizeof(Char) == sizeof(char) && from == (char *)to) {
   48     *rest = from + fromLen;
   49     return fromLen;
   50   }
   51   for (size_t n = fromLen; n > 0; n--)
   52     *to++ = (unsigned char)*from++; // zero extend
   53   *rest = from;
   54   return fromLen;
   55 }
   56 
   57 Boolean IdentityDecoder::convertOffset(unsigned long &) const
   58 {
   59   return true;
   60 }
   61 
   62 IdentityEncoder::IdentityEncoder()
   63 {
   64 }
   65 
   66 void IdentityEncoder::output(const Char *s, size_t n, OutputByteStream *sb)
   67 {
   68   if (sizeof(Char) != sizeof(char)) {
   69     for (size_t i = 0; i < n; i++) {
   70       Char c = s[i];
   71       if (c > UCHAR_MAX)
   72     handleUnencodable(c, sb);
   73       else
   74     sb->sputc((unsigned char)c);
   75     }
   76   }
   77   else
   78     sb->sputn((const char *)s, n);
   79 }
   80 
   81 #ifdef SP_NAMESPACE
   82 }
   83 #endif