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
TChA Class Reference

#include <dt.h>

List of all members.

Public Member Functions

 TChA (const int &_MxBfL=256)
 TChA (const char *CStr)
 TChA (const char *CStr, const int &StrLen)
 TChA (const TChA &ChA)
 TChA (const TStr &Str)
 TChA (const TMem &Mem)
 ~TChA ()
 TChA (TSIn &SIn)
void Load (TSIn &SIn)
void Save (TSOut &SOut, const bool &SaveCompact=true) const
void LoadXml (const PXmlTok &XmlTok, const TStr &Nm)
void SaveXml (TSOut &SOut, const TStr &Nm) const
TChAoperator= (const TChA &ChA)
TChAoperator= (const TStr &Str)
TChAoperator= (const char *CStr)
bool operator== (const TChA &ChA) const
bool operator== (const char *_CStr) const
bool operator== (const char &Ch) const
bool operator!= (const TChA &ChA) const
bool operator!= (const char *_CStr) const
bool operator!= (const char &Ch) const
bool operator< (const TChA &ChA) const
TChAoperator+= (const TMem &Mem)
TChAoperator+= (const TChA &ChA)
TChAoperator+= (const TStr &Str)
TChAoperator+= (const char *CStr)
TChAoperator+= (const char &Ch)
char operator[] (const int &ChN) const
char & operator[] (const int &ChN)
int GetMemUsed () const
char * operator() ()
const char * operator() () const
char * CStr ()
const char * CStr () const
void Clr ()
int Len () const
bool Empty () const
void Ins (const int &BChN, const char *CStr)
void Del (const int &ChN)
void DelLastCh ()
void Push (const char &Ch)
char Pop ()
void Trunc ()
void Trunc (const int &_BfL)
void Reverse ()
void AddCh (const char &Ch, const int &MxLen=-1)
void AddChTo (const char &Ch, const int &ToChN)
void AddBf (char *NewBf, const int &BfS)
void PutCh (const int &ChN, const char &Ch)
char GetCh (const int &ChN) const
char LastCh () const
char LastLastCh () const
TChA GetSubStr (const int &BChN, const int &EChN) const
int CountCh (const char &Ch, const int &BChN=0) const
int SearchCh (const char &Ch, const int &BChN=0) const
int SearchChBack (const char &Ch, int BChN=-1) const
int SearchStr (const TChA &Str, const int &BChN=0) const
int SearchStr (const TStr &Str, const int &BChN=0) const
int SearchStr (const char *CStr, const int &BChN=0) const
bool IsStrIn (const TStr &Str) const
bool IsPrefix (const char *CStr, const int &BChN=0) const
bool IsPrefix (const TStr &Str) const
bool IsPrefix (const TChA &Str) const
bool IsSuffix (const char *CStr) const
bool IsSuffix (const TStr &Str) const
bool IsSuffix (const TChA &Str) const
bool IsChIn (const char &Ch) const
void ChangeCh (const char &SrcCh, const char &DstCh)
TChAToUc ()
TChAToLc ()
TChAToTrunc ()
void CompressWs ()
void Swap (const int &ChN1, const int &ChN2)
void Swap (TChA &ChA)
int GetPrimHashCd () const
int GetSecHashCd () const
void SaveTxt (const PSOut &SOut) const

Static Public Member Functions

static void LoadTxt (const PSIn &SIn, TChA &ChA)

Private Member Functions

void Resize (const int &_MxBfL)

Private Attributes

int MxBfL
int BfL
char * Bf

Detailed Description

Definition at line 201 of file dt.h.


Constructor & Destructor Documentation

TChA::TChA ( const int &  _MxBfL = 256) [inline, explicit]

Definition at line 207 of file dt.h.

                                      {
    Bf=new char[(MxBfL=_MxBfL)+1]; Bf[BfL=0]=0;}
TChA::TChA ( const char *  CStr) [inline]

Definition at line 209 of file dt.h.

                        {
    Bf=new char[(MxBfL=BfL=int(strlen(CStr)))+1]; strcpy(Bf, CStr);}
TChA::TChA ( const char *  CStr,
const int &  StrLen 
) [inline]

Definition at line 211 of file dt.h.

                                            : MxBfL(StrLen), BfL(StrLen) {
    Bf=new char[StrLen+1]; strncpy(Bf, CStr, StrLen); Bf[StrLen]=0;}
TChA::TChA ( const TChA ChA) [inline]

Definition at line 213 of file dt.h.

                       {
    Bf=new char[(MxBfL=ChA.MxBfL)+1]; BfL=ChA.BfL; strcpy(Bf, ChA.CStr());}
TChA::TChA ( const TStr Str)

Definition at line 356 of file dt.cpp.

                         {
  Bf=new char[(MxBfL=BfL=Str.Len())+1];
  strcpy(Bf, Str.CStr());
}
TChA::TChA ( const TMem Mem) [inline]

Definition at line 216 of file dt.h.

                       {
    Bf=new char[(MxBfL=BfL=Mem.Len())+1]; Bf[MxBfL]=0;
    memcpy(CStr(), Mem(), Mem.Len());}
TChA::~TChA ( ) [inline]

Definition at line 219 of file dt.h.

{delete[] Bf;}
TChA::TChA ( TSIn SIn) [inline, explicit]

Definition at line 220 of file dt.h.

                          {
    SIn.Load(MxBfL); SIn.Load(BfL); SIn.Load(Bf, MxBfL, BfL);}

Member Function Documentation

void TChA::AddBf ( char *  NewBf,
const int &  BfS 
) [inline]

Definition at line 275 of file dt.h.

                                         {
    if ((BfL+BfS+1)>MxBfL){Resize(BfL+BfS+1);}
    strncpy(Bf+BfL,NewBf,BfS); BfL+=BfS; Bf[BfL]=0;}
void TChA::AddCh ( const char &  Ch,
const int &  MxLen = -1 
) [inline]

Definition at line 271 of file dt.h.

                                                 {
    if ((MxLen==-1)||(BfL<MxLen)){operator+=(Ch);}}
void TChA::AddChTo ( const char &  Ch,
const int &  ToChN 
) [inline]

Definition at line 273 of file dt.h.

                                                {
    while (Len()<ToChN){AddCh(Ch);}}
void TChA::ChangeCh ( const char &  SrcCh,
const char &  DstCh 
)

Definition at line 537 of file dt.cpp.

                                                       {
  int StrLen=Len();
  for (int ChN=0; ChN<StrLen; ChN++){if (Bf[ChN]==SrcCh){Bf[ChN]=DstCh;}}
}
void TChA::Clr ( ) [inline]

Definition at line 258 of file dt.h.

{Bf[BfL=0]=0;}
void TChA::CompressWs ( )

Definition at line 581 of file dt.cpp.

                     {
  int StrLen=Len(); int SrcChN=0; int DstChN=0;
  while ((SrcChN<StrLen)&&TCh::IsWs(GetCh(SrcChN))){SrcChN++;}
  while (SrcChN<StrLen){
    if ((TCh::IsWs(GetCh(SrcChN)))&&(DstChN>0)&&(TCh::IsWs(GetCh(DstChN-1)))){
      SrcChN++;
    } else {
      PutCh(DstChN, GetCh(SrcChN)); SrcChN++; DstChN++;
    }
  }
  if ((DstChN>0)&&(TCh::IsWs(GetCh(DstChN-1)))){DstChN--;}
  Trunc(DstChN);
}
int TChA::CountCh ( const char &  Ch,
const int &  BChN = 0 
) const

Definition at line 462 of file dt.cpp.

                                                       {
  int ChN=TInt::GetMx(BChN, 0);
  const int ThisLen=Len();
  int Cnt = 0;
  while (ChN<ThisLen){if (Bf[ChN]==Ch){ Cnt++;} ChN++;}
  return Cnt;
}
char* TChA::CStr ( ) [inline]

Definition at line 255 of file dt.h.

{return Bf;}
const char* TChA::CStr ( ) const [inline]

Definition at line 256 of file dt.h.

{return Bf;}
void TChA::Del ( const int &  ChN)

Definition at line 414 of file dt.cpp.

                            {
  Assert((0<=ChN)&&(ChN<BfL));
  memmove(Bf+ChN, Bf+ChN+1, BfL-ChN);
  BfL--;
}
void TChA::DelLastCh ( ) [inline]

Definition at line 263 of file dt.h.

{Pop();}
bool TChA::Empty ( ) const [inline]

Definition at line 260 of file dt.h.

{return BfL==0;}
char TChA::GetCh ( const int &  ChN) const [inline]

Definition at line 280 of file dt.h.

{return operator[](ChN);}
int TChA::GetMemUsed ( ) const [inline]

Definition at line 251 of file dt.h.

{return int(2*sizeof(int)+sizeof(char*)+sizeof(char)*MxBfL);}
int TChA::GetPrimHashCd ( ) const

Definition at line 607 of file dt.cpp.

int TChA::GetSecHashCd ( ) const

Definition at line 611 of file dt.cpp.

TChA TChA::GetSubStr ( const int &  BChN,
const int &  EChN 
) const

Definition at line 448 of file dt.cpp.

                                                             {
  int BChN=TInt::GetMx(_BChN, 0);
  int EChN=TInt::GetMn(_EChN, Len()-1);
  int Chs=EChN-BChN+1;
  if (Chs<=0){return TStr::GetNullStr();}
  else if (Chs==Len()){return *this;}
  else {
    //char* Bf=new char[Chs+1]; strncpy(Bf, CStr()+BChN, Chs); Bf[Chs]=0;
    //TStr Str(Bf); delete[] Bf;
    //return Str;
    return TChA(CStr()+BChN, Chs);
  }
}
void TChA::Ins ( const int &  BChN,
const char *  CStr 
)

Definition at line 407 of file dt.cpp.

                                               {
  Assert((0<=BChN)&&(BChN<=BfL)); //** ali je <= v (BChN<=BfL) upravicen?
  int CStrLen=int(strlen(CStr)); Resize(BfL+CStrLen);
  memmove(Bf+BChN+CStrLen, Bf+BChN, BfL-BChN+1);
  memmove(Bf+BChN, CStr, CStrLen); BfL+=CStrLen;
}
bool TChA::IsChIn ( const char &  Ch) const [inline]

Definition at line 300 of file dt.h.

{return SearchCh(Ch)!=-1;}
bool TChA::IsPrefix ( const char *  CStr,
const int &  BChN = 0 
) const

Definition at line 499 of file dt.cpp.

                                                           {
  if (BChN+(int)strlen(CStr)>Len()){return false;}
  const char* B = Bf+BChN;
  const char* C = CStr;
  while (*C!=0 && *B==*C) {
    B++; C++;
  }
  if (*C==0){return true;}
  else {return false;}
}
bool TChA::IsPrefix ( const TStr Str) const

Definition at line 510 of file dt.cpp.

                                         {
  return IsPrefix(Str.CStr());
}
bool TChA::IsPrefix ( const TChA Str) const

Definition at line 514 of file dt.cpp.

                                         {
  return IsPrefix(Str.CStr());
}
bool TChA::IsStrIn ( const TStr Str) const [inline]

Definition at line 292 of file dt.h.

{return SearchStr(Str)!=-1;}
bool TChA::IsSuffix ( const char *  CStr) const

Definition at line 518 of file dt.cpp.

                                          {
  if ((int)strlen(CStr) > Len()) { return false; }
  const char* E = Bf+Len()-1;
  const char* C = CStr+strlen(CStr)-1;
  while (C >= CStr && *E==*C) {
    E--;  C--;
  }
  if (C+1 == CStr) { return true; }
  else { return false; }
}
bool TChA::IsSuffix ( const TStr Str) const

Definition at line 529 of file dt.cpp.

                                         {
  return IsSuffix(Str.CStr());
}
bool TChA::IsSuffix ( const TChA Str) const

Definition at line 533 of file dt.cpp.

                                         {
  return IsSuffix(Str.CStr());
}
char TChA::LastCh ( ) const [inline]

Definition at line 281 of file dt.h.

{ Assert(1<=BfL); return Bf[BfL-1]; }
char TChA::LastLastCh ( ) const [inline]

Definition at line 282 of file dt.h.

{ Assert(2<=BfL); return Bf[BfL-2]; }
int TChA::Len ( ) const [inline]

Definition at line 259 of file dt.h.

{return BfL;}
void TChA::Load ( TSIn SIn) [inline]

Definition at line 222 of file dt.h.

                      { delete[] Bf;
    SIn.Load(MxBfL); SIn.Load(BfL); SIn.Load(Bf, MxBfL, BfL);}
void TChA::LoadTxt ( const PSIn SIn,
TChA ChA 
) [static]

Definition at line 616 of file dt.cpp.

                                            {
  delete[] ChA.Bf;
  ChA.Bf=new char[(ChA.MxBfL=ChA.BfL=SIn->Len())+1];
  SIn->GetBf(ChA.CStr(), SIn->Len()); ChA.Bf[ChA.BfL]=0;
}
void TChA::LoadXml ( const PXmlTok XmlTok,
const TStr Nm 
)
bool TChA::operator!= ( const TChA ChA) const [inline]

Definition at line 235 of file dt.h.

{return strcmp(CStr(), ChA.CStr())!=0;}
bool TChA::operator!= ( const char *  _CStr) const [inline]

Definition at line 236 of file dt.h.

{return strcmp(CStr(), _CStr)!=0;}
bool TChA::operator!= ( const char &  Ch) const [inline]

Definition at line 237 of file dt.h.

{return !((BfL==1)&&(Bf[0]==Ch));}
char* TChA::operator() ( ) [inline]

Definition at line 253 of file dt.h.

{return Bf;}
const char* TChA::operator() ( ) const [inline]

Definition at line 254 of file dt.h.

{return Bf;}
TChA & TChA::operator+= ( const TMem Mem)

Definition at line 387 of file dt.cpp.

                                      {
  Resize(BfL+Mem.Len());
  strcpy(Bf+BfL, Mem.GetBf()); BfL+=Mem.Len(); return *this;
}
TChA & TChA::operator+= ( const TChA ChA)

Definition at line 392 of file dt.cpp.

                                     {
  Resize(BfL+ChA.Len());
  strcpy(Bf+BfL, ChA.CStr()); BfL+=ChA.Len(); return *this;
}
TChA & TChA::operator+= ( const TStr Str)

Definition at line 397 of file dt.cpp.

                                     {
  Resize(BfL+Str.Len());
  strcpy(Bf+BfL, Str.CStr()); BfL+=Str.Len(); return *this;
}
TChA & TChA::operator+= ( const char *  CStr)

Definition at line 402 of file dt.cpp.

                                      {
  int CStrLen=(int)strlen(CStr); Resize(BfL+CStrLen);
  strcpy(Bf+BfL, CStr); BfL+=CStrLen; return *this;
}
TChA& TChA::operator+= ( const char &  Ch) [inline]

Definition at line 244 of file dt.h.

                                  {
    if (BfL==MxBfL){Resize(BfL+1);}
    Bf[BfL]=Ch; BfL++; Bf[BfL]=0; return *this;}
bool TChA::operator< ( const TChA ChA) const [inline]

Definition at line 238 of file dt.h.

{return strcmp(CStr(), ChA.CStr())<0;}
TChA & TChA::operator= ( const TChA ChA)

Definition at line 366 of file dt.cpp.

                                    {
  if (this!=&ChA){
    if (ChA.BfL>MxBfL){delete[] Bf; Bf=new char[(MxBfL=ChA.BfL)+1];}
    BfL=ChA.BfL; strcpy(Bf, ChA.CStr());
  }
  return *this;
}
TChA & TChA::operator= ( const TStr Str)

Definition at line 374 of file dt.cpp.

                                    {
  if (Str.Len()>MxBfL){delete[] Bf; Bf=new char[(MxBfL=Str.Len())+1];}
  BfL=Str.Len(); strcpy(Bf, Str.CStr());
  return *this;
}
TChA & TChA::operator= ( const char *  CStr)

Definition at line 380 of file dt.cpp.

                                     {
  int CStrLen=int(strlen(CStr));
  if (CStrLen>MxBfL){delete[] Bf; Bf=new char[(MxBfL=CStrLen)+1];}
  BfL=CStrLen; strcpy(Bf, CStr);
  return *this;
}
bool TChA::operator== ( const TChA ChA) const [inline]

Definition at line 232 of file dt.h.

{return strcmp(CStr(), ChA.CStr())==0;}
bool TChA::operator== ( const char *  _CStr) const [inline]

Definition at line 233 of file dt.h.

{return strcmp(CStr(), _CStr)==0;}
bool TChA::operator== ( const char &  Ch) const [inline]

Definition at line 234 of file dt.h.

{return (BfL==1)&&(Bf[0]==Ch);}
char TChA::operator[] ( const int &  ChN) const [inline]

Definition at line 247 of file dt.h.

                                        {
    Assert((0<=ChN)&&(ChN<BfL)); return Bf[ChN];}
char& TChA::operator[] ( const int &  ChN) [inline]

Definition at line 249 of file dt.h.

                                  {
    Assert((0<=ChN)&&(ChN<BfL)); return Bf[ChN];}
char TChA::Pop ( ) [inline]

Definition at line 265 of file dt.h.

{IAssert(BfL>0); BfL--; char Ch=Bf[BfL]; Bf[BfL]=0; return Ch;}
void TChA::Push ( const char &  Ch) [inline]

Definition at line 264 of file dt.h.

{operator+=(Ch);}
void TChA::PutCh ( const int &  ChN,
const char &  Ch 
) [inline]

Definition at line 278 of file dt.h.

                                            {
    Assert((0<=ChN)&&(ChN<BfL)); Bf[ChN]=Ch;}
void TChA::Resize ( const int &  _MxBfL) [private]

Definition at line 348 of file dt.cpp.

                                  {
  if (_MxBfL<=MxBfL){return;}
  else {if (MxBfL*2<_MxBfL){MxBfL=_MxBfL;} else {MxBfL*=2;}}
  char* NewBf=new char[MxBfL+1]; IAssert(NewBf!=NULL);
  strcpy(NewBf, Bf);
  delete[] Bf; Bf=NewBf;
}
void TChA::Reverse ( )

Definition at line 440 of file dt.cpp.

                  {
  for (int ChN=0; ChN<BfL/2; ChN++){
    char Ch=Bf[ChN];
    Bf[ChN]=Bf[BfL-ChN-1];
    Bf[BfL-ChN-1]=Ch;
  }
}
void TChA::Save ( TSOut SOut,
const bool &  SaveCompact = true 
) const [inline]

Definition at line 224 of file dt.h.

                                                             { //J:
    SOut.Save(SaveCompact?BfL:MxBfL); SOut.Save(BfL); SOut.Save(Bf, BfL);}
void TChA::SaveTxt ( const PSOut SOut) const

Definition at line 622 of file dt.cpp.

                                          {
  SOut->SaveBf(CStr(), Len());
}
void TChA::SaveXml ( TSOut SOut,
const TStr Nm 
) const

Definition at line 361 of file dt.cpp.

int TChA::SearchCh ( const char &  Ch,
const int &  BChN = 0 
) const

Definition at line 470 of file dt.cpp.

                                                        {
  int ChN=TInt::GetMx(BChN, 0);
  const int ThisLen=Len();
  while (ChN<ThisLen){if (Bf[ChN]==Ch){return ChN;} ChN++;}
  return -1;
}
int TChA::SearchChBack ( const char &  Ch,
int  BChN = -1 
) const

Definition at line 477 of file dt.cpp.

                                                     {
  if (BChN >= Len() || BChN < 0) { BChN = Len()-1; }
  for (int i = BChN; i >= 0; i--) {
    if (GetCh(i) == Ch) { return i; }
  }
  return -1;
}
int TChA::SearchStr ( const TChA Str,
const int &  BChN = 0 
) const

Definition at line 485 of file dt.cpp.

                                                          {
  return SearchStr(Str.CStr(), BChN);
}
int TChA::SearchStr ( const TStr Str,
const int &  BChN = 0 
) const

Definition at line 489 of file dt.cpp.

                                                          {
  return SearchStr(Str.CStr(), BChN);
}
int TChA::SearchStr ( const char *  CStr,
const int &  BChN = 0 
) const

Definition at line 493 of file dt.cpp.

                                                           {
  const char* BegPos=strstr(Bf+BChN, CStr);
  if (BegPos==NULL){return -1;}
  else {return int(BegPos-Bf);}
}
void TChA::Swap ( const int &  ChN1,
const int &  ChN2 
)

Definition at line 595 of file dt.cpp.

                                               {
  char Ch=GetCh(ChN1);
  PutCh(ChN1, GetCh(ChN2));
  PutCh(ChN2, Ch);
}
void TChA::Swap ( TChA ChA)

Definition at line 601 of file dt.cpp.

                         {
  ::Swap(MxBfL, ChA.MxBfL);
  ::Swap(BfL, ChA.BfL);
  ::Swap(Bf, ChA.Bf);
}

Definition at line 552 of file dt.cpp.

                 {
  char *c = Bf;
  while (*c) {
    *c = (char) tolower(*c);  c++;
  }
  return *this;
}

Definition at line 568 of file dt.cpp.

                   {
  int StrLen=Len(); int BChN=0; int EChN=StrLen-1;
  while ((BChN<StrLen)&&TCh::IsWs(GetCh(BChN))){BChN++;}
  while ((EChN>=0)&&TCh::IsWs(GetCh(EChN))){EChN--;}
  if ((BChN!=0)||(EChN!=StrLen-1)){
    int DstChN=0;
    for (int SrcChN=BChN; SrcChN<=EChN; SrcChN++){
      PutCh(DstChN, GetCh(SrcChN)); DstChN++;}
    Trunc(DstChN);
  }
  return *this;
}

Definition at line 560 of file dt.cpp.

                 {
  char *c = Bf;
  while (*c) {
    *c = (char) toupper(*c); c++;
  }
  return *this;
}
void TChA::Trunc ( )

Definition at line 420 of file dt.cpp.

                {
  int BChN=0; while ((BChN<BfL)&&(GetCh(BChN)<=' ')){BChN++;}
  int EChN=BfL-1; while ((0<=EChN)&&(GetCh(EChN)<=' ')){EChN--;}
  if (BChN<=EChN){
    for (int ChN=BChN; ChN<=EChN; ChN++){
      PutCh(ChN-BChN, GetCh(ChN));}
    Trunc(EChN-BChN+1);
  } else {
    Clr();
  }
/*  int BChN=0; while ((BChN<BfL)&&(Bf[BChN]<=' ')){BChN++;}
  int EChN=BfL-1; while ((0<=EChN)&&(Bf[EChN]<=' ')){EChN--;}
  if (BChN<=EChN){
    for (int ChN=BChN; ChN<=EChN; ChN++){Bf[ChN-BChN]=Bf[ChN];}
    Bf[BfL=EChN+1]=0;
  } else {
    Clr();
  }*/
}
void TChA::Trunc ( const int &  _BfL) [inline]

Definition at line 267 of file dt.h.

                             {
    if ((0<=_BfL)&&(_BfL<=BfL)){Bf[BfL=_BfL]=0;}}

Member Data Documentation

char* TChA::Bf [private]

Definition at line 204 of file dt.h.

int TChA::BfL [private]

Definition at line 203 of file dt.h.

int TChA::MxBfL [private]

Definition at line 203 of file dt.h.


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