"Fossies" - the Fresh Open Source Software Archive

Member "unrar/strlist.cpp" (4 May 2022, 2330 Bytes) of package /linux/misc/unrarsrc-6.1.7.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 "strlist.cpp" see the Fossies "Dox" file reference documentation.

    1 #include "rar.hpp"
    2 
    3 StringList::StringList()
    4 {
    5   Reset();
    6 }
    7 
    8 
    9 void StringList::Reset()
   10 {
   11   Rewind();
   12   StringData.Reset();
   13   StringsCount=0;
   14   SavePosNumber=0;
   15 }
   16 
   17 
   18 void StringList::AddStringA(const char *Str)
   19 {
   20   Array<wchar> StrW(strlen(Str));
   21   CharToWide(Str,&StrW[0],StrW.Size());
   22   AddString(&StrW[0]);
   23 }
   24 
   25 
   26 void StringList::AddString(const wchar *Str)
   27 {
   28   if (Str==NULL)
   29     Str=L"";
   30 
   31   size_t PrevSize=StringData.Size();
   32   StringData.Add(wcslen(Str)+1);
   33   wcscpy(&StringData[PrevSize],Str);
   34 
   35   StringsCount++;
   36 }
   37 
   38 
   39 bool StringList::GetStringA(char *Str,size_t MaxLength)
   40 {
   41   Array<wchar> StrW(MaxLength);
   42   if (!GetString(&StrW[0],StrW.Size()))
   43     return false;
   44   WideToChar(&StrW[0],Str,MaxLength);
   45   return true;
   46 }
   47 
   48 
   49 bool StringList::GetString(wchar *Str,size_t MaxLength)
   50 {
   51   wchar *StrPtr;
   52   if (!GetString(&StrPtr))
   53     return false;
   54   wcsncpyz(Str,StrPtr,MaxLength);
   55   return true;
   56 }
   57 
   58 
   59 #ifndef SFX_MODULE
   60 bool StringList::GetString(wchar *Str,size_t MaxLength,int StringNum)
   61 {
   62   SavePosition();
   63   Rewind();
   64   bool RetCode=true;
   65   while (StringNum-- >=0)
   66     if (!GetString(Str,MaxLength))
   67     {
   68       RetCode=false;
   69       break;
   70     }
   71   RestorePosition();
   72   return RetCode;
   73 }
   74 #endif
   75 
   76 
   77 wchar* StringList::GetString()
   78 {
   79   wchar *Str;
   80   GetString(&Str);
   81   return Str;
   82 }
   83 
   84 
   85 bool StringList::GetString(wchar **Str)
   86 {
   87   if (CurPos>=StringData.Size()) // No more strings left unprocessed.
   88   {
   89     if (Str!=NULL)
   90       *Str=NULL;
   91     return false;
   92   }
   93 
   94   wchar *CurStr=&StringData[CurPos];
   95   CurPos+=wcslen(CurStr)+1;
   96   if (Str!=NULL)
   97     *Str=CurStr;
   98 
   99   return true;
  100 }
  101 
  102 
  103 void StringList::Rewind()
  104 {
  105   CurPos=0;
  106 }
  107 
  108 
  109 #ifndef SFX_MODULE
  110 bool StringList::Search(const wchar *Str,bool CaseSensitive)
  111 {
  112   SavePosition();
  113   Rewind();
  114   bool Found=false;
  115   wchar *CurStr;
  116   while (GetString(&CurStr))
  117   {
  118     if (Str!=NULL && CurStr!=NULL)
  119       if ((CaseSensitive ? wcscmp(Str,CurStr):wcsicomp(Str,CurStr))!=0)
  120         continue;
  121     Found=true;
  122     break;
  123   }
  124   RestorePosition();
  125   return Found;
  126 }
  127 #endif
  128 
  129 
  130 #ifndef SFX_MODULE
  131 void StringList::SavePosition()
  132 {
  133   if (SavePosNumber<ASIZE(SaveCurPos))
  134   {
  135     SaveCurPos[SavePosNumber]=CurPos;
  136     SavePosNumber++;
  137   }
  138 }
  139 #endif
  140 
  141 
  142 #ifndef SFX_MODULE
  143 void StringList::RestorePosition()
  144 {
  145   if (SavePosNumber>0)
  146   {
  147     SavePosNumber--;
  148     CurPos=SaveCurPos[SavePosNumber];
  149   }
  150 }
  151 #endif