SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
T8BitCodec< TEncoding_ > Class Template Reference

#include <unicode.h>

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

Definition at line 570 of file unicode.h.

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

Definition at line 571 of file unicode.h.

571  :
572  errorHandling(errorHandling_), replacementChar(replacementChar_) { }
int replacementChar
Definition: unicode.h:568
TUnicodeErrorHandling errorHandling
Definition: unicode.h:567

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.

621  {
622  typedef typename TVecElt<TDestVec>::TElement TDestCh;
623  if (clrDest) dest.Clr();
624  size_t toDo = srcCount, nEncoded = 0;
625  while (toDo-- > 0) {
626  int chSrc = (int) src[TVecIdx(srcIdx)]; srcIdx++;
627  int chDest = TEncoding::FromUnicode(chSrc);
628  if (chDest < 0) {
629  switch (errorHandling) {
630  case uehThrow: throw TUnicodeException(srcIdx - 1, chSrc, "Invalid character for encoding into " + GetName() + ".");
631  case uehAbort: return nEncoded;
632  case uehReplace: TVecElt<TDestVec>::Add(dest, TDestCh(replacementChar)); continue;
633  case uehIgnore: continue;
634  default: Fail; } }
635  TVecElt<TDestVec>::Add(dest, TDestCh(chDest)); nEncoded++; }
636  return nEncoded;
637  }
#define Fail
Definition: bd.h:238
int replacementChar
Definition: unicode.h:568
TUniVecIdx TVecIdx
Definition: unicode.h:564
static TStr GetName()
Definition: unicode.h:573
TUnicodeErrorHandling errorHandling
Definition: unicode.h:567
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.

640 { return FromUnicode(src, 0, src.Len(), dest, clrDest); }
size_t FromUnicode(const TSrcVec &src, size_t srcIdx, const size_t srcCount, TDestVec &dest, const bool clrDest=true) const
Definition: unicode.h:618
template<class TEncoding_>
static TStr T8BitCodec< TEncoding_ >::GetName ( )
inlinestatic

Definition at line 573 of file unicode.h.

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

Definition at line 575 of file unicode.h.

576  {
577  int nDecoded = 0;
578  for (int c = 0; c <= 255; c++) {
579  int cu = TEncoding::ToUnicode(c); if (cu == -1) continue;
580  nDecoded++;
581  IAssert(0 <= cu && cu < 0x110000);
582  int c2 = TEncoding::FromUnicode(cu);
583  IAssert(c2 == c); }
584  int nEncoded = 0;
585  for (int cu = 0; cu < 0x110000; cu++) {
586  int c = TEncoding::FromUnicode(cu); if (c == -1) continue;
587  nEncoded++;
588  IAssert(0 <= c && c <= 255);
589  int cu2 = TEncoding::ToUnicode(c);
590  IAssert(cu2 == cu); }
591  IAssert(nDecoded == nEncoded);
592  }
#define IAssert(Cond)
Definition: bd.h:262
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.

600  {
601  if (clrDest) dest.Clr();
602  size_t toDo = srcCount;
603  while (toDo-- > 0) {
604  int chSrc = ((int) src[TVecIdx(srcIdx)]) & 0xff; srcIdx++;
605  int chDest = TEncoding::ToUnicode(chSrc);
606  dest.Add(chDest); }
607  return srcCount;
608  }
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
TUniVecIdx TVecIdx
Definition: unicode.h:564
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
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.

610 { return ToUnicode(src, 0, src.Len(), dest, clrDest); }
size_t ToUnicode(const TSrcVec &src, size_t srcIdx, const size_t srcCount, TVec< TDestCh > &dest, const bool clrDest=true) const
Definition: unicode.h:597
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.

612 { return ToUnicode(src, 0, src.Len(), dest, clrDest); }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
size_t ToUnicode(const TSrcVec &src, size_t srcIdx, const size_t srcCount, TVec< TDestCh > &dest, const bool clrDest=true) const
Definition: unicode.h:597
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.

613 { return ToUnicode(src, 0, src.Len(), dest, clrDest); }
int Len() const
Definition: dt.h:490
size_t ToUnicode(const TSrcVec &src, size_t srcIdx, const size_t srcCount, TVec< TDestCh > &dest, const bool clrDest=true) const
Definition: unicode.h:597
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.

642  {
643  TChA buf; size_t retVal = FromUnicode(src, srcIdx, srcCount, buf, false);
644  if (clrDest) dest += buf.CStr(); else dest = buf.CStr();
645  return retVal; }
size_t FromUnicode(const TSrcVec &src, size_t srcIdx, const size_t srcCount, TDestVec &dest, const bool clrDest=true) const
Definition: unicode.h:618
char * CStr()
Definition: dt.h:255
Definition: dt.h:201
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.

646 { return UniToStr(src, 0, src.Len(), dest, clrDest); }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
size_t UniToStr(const TIntV &src, size_t srcIdx, const size_t srcCount, TStr &dest, const bool clrDest=true) const
Definition: unicode.h:642

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: