SNAP Library 2.1, User Reference  2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
T8BitCodec< TEncoding_ > Class Template Reference

#include <unicode.h>

List of all members.

Public Types

typedef TEncoding_ TEncoding

Public Member Functions

 T8BitCodec ()
 T8BitCodec (TUnicodeErrorHandling errorHandling_, int replacementChar_=TUniCodec::DefaultReplacementChar)
void Test () const
template<typename TSrcVec , typename TDestCh >
size_t ToUnicode (const TSrcVec &src, size_t srcIdx, const size_t srcCount, TVec< TDestCh > &dest, const bool clrDest=true) const
template<typename TSrcVec , typename TDestCh >
size_t ToUnicode (const TSrcVec &src, TVec< TDestCh > &dest, const bool clrDest=true) const
size_t ToUnicode (const TIntV &src, TIntV &dest, const bool clrDest=true) const
size_t ToUnicode (const TStr &src, TIntV &dest, const bool clrDest=true) const
template<typename TSrcVec , typename TDestVec >
size_t FromUnicode (const TSrcVec &src, size_t srcIdx, const size_t srcCount, TDestVec &dest, const bool clrDest=true) const
template<typename TSrcVec , typename TDestVec >
size_t FromUnicode (const TSrcVec &src, TDestVec &dest, const bool clrDest=true) const
size_t UniToStr (const TIntV &src, size_t srcIdx, const size_t srcCount, TStr &dest, const bool clrDest=true) const
size_t UniToStr (const TIntV &src, TStr &dest, const bool clrDest=true) const

Static Public Member Functions

static TStr GetName ()

Public Attributes

TUnicodeErrorHandling errorHandling
int replacementChar

Protected Types

typedef TUniVecIdx TVecIdx

Detailed Description

template<class TEncoding_>
class T8BitCodec< TEncoding_ >

Definition at line 561 of file unicode.h.


Member Typedef Documentation

template<class TEncoding_>
typedef TEncoding_ T8BitCodec< TEncoding_ >::TEncoding

Definition at line 566 of file unicode.h.

template<class TEncoding_>
typedef TUniVecIdx T8BitCodec< TEncoding_ >::TVecIdx [protected]

Definition at line 564 of file unicode.h.


Constructor & Destructor Documentation

template<class TEncoding_>
T8BitCodec< TEncoding_ >::T8BitCodec ( ) [inline]
template<class TEncoding_>
T8BitCodec< TEncoding_ >::T8BitCodec ( TUnicodeErrorHandling  errorHandling_,
int  replacementChar_ = TUniCodec::DefaultReplacementChar 
) [inline]

Definition at line 571 of file unicode.h.

                                                                                                                 :
                errorHandling(errorHandling_), replacementChar(replacementChar_) { }

Member Function Documentation

template<class TEncoding_>
template<typename TSrcVec , typename TDestVec >
size_t T8BitCodec< TEncoding_ >::FromUnicode ( const TSrcVec &  src,
size_t  srcIdx,
const size_t  srcCount,
TDestVec &  dest,
const bool  clrDest = true 
) const [inline]

Definition at line 618 of file unicode.h.

        {
                typedef typename TVecElt<TDestVec>::TElement TDestCh;
                if (clrDest) dest.Clr();
                size_t toDo = srcCount, nEncoded = 0;
                while (toDo-- > 0) {
                        int chSrc = (int) src[TVecIdx(srcIdx)]; srcIdx++;
                        int chDest = TEncoding::FromUnicode(chSrc);
                        if (chDest < 0) {
                                switch (errorHandling) {
                                case uehThrow: throw TUnicodeException(srcIdx - 1, chSrc, "Invalid character for encoding into " + GetName() + ".");
                                case uehAbort: return nEncoded;
                                case uehReplace: TVecElt<TDestVec>::Add(dest, TDestCh(replacementChar)); continue;
                                case uehIgnore: continue;
                                default: Fail; } }
                        TVecElt<TDestVec>::Add(dest, TDestCh(chDest)); nEncoded++; }
                return nEncoded;
        }
template<class TEncoding_>
template<typename TSrcVec , typename TDestVec >
size_t T8BitCodec< TEncoding_ >::FromUnicode ( const TSrcVec &  src,
TDestVec &  dest,
const bool  clrDest = true 
) const [inline]

Definition at line 640 of file unicode.h.

{ return FromUnicode(src, 0, src.Len(), dest, clrDest); }
template<class TEncoding_>
static TStr T8BitCodec< TEncoding_ >::GetName ( ) [inline, static]

Definition at line 573 of file unicode.h.

{ return TEncoding::GetName(); }
template<class TEncoding_>
void T8BitCodec< TEncoding_ >::Test ( ) const [inline]

Definition at line 575 of file unicode.h.

        {
                int nDecoded = 0;
                for (int c = 0; c <= 255; c++) {
                        int cu = TEncoding::ToUnicode(c); if (cu == -1) continue;
                        nDecoded++;
                        IAssert(0 <= cu && cu < 0x110000);
                        int c2 = TEncoding::FromUnicode(cu);
                        IAssert(c2 == c); }
                int nEncoded = 0;
                for (int cu = 0; cu < 0x110000; cu++) {
                        int c = TEncoding::FromUnicode(cu); if (c == -1) continue;
                        nEncoded++;
                        IAssert(0 <= c && c <= 255);
                        int cu2 = TEncoding::ToUnicode(c);
                        IAssert(cu2 == cu); }
                IAssert(nDecoded == nEncoded);
        }
template<class TEncoding_>
template<typename TSrcVec , typename TDestCh >
size_t T8BitCodec< TEncoding_ >::ToUnicode ( const TSrcVec &  src,
size_t  srcIdx,
const size_t  srcCount,
TVec< TDestCh > &  dest,
const bool  clrDest = true 
) const [inline]

Definition at line 597 of file unicode.h.

        {
                if (clrDest) dest.Clr();
                size_t toDo = srcCount;
                while (toDo-- > 0) {
                        int chSrc = ((int) src[TVecIdx(srcIdx)]) & 0xff; srcIdx++;
                        int chDest = TEncoding::ToUnicode(chSrc);
                        dest.Add(chDest); }
                return srcCount;
        }
template<class TEncoding_>
template<typename TSrcVec , typename TDestCh >
size_t T8BitCodec< TEncoding_ >::ToUnicode ( const TSrcVec &  src,
TVec< TDestCh > &  dest,
const bool  clrDest = true 
) const [inline]

Definition at line 610 of file unicode.h.

{ return ToUnicode(src, 0, src.Len(), dest, clrDest); }
template<class TEncoding_>
size_t T8BitCodec< TEncoding_ >::ToUnicode ( const TIntV src,
TIntV dest,
const bool  clrDest = true 
) const [inline]

Definition at line 612 of file unicode.h.

{ return ToUnicode(src, 0, src.Len(), dest, clrDest); }
template<class TEncoding_>
size_t T8BitCodec< TEncoding_ >::ToUnicode ( const TStr src,
TIntV dest,
const bool  clrDest = true 
) const [inline]

Definition at line 613 of file unicode.h.

{ return ToUnicode(src, 0, src.Len(), dest, clrDest); }
template<class TEncoding_>
size_t T8BitCodec< TEncoding_ >::UniToStr ( const TIntV src,
size_t  srcIdx,
const size_t  srcCount,
TStr dest,
const bool  clrDest = true 
) const [inline]

Definition at line 642 of file unicode.h.

                                                                                                                             {
                TChA buf; size_t retVal = FromUnicode(src, srcIdx, srcCount, buf, false);
                if (clrDest) dest += buf.CStr(); else dest = buf.CStr();
                return retVal; }
template<class TEncoding_>
size_t T8BitCodec< TEncoding_ >::UniToStr ( const TIntV src,
TStr dest,
const bool  clrDest = true 
) const [inline]

Definition at line 646 of file unicode.h.

{ return UniToStr(src, 0, src.Len(), dest, clrDest); }

Member Data Documentation

template<class TEncoding_>
TUnicodeErrorHandling T8BitCodec< TEncoding_ >::errorHandling

Definition at line 567 of file unicode.h.

template<class TEncoding_>
int T8BitCodec< TEncoding_ >::replacementChar

Definition at line 568 of file unicode.h.


The documentation for this class was generated from the following file: