22 Seed=abs(
int(TSysTm::GetPerfTimerTicks()));
30 for (
int StepN=0; StepN<Steps; StepN++){
GetNextSeed();}
35 for (
int SeedN=0; SeedN<10000; SeedN++){
GetNextSeed();}
36 bool Ok=
Seed==1043618065;
Seed=PSeed;
return Ok;
41 if (Range==0){
return Seed;}
42 else {
return Seed%Range;}
47 if (Range==0){
return Seed;}
48 else {
return Seed%Range;}
53 if (Range==0){
return RndVal;}
54 else {
return RndVal%Range;}
59 if (Range==0){
return RndVal;}
60 else {
return RndVal%Range;}
69 }
while ((rsq>=1.0)||(rsq==0.0));
70 double fac=sqrt(-2.0*log(rsq)/rsq);
76 const double& Mean,
const double& SDev,
const double& Mn,
const double& Mx){
87 }
while (UniDev==0.0);
97 double am,e,s,v1,v2,x,y;
109 }
while (v1*v1+v2*v2 > 1.0);
115 e=(1.0+y*y)*exp(am*log(x/am)-s*y);
122 static double sq,alxm,g,oldm=(-1.0);
156 static int nold=(-1);
157 double am,em,g,angle,p,bnl,sq,t,y;
158 static double pold=(-1.0),pc,plog,pclog,en,oldg;
160 p=(Prb <= 0.5 ? Prb : 1.0-Prb);
164 for (j=1;j<=Trials;j++)
166 }
else if (am < 1.0) {
169 for (j=0;j<=Trials;j++) {
173 bnl=(j <= Trials ? j : Trials);
175 if (Trials != nold) {
191 }
while (em < 0.0 || em >= (en+1.0));
193 t=1.2*sq*(1.0+y*y)*exp(oldg-(em+1.0)
198 if (p != Prb) bnl=Trials-bnl;
226 if (_MxBfL<=
MxBfL){
return;}
230 if (
Bf!=NULL){
delete[]
Bf;}
235 MxBfL(Str.Len()), BfL(MxBfL), Bf(NULL){
258 if (LBfL>0){memcpy(&
Bf[
BfL], Mem(), LBfL);}
259 BfL+=LBfL;
return *
this;
264 if (LBfL>0){memcpy(
Bf+
BfL, Str.
CStr(), LBfL);}
265 BfL+=LBfL;
return *
this;
270 char* LBf=
new char[LBfL];
271 SIn->
GetBf(LBf, LBfL);
272 if (LBfL>0){memcpy(
Bf+
BfL, LBf, LBfL);}
274 BfL+=LBfL;
return *
this;
278 if (BChN>EChN){
return;}
279 if ((BChN==0)&&(EChN==
BfL-1)){
Clr();
return;}
281 memmove(
Bf+BChN,
Bf+EChN+1,
BfL-EChN-1);
292 IAssert((_BfL>=0) && (_Bf != NULL));
294 memcpy(
Bf +
BfL, _Bf, _BfL);
304 if (NewNullCh!=
'\0'){
316 TSBase(
"Input-Memory"),
TSIn(
"Input-Memory"), Mem(), Bf(_Mem()), BfC(_BfC), BfL(_Mem.Len()){}
321 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
322 LBfS+=(((
char*)LBf)[LBfC]=
Bf[
BfC++]);}
339 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
340 char Ch=((
char*)LBf)[LBfC];
349 if (_MxBfL<=
MxBfL){
return;}
353 delete[]
Bf;
Bf=NewBf;
381 int CStrLen=int(strlen(CStr));
383 BfL=CStrLen; strcpy(
Bf, CStr);
403 int CStrLen=(int)strlen(CStr);
Resize(
BfL+CStrLen);
404 strcpy(
Bf+
BfL, CStr);
BfL+=CStrLen;
return *
this;
409 int CStrLen=int(strlen(CStr));
Resize(
BfL+CStrLen);
410 memmove(
Bf+BChN+CStrLen,
Bf+BChN,
BfL-BChN+1);
411 memmove(
Bf+BChN, CStr, CStrLen);
BfL+=CStrLen;
416 memmove(
Bf+ChN,
Bf+ChN+1,
BfL-ChN);
421 int BChN=0;
while ((BChN<
BfL)&&(
GetCh(BChN)<=
' ')){BChN++;}
422 int EChN=
BfL-1;
while ((0<=EChN)&&(
GetCh(EChN)<=
' ')){EChN--;}
424 for (
int ChN=BChN; ChN<=EChN; ChN++){
441 for (
int ChN=0; ChN<
BfL/2; ChN++){
453 else if (Chs==
Len()){
return *
this;}
464 const int ThisLen=
Len();
466 while (ChN<ThisLen){
if (
Bf[ChN]==Ch){ Cnt++;} ChN++;}
472 const int ThisLen=
Len();
473 while (ChN<ThisLen){
if (
Bf[ChN]==Ch){
return ChN;} ChN++;}
478 if (BChN >=
Len() || BChN < 0) { BChN =
Len()-1; }
479 for (
int i = BChN; i >= 0; i--) {
480 if (
GetCh(i) == Ch) {
return i; }
494 const char* BegPos=strstr(
Bf+BChN, CStr);
495 if (BegPos==NULL){
return -1;}
496 else {
return int(BegPos-
Bf);}
500 if (BChN+(
int)strlen(CStr)>
Len()){
return false;}
501 const char* B =
Bf+BChN;
502 const char* C =
CStr;
503 while (*C!=0 && *B==*C) {
506 if (*C==0){
return true;}
519 if ((
int)strlen(CStr) >
Len()) {
return false; }
520 const char* E =
Bf+
Len()-1;
521 const char* C = CStr+strlen(CStr)-1;
522 while (C >= CStr && *E==*C) {
525 if (C+1 == CStr) {
return true; }
526 else {
return false; }
539 for (
int ChN=0; ChN<StrLen; ChN++){
if (
Bf[ChN]==SrcCh){
Bf[ChN]=DstCh;}}
555 *c = (char) tolower(*c); c++;
563 *c = (char) toupper(*c); c++;
569 int StrLen=
Len();
int BChN=0;
int EChN=StrLen-1;
572 if ((BChN!=0)||(EChN!=StrLen-1)){
574 for (
int SrcChN=BChN; SrcChN<=EChN; SrcChN++){
582 int StrLen=
Len();
int SrcChN=0;
int DstChN=0;
584 while (SrcChN<StrLen){
588 PutCh(DstChN,
GetCh(SrcChN)); SrcChN++; DstChN++;
642 TSBase(
"Input-Char-Array"),
TSIn(
"Input-Char-Array"), Bf(ChA.CStr()), BfC(_BfC), BfL(ChA.Len()){}
647 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
648 LBfS+=(((
char*)LBf)[LBfC]=
Bf[
BfC++]);}
662 for (
int ChN=0; ChN<StrLen; ChN++){
663 if ((
'a'<=
Bf[ChN])&&(
Bf[ChN]<=
'z')){
return false;}}
669 for (
int ChN=0; ChN<StrLen; ChN++){
670 Bf[ChN]=(char)toupper(
Bf[ChN]);}}
674 for (
int ChN=0; ChN<StrLen; ChN++){
675 if ((
'A'<=
Bf[ChN])&&(
Bf[ChN]<=
'Z')){
return false;}}
681 for (
int ChN=0; ChN<StrLen; ChN++){
682 Bf[ChN]=(char)tolower(
Bf[ChN]);}
688 Bf[0]=(char)toupper(
Bf[0]);}
689 for (
int ChN=1; ChN<StrLen; ChN++){
690 Bf[ChN]=(char)tolower(
Bf[ChN]);}
695 for (
int ChN=0; ChN<StrLen; ChN++){
700 if (!p){
return r ? (*r ? -1 : 0) : 0;}
701 if (!r){
return (*p ? 1 : 0);}
703 int i=int(toupper(*p++))-int(toupper(*r++));
706 return int(toupper(*p++))-int(toupper(*r++));
721 if (CStr==NULL){CStrLen=0;}
else {CStrLen=int(strlen(CStr));}
726 else {
return new TRStr(CStr);}
771 int ThisLen=
Len();
char* ThisBf=
CStr();
772 int BChN=0;
int EChN=ThisLen-1;
773 while ((BChN<ThisLen)&&
TCh::IsWs(ThisBf[BChN])){BChN++;}
774 while ((EChN>=0)&&
TCh::IsWs(ThisBf[EChN])){EChN--;}
788 for (
int ChN=0; ChN<StrLen; ChN++){
792 ChA+=MshCh; ChA+=LshCh;
802 char MshCh=
RStr->
Bf[ChN]; ChN++;
803 char LshCh=
RStr->
Bf[ChN]; ChN++;
816 if (Chs<=0){
return TStr();}
817 else if (Chs==StrLen){
return *
this;}
819 char* Bf=
new char[Chs+1]; strncpy(Bf,
CStr()+BChN, Chs); Bf[Chs]=0;
820 TStr Str(Bf);
delete[] Bf;
827 IAssert((0<=BChN)&&(BChN<=ThisLen));
853 int Chs=
Len()-(EChN-BChN+1);
856 char* Bf=
new char[Chs+1]; strncpy(Bf,
CStr(), BChN);
857 strncpy(Bf+BChN,
CStr()+EChN+1,
Len()-EChN-1); Bf[Chs]=0;
858 TStr Str(Bf);
delete[] Bf;
874 int ThisLen=
Len();
const char* ThisBf=
CStr();
876 while ((ChN<ThisLen)&&(ThisBf[ChN]!=SplitCh)){ChN++;}
877 return (ChN==ThisLen) ?
"" :
GetSubStr(0, ChN-1);
881 const char* ThisBf=
CStr();
883 while ((ChN>=0)&&(ThisBf[ChN]!=SplitCh)){ChN--;}
884 return (ChN==-1) ?
"" :
GetSubStr(0, ChN-1);
888 int ThisLen=
Len();
const char* ThisBf=
CStr();
890 while ((ChN<ThisLen)&&(ThisBf[ChN]!=SplitCh)){ChN++;}
891 return (ChN==ThisLen) ?
"" :
GetSubStr(ChN+1, ThisLen-1);
895 int ThisLen=
Len();
const char* ThisBf=
CStr();
897 while ((ChN>=0)&&(ThisBf[ChN]!=SplitCh)){ChN--;}
898 return (ChN==-1) ?
"" :
GetSubStr(ChN+1, ThisLen-1);
902 int ThisLen=
Len();
const char* ThisBf=
CStr();
904 while ((ChN<ThisLen)&&(ThisBf[ChN]!=SplitCh)){ChN++;}
913 int ThisLen=
Len();
const char* ThisBf=
CStr();
915 while ((ChN>=0)&&(ThisBf[ChN]!=SplitCh)){ChN--;}
927 const char& SplitCh,
TStrV& StrV,
const bool& SkipEmpty)
const {
929 char* Bf=
new char[
Len()+1];
934 while ((*BfC!=0)&&(*BfC!=SplitCh)){BfC++;}
935 bool IsEnd=(*BfC==
'\0');
937 if ((BfC>CurStrBf)||(!SkipEmpty)){StrV.
Add(
TStr(CurStrBf));}
945 const TStr& SplitChStr,
TStrV& StrV,
const bool& SkipEmpty)
const {
949 char* Bf=
new char[
Len()+1];
953 const char* SplitChBf=SplitChStr.
CStr();
957 const char* SplitChBfC=SplitChBf;
958 while ((*SplitChBfC!=0)&&(*SplitChBfC!=*BfC)){SplitChBfC++;}
959 if (*SplitChBfC!=0){
break;}
962 bool IsEnd=(*BfC==0);
964 if ((BfC>CurStrBf)||(!SkipEmpty)){StrV.
Add(
TStr(CurStrBf));}
974 char* Bf=
new char[
Len()+1];
978 while ((*StrBf!=0)&&(
TCh::IsWs(*StrBf))){StrBf++;}
980 while ((*BfC!=0)&&(!
TCh::IsWs(*BfC))){BfC++;}
981 bool IsEnd=(*BfC==
'\0');
983 if (BfC>StrBf){StrV.
Add(
TStr(StrBf));}
992 char* Bf=
new char[
Len()+1];
999 bool IsEnd=(*BfC==
'\0');
1001 if (BfC>StrBf){StrV.
Add(
TStr(StrBf));}
1010 int SplitStrLen=SplitStr.
Len();
1011 int PrevChN=0;
int ChN=0;
1012 while ((ChN=
SearchStr(SplitStr, ChN))!=-1){
1016 PrevChN=ChN=ChN+SplitStrLen;
1020 StrV.
Add(LastSubStr);
1034 const int ThisLen=
Len();
1035 const char* ThisBf=
CStr();
1037 for (
int ChN=
TInt::GetMx(BChN, 0); ChN<ThisLen; ChN++){
1038 if (ThisBf[ChN]==Ch){Chs++;}
1044 int ThisLen=
Len();
const char* ThisBf=
CStr();
1046 while (ChN<ThisLen){
1047 if (ThisBf[ChN]==Ch){
return ChN;}
1054 const int StrLen=
Len();
1055 if (BChN==-1||BChN>=StrLen){BChN=StrLen-1;}
1056 const char* ThisBf=
CStr();
1057 const char* Pt=ThisBf + BChN;
1058 while (Pt>=ThisBf) {
1059 if (*Pt==Ch){
return (
int)(Pt-ThisBf);}
1067 const char* StrPt=strstr((
const char*)
CStr()+NrBChN, Str.
CStr());
1068 if (StrPt==NULL){
return -1;}
1069 else {
return int(StrPt-
CStr());}
1082 size_t len = strlen(Str);
1083 size_t thisLen =
Len();
1084 if (len > thisLen) {
1087 size_t minLen =
MIN(len, thisLen);
1088 int cmp = strncmp(Str,
RStr->
Bf, minLen);
1094 size_t len = strlen(Str);
1095 size_t thisLen =
Len();
1096 if (len > thisLen) {
1101 const char *ending =
RStr->
Bf + thisLen - len;
1102 int cmp = strncmp(Str, ending, len);
1109 if (ChN!=-1){
PutCh(ChN, DstCh);}
1120 char* ThisBf=
CStr();
int StrLen=
Len();
int Changes=0;
1121 for (
int ChN=FirstChN; ChN<StrLen; ChN++){
1123 if (ThisBf[ChN]==SrcCh){ThisBf[ChN]=DstCh; Changes++;}
1142 const int DstStrLen=DstStr.
Len();
1143 int Changes=0-1;
int BChN=0-DstStrLen;
1146 if (FromStartP){BChN=0-DstStrLen;}
1154 if (
operator==(
"T")){Val=
true;
return true;}
1155 else if (
operator==(
"F")){Val=
false;
return true;}
1156 else {
return false;}
1160 const bool& Check,
const int& MnVal,
const int& MxVal,
int& Val)
const {
1166 if (Ch()==
'+'){Minus=
false; Ch.
GetCh();}
1167 if (Ch()==
'-'){Minus=
true; Ch.
GetCh();}
1171 if (Minus){_Val=-_Val;}
1172 if (Check&&((_Val<MnVal)||(_Val>MxVal))){
return false;}
1173 if (Ch.
Eof()){Val=_Val;
return true;}
else {
return false;}
1177 const bool& Check,
const uint& MnVal,
const uint& MxVal,
uint& Val)
const {
1182 if (Ch()==
'+'){Ch.
GetCh();}
1186 if (Check&&((_Val<MnVal)||(_Val>MxVal))){
return false;}
1187 if (Ch.
Eof()){Val=_Val;
return true;}
else {
return false;}
1190 bool TStr::IsHexInt(
const bool& Check,
const int& MnVal,
const int& MxVal,
int& Val)
const {
1196 if (Ch()==
'+'){Minus=
false; Ch.
GetCh();}
1197 if (Ch()==
'-'){Minus=
true; Ch.
GetCh();}
1200 if (tolower(Ch())==
'x' ){
1201 Ch.
GetCh();
if (Ch.
Eof()){
return false;}
1207 if (Minus){_Val=-_Val;}
1208 if (Check&&((_Val<MnVal)||(_Val>MxVal))){
return false;}
1209 if (Ch.
Eof()){Val=_Val;
return true;}
else {
return false;}
1213 const bool& Check,
const int64& MnVal,
const int64& MxVal,
int64& Val)
const {
1219 if (Ch()==
'+'){Minus=
false; Ch.
GetCh();}
1220 if (Ch()==
'-'){Minus=
true; Ch.
GetCh();}
1224 if (Minus){_Val=-_Val;}
1225 if (Check&&((_Val<MnVal)||(_Val>MxVal))){
return false;}
1226 if (Ch.
Eof()){Val=_Val;
return true;}
else {
return false;}
1235 if (Ch()==
'+'){Ch.
GetCh();}
1239 if (Check&&((_Val<MnVal)||(_Val>MxVal))){
return false;}
1240 if (Ch.
Eof()){Val=_Val;
return true;}
else {
return false;}
1244 const bool& Check,
const int64& MnVal,
const int64& MxVal,
int64& Val)
const {
1250 if (Ch()==
'+'){Minus=
false; Ch.
GetCh();}
1251 if (Ch()==
'-'){Minus=
true; Ch.
GetCh();}
1254 if (tolower(Ch())==
'x' ){
1255 Ch.
GetCh();
if (Ch.
Eof()){
return false;}
1260 if (Minus){_Val=-_Val;}
1261 if (Check&&((_Val<MnVal)||(_Val>MxVal))){
return false;}
1262 if (Ch.
Eof()){Val=_Val;
return true;}
else {
return false;}
1265 bool TStr::IsFlt(
const bool& Check,
const double& MnVal,
const double& MxVal,
1266 double& Val,
const char& DecDelimCh)
const {
1270 if ((Ch()==
'+')||(Ch()==
'-')){Ch.
GetCh();}
1271 if (!
TCh::IsNum(Ch())&&Ch()!=DecDelimCh){
return false;}
1273 if (Ch()==DecDelimCh){
1277 if ((Ch()==
'e')||(Ch()==
'E')){
1279 if ((Ch()==
'+')||(Ch()==
'-')){Ch.
GetCh();}
1283 if (!Ch.
Eof()){
return false;}
1284 double _Val=atof(
CStr());
1285 if (Check&&((_Val<MnVal)||(_Val>MxVal))){
1288 Val=_Val;
return true;
1292 bool TStr::IsWord(
const bool& WsPrefixP,
const bool& FirstUcAllowedP)
const {
1298 else if (!FirstUcAllowedP&&(
TCh::IsUc(Ch()))){
return false;}
1300 if (!Ch.
Eof()){
return false;}
1312 const int& StrBChN,
const TStr& WcStr,
const int& WcStrBChN,
TStrV& StarStrV,
1313 const char& StarCh,
const char& QuestCh)
const {
1314 int StrLen=
Len();
int WcStrLen=WcStr.
Len();
1315 int StrChN=StrBChN;
int WcStrChN=WcStrBChN;
1316 while ((StrChN<StrLen)&&(WcStrChN<WcStrLen)){
1317 if ((WcStr[WcStrChN]==QuestCh)||(
GetCh(StrChN)==WcStr[WcStrChN])){
1318 StrChN++; WcStrChN++;
1320 if (WcStr[WcStrChN]==StarCh){
1322 for (
int AfterStrChN=StrChN; AfterStrChN<=StrLen; AfterStrChN++){
1323 if (AfterStrChN>StrChN){
1324 StarChA+=
GetCh(AfterStrChN-1);}
1325 if (
IsWcMatch(AfterStrChN, WcStr, WcStrChN+1, StarStrV, StarCh, QuestCh)){
1326 StarStrV.
Add(StarChA);
return true;
1334 if (StrChN==StrLen){
1335 for (
int AfterWcStrChN=WcStrChN; AfterWcStrChN<WcStrLen; AfterWcStrChN++){
1336 if (WcStr[AfterWcStrChN]!=StarCh){
return false;}}
1344 const TStr& WcStr,
TStrV& StarStrV,
const char& StarCh,
const char& QuestCh)
const {
1345 bool WcMatch=
IsWcMatch(0, WcStr, 0, StarStrV, StarCh, QuestCh);
1355 const TStr& WcStr,
const char& StarCh,
const char& QuestCh)
const {
1357 return IsWcMatch(0, WcStr, 0, StarStrV, StarCh, QuestCh);
1363 if (StarStrV.
Len()>StarStrN){
1364 StarStr=StarStrV[StarStrV.
Len()-StarStrN-1];
1376 return IsWcMatch(0, WcStr, 0, StarStrV);
1381 if (
IsWcMatch(WcStr, StarStrV)&&(StarStrV.
Len()>=StarStrN)){
1383 return StarStrV[StarStrV.
Len()-StarStrN-1];
1390 int ThisLen=
Len();
const char* ThisBf=
CStr();
1392 while ((ChN>=0)&&(ThisBf[ChN]!=
'/')&&(ThisBf[ChN]!=
'\\')){ChN--;}
1397 int ThisLen=
Len();
const char* ThisBf=
CStr();
1399 while ((ChN>=0)&&(ThisBf[ChN]!=
'/')&&(ThisBf[ChN]!=
'\\')){ChN--;}
1404 int ThisLen=
Len();
const char* ThisBf=
CStr();
1406 while ((ChN>=0)&&(ThisBf[ChN]!=
'/')&&(ThisBf[ChN]!=
'\\')&&(ThisBf[ChN]!=
'.')){
1411 if (ThisBf[ChN]==
'.'){
1413 while ((ChN>=0)&&(ThisBf[ChN]!=
'/')&&(ThisBf[ChN]!=
'\\')){ChN--;}
1422 int ThisLen=
Len();
const char* ThisBf=
CStr();
1424 while ((ChN>=0)&&(ThisBf[ChN]!=
'/')&&(ThisBf[ChN]!=
'\\')&&
1425 (ThisBf[ChN]!=
'.')){ChN--;}
1426 if ((ChN>=0)&&(ThisBf[ChN]==
'.')){
return GetSubStr(ChN,
Len());}
1427 else {
return TStr();}
1431 TChA NrFPath(FPath.
Len()+4); NrFPath+=FPath;
1433 if (NrFPath.Empty()){NrFPath=
"./";}
1434 if ((NrFPath.Len()>=2)&&isalpha(NrFPath[0])&&(NrFPath[1]==
':')){
1435 if (NrFPath.Len()==2){NrFPath+=
"./";}
1436 if ((NrFPath[2]!=
'.')&&(NrFPath[2]!=
'/')){NrFPath.Ins(2,
"./");}
1437 if (NrFPath[NrFPath.Len()-1]!=
'/'){NrFPath+=
"/";}
1439 if ((NrFPath[0]!=
'.')&&(NrFPath[0]!=
'/')){NrFPath.Ins(0,
"./");}
1440 if (NrFPath[NrFPath.Len()-1]!=
'/'){NrFPath+=
"/";}
1447 int FMidLen=FMid.
Len();
1448 for (
int ChN=0; ChN<FMidLen; ChN++){
1456 if (FExt.
Empty()||(FExt[0]==
'.')){
return FExt;}
1457 else {
return TStr(
".")+FExt;}
1462 while (FExtNStr.
Len()<3){
1463 FExtNStr=
TStr(
"0")+FExtNStr;}
1473 if (BaseFPath.
Empty()){
1492 if ((FPath.
Len()>=3)&&isalpha(FPath[0])&&(FPath[1]==
':')&&
1493 ((FPath[2]==
'/')||(FPath[2]==
'\\'))){
1533 for (
int ChN=0; ChN<FNm.
Len(); ChN++){
1537 ((
'0'<=Ch)&&(Ch<=
'9'))||
1538 ((
'A'<=Ch)&&(Ch<=
'Z'))||
1539 ((
'a'<=Ch)&&(Ch<=
'z'))||
1540 (Ch==
'-')||(Ch==
'_')){}
1543 if ((Ch<=
' ')||(Ch==
'/')||(Ch==
'\\')||(Ch==
':')||(Ch==
'.')){
1552 static char MnCh=char(CHAR_MIN);
1553 static char MxCh=char(CHAR_MAX);
1554 static int Chs=int(MxCh)-int(MnCh)+1;
1555 static TStrV ChStrV;
1556 if (ChStrV.
Empty()){
1558 for (
int ChN=0; ChN<Chs; ChN++){
1559 ChStrV[ChN]=
TStr(
char(MnCh+ChN),
true);}
1561 return ChStrV[int(Ch-MnCh)];
1567 if (DChStrVV.
Empty()){
1569 for (
int Ch1N=0; Ch1N<
TCh::Vals; Ch1N++){
1570 for (
int Ch2N=0; Ch2N<
TCh::Vals; Ch2N++){
1571 DChStrVV.
At(Ch1N, Ch2N)=
1584 sprintf(Bf, FmtStr, Str.
CStr());
1591 TChA ResStr=StrV[0];
1592 for (
int StrN=1; StrN<StrV.
Len(); StrN++){
1593 ResStr+=DelimiterStr;
1602 va_start(valist, FmtStr);
1603 const int RetVal=vsnprintf(Bf, 10*1024-2, FmtStr, valist);
1609 static TStrV SpaceStrV;
1610 if (SpaceStrV.
Len()==0){
1611 for (
int SpaceStrN=0; SpaceStrN<10; SpaceStrN++){
1613 for (
int ChN=0; ChN<SpaceStrN; ChN++){SpaceChA+=
' ';}
1614 SpaceStrV.
Add(SpaceChA);
1617 if ((0<=Spaces)&&(Spaces<SpaceStrV.
Len())){
1618 return SpaceStrV[Spaces];
1621 for (
int ChN=0; ChN<Spaces; ChN++){SpaceChA+=
' ';}
1627 static TStr NullStr=
"";
1632 if (LStr.
Empty()){
return RStr;}
1633 else if (RStr.
Empty()){
return LStr;}
1634 else {
return TStr(LStr)+=RStr;}
1638 return TStr(LStr)+=RCStr;
1644 TSBase(
"Input-String"),
TSIn(
"Input-String"), Str(_Str), Bf(Str.CStr()), BfC(0), BfL(Str.Len()){}
1649 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
1650 LBfS+=(((
char*)LBf)[LBfC]=
Bf[
BfC++]);}
1664 while (newSize < _MxBfL) {
1666 else if (newSize > 0) newSize *= 2;
1669 IAssertR(newSize >=
MxBfL,
TStr::Fmt(
"TStrPool::Resize: %u, %u [Size larger than 4Gb, which is not supported by TStrPool]", newSize,
MxBfL).CStr());
1671 if (newSize >
MxBfL) {
1672 Bf = (
char *) realloc(
Bf, newSize);
1681 if (
MxBfL > 0) {
Bf = (
char *) malloc(
MxBfL);
IAssertR(
Bf,
TStr::Fmt(
"Can not resize buffer to %u bytes. [Program failed to allocate more memory. Solution: Get a bigger machine.]",
MxBfL).CStr()); }
1689 if (
MxBfL > 0) {
Bf = (
char *) malloc(
MxBfL);
IAssertR(
Bf,
TStr::Fmt(
"Can not resize buffer to %u bytes. [Program failed to allocate more memory. Solution: Get a bigger machine.]",
MxBfL).CStr()); }
1701 if (
this != &Pool) {
1704 Bf = (
char *) malloc(
MxBfL);
IAssertR(
Bf,
TStr::Fmt(
"Can not resize buffer to %u bytes. [Program failed to allocate more memory. Solution: Get a bigger machine.]",
MxBfL).CStr()); memcpy(
Bf, Pool.
Bf,
BfL);
1712 IAssertR(Len > 0,
"String too short (length includes the null character)");
1713 if (Len == 1 &&
BfL > 0) {
return 0; }
1716 memcpy(
Bf +
BfL, Str, Len);
1732 while (newSize < _MxBfL) {
1734 else if (newSize > 0) newSize *= 2;
1738 if (newSize >
MxBfL) {
1739 Bf = (
char *) realloc(
Bf, newSize);
1747 MxBfL(_MxBfL), BfL(0), GrowBy(_GrowBy), Bf(NULL) {
1754 MxBfL(StrPool.MxBfL), BfL(StrPool.BfL), GrowBy(StrPool.GrowBy) {
1761 MxBfL(0), BfL(0), GrowBy(0), Bf(0) {
1762 uint64 _GrowBy, _MxBfL, _BfL;
1767 for (::
TSize BfN = 0; BfN < _BfL; BfN++) {
Bf[BfN] = SIn.
GetCh(); }
1773 SOut.
Save(_GrowBy); SOut.
Save(_MxBfL); SOut.
Save(_BfL);
1774 for (::
TSize BfN = 0; BfN < _BfL; BfN++) { SOut.
PutCh(
Bf[BfN]); }
1779 if (
this != &StrPool) {
1790 if (DoDel && (
Bf!=NULL)) {
1797 const int Len = Str.
Len() + 1;
1806 return TStr(
Bf + Offset);
1887 case '~':
return 'c';
1888 case '^':
return 'C';
1889 case '{':
return 's';
1890 case '[':
return 'S';
1891 case '`':
return 'z';
1892 case '@':
return 'Z';
1893 case '|':
return 'd';
1894 case '\\':
return 'D';
1937 sprintf(Bf, FmtStr, Val);
1961 if (i >= 0 && i <= 127) { *pDest++ = char(i);
return pDest; }
1962 if (i >= 128 && i < 128 + 8192) { i -= 128; *pDest++ = char(0x80 | (i & 0x7f));
1963 *pDest++ = char((i >> 7) & 0x3f);
return pDest; }
1964 if (i <= -1 && i > -1 - 8192) { i = -1 - i; *pDest++ = char(0x80 | (i & 0x7f));
1965 *pDest++ = char(0x40 | ((i >> 7) & 0x3f));
return pDest; }
1966 if (i >= 128 + 8192 && i < 128 + 8192 + 536870912) { i -= 128 + 8192;
1967 *pDest++ = char(0x80 | (i & 0x7f)); *pDest++ = char(0x80 | ((i >> 7) & 0x7f));
1968 *pDest++ = char((i >> 14) & 0xff); *pDest++ = char((i >> 22) & 0x7f);
return pDest; }
1969 if (i <= -1 - 8192 && i > -1 - 8192 - 536870912) { i = (-1 - 8192) - i;
1970 *pDest++ = char(0x80 | (i & 0x7f)); *pDest++ = char(0x80 | ((i >> 7) & 0x7f));
1971 *pDest++ = char((i >> 14) & 0xff); *pDest++ = char(0x80 | ((i >> 22) & 0x7f));
return pDest; }
1977 int ch = (int) ((
unsigned char) (*pSrc++));
1978 if ((ch & 0x80) == 0) { i = ch; i--;
return pSrc; }
1980 ch = (int) ((
unsigned char) (*pSrc++));
1981 if ((ch & 0x80) == 0)
1983 i |= (ch & 0x3f) << 7;
1984 if ((ch & 0x40) == 0) i += 128;
else i = -1 - i;
1987 i |= (ch & 0x7f) << 7;
1988 ch = (int) ((
unsigned char) (*pSrc++));
1990 ch = (int) ((
unsigned char) (*pSrc++));
1991 i |= (ch & 0x7f) << 22;
1992 if ((ch & 0x80) == 0) i += 128 + 8192;
else i = (-1 - 8192) - i;
1999 char buf[10], *p = &buf[0], *r, *s;
2001 #define __TEST(from, to, len) \
2002 for (i = (from); i <= (to); i++) \
2003 { if ((i & 0xffff) == 0) printf("%d\r", i); \
2004 r = SaveFrugalInt(p, i); s = LoadFrugalInt(p, j); \
2005 IAssert(r == s); IAssert(i == j); IAssert(r - p == len); }
2008 __TEST(127, 127 + 8191, 2);
2009 __TEST(-2 - 8191, -2, 2);
2010 __TEST(127 + 8192, 127 + 8191 + (1 << 29), 4);
2011 __TEST(-2 - 8191 - (1 << 29), -2 - 8192, 4);
2020 int count = v.
Len();
2021 char *buf =
new char[4 * (count + 1)], *pStart, *pEnd;
2023 pStart = buf + 4; pEnd = pStart;
2024 for (
int i = 0; i < count; i++)
2030 int size = int(pEnd - pStart);
2031 char *pSizeStart = buf;
2033 while (pSizeEnd > pSizeStart) *(--pStart) = *(--pSizeEnd);
2044 if (clearVec) v.
Clr();
2045 char sizeBuf[4], *p, *pEnd;
2048 sizeBuf[0] = SIn.
GetCh();
int count = 1;
2049 if (sizeBuf[0] & 0x80)
2051 sizeBuf[1] = SIn.
GetCh(); count++;
2052 if (sizeBuf[1] & 0x80) { sizeBuf[2] = SIn.
GetCh();
2053 sizeBuf[3] = SIn.
GetCh(); count += 2;}
2058 IAssert(pEnd - &sizeBuf[0] == count);
2059 if (size <= 0)
return;
2061 char *buf =
new char[size];
2062 SIn.
GetBf(buf, size);
2064 p = buf; pEnd = buf + size;
2091 sprintf(Bf, FmtStr, Val);
2098 Ip = 0;
int Byte = 0;
2099 if (IpStrV.
Len() != 4) {
return false; }
2100 if (!IpStrV[0].IsInt(
true, 0, 255, Byte)) {
return false; }; Ip = (
uint)Byte;
2101 if (!IpStrV[1].IsInt(
true, 0, 255, Byte)) {
return false; }; Ip = (Ip << 8) | (
uint)Byte;
2102 if (!IpStrV[2].IsInt(
true, 0, 255, Byte)) {
return false; }; Ip = (Ip << 8) | (
uint)Byte;
2103 if (!IpStrV[3].IsInt(
true, 0, 255, Byte)) {
return false; }; Ip = (Ip << 8) | (
uint)Byte;
2109 uint Ip = 0;
int Byte = 0;
2118 return TStr::Fmt(
"%d.%d.%d.%d", ((Ip>>24) & 0xFF),
2119 ((Ip>>16) & 0xFF), ((Ip>>8) & 0xFF), (Ip & 0xFF));
2125 if (IpStrV.
Len() > 8) {
return false; }
2128 for (
int IpStrN = 0; IpStrN < IpStrV.
Len(); IpStrN++) {
2129 if (IpStrV[IpStrN].Empty()) {
continue; }
2130 if (IpStrV[IpStrN].IsHexInt(
true, 0x0000, 0xFFFF, Group)) {
continue; }
2140 #if defined (GLib_WIN32)
2143 #elif defined (GLib_BCB)
2238 if ((Width==-1)&&(Prec==-1)){sprintf(Bf,
"%g", Val);}
2239 else {sprintf(Bf,
"%*.*f", Width, Prec, Val);}
2248 sprintf(Bf, FmtStr, Val);
2286 if ((Width==-1)&&(Prec==-1)){sprintf(Bf,
"%Lg", Val);}
2287 else {sprintf(Bf,
"%*.*Lf", Width, Prec, Val);}
2296 sprintf(Bf, FmtStr, Val);
2322 return (MnXX < MxXX) && (MnYY < MxYY);
void Save(TSOut &SOut) const
static int CmpI(const char *CStr1, const char *CStr2)
static bool IsHex(const char &Ch)
void Resize(const uint &_MxBfL)
static TStr PutFExtIfEmpty(const TStr &FNm, const TStr &FExt)
static double LnGamma(const double &xx)
int SearchCh(const char &Ch, const int &BChN=0) const
int GetBf(const void *LBf, const TSize &LBfL)
TMemOut(const PMem &_Mem)
virtual int Len() const =0
#define IAssertR(Cond, Reason)
static TStr GetSpaceStr(const int &Spaces)
void SaveXml(TSOut &SOut, const TStr &Nm) const
#define XSaveBETagArg(Nm, ArgNm, ArgVal)
TStr GetAsStr(const char &NewNullCh='\0') const
const char * CStr() const
void Resize(const int &_MxBfL)
static void LoadTxt(const PSIn &SIn, TChA &ChA)
int64 GetUniDevInt64(const int64 &Range=0)
void Ins(const int &BChN, const char *CStr)
static bool IsNum(const char &Ch)
bool IsPrefix(const char *Str) const
virtual int PutCh(const char &Ch)=0
virtual int PutBf(const void *LBf, const TSize &LBfL)=0
#define XSaveHdArg(Nm, ArgNm, ArgVal)
void SaveXml(TSOut &SOut, const TStr &Nm) const
static TStr GetStrFromIpUInt(const uint &Ip)
int GetPrimHashCd() const
TMem & operator+=(const char &Ch)
void Save(TSOut &SOut) const
int SearchChBack(const char &Ch, int BChN=-1) const
static TRnd LoadTxt(TILx &Lx)
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
static double GetMx(const double &Flt1, const double &Flt2)
static int GetMx(const int &Int1, const int &Int2)
static char * SaveFrugalInt(char *pDest, int i)
void PutCh(const int &ChN, const char &Ch)
static char GetHexCh(const int &Val)
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
void Clr(bool DoDel=false)
static const double EpsHalf
TSizeTy Len() const
Returns the number of elements in the vector.
static void SaveFrugalIntV(TSOut &SOut, const TVec< TInt, int > &IntV)
static int GetPrimHashCd(const char *CStr)
uint64 GetUniDevUInt64(const uint64 &Range=0)
void PutInt(const TInt &Int)
static TStr GetXmlStrFromPlainMem(const TMem &PlainMem)
void DelChAll(const char &Ch)
void SaveXml(TSOut &SOut, const TStr &Nm) const
virtual int GetBf(const void *Bf, const TSize &BfL)=0
static int GetHex(const char &Ch)
static TStr GetNrFMid(const TStr &FMid)
TStr GetSubStr(const int &BChN, const int &EChN) const
bool DelStr(const TStr &Str)
int GetBf(const void *LBf, const TSize &LBfL)
static TStr GetNrFNm(const TStr &FNm)
int SearchStr(const TChA &Str, const int &BChN=0) const
static int64 GetInt64Arg(const PXmlTok &XmlTok, const TStr &Nm)
static bool IsIpv6Str(const TStr &IpStr, const char &SplitCh= ':')
TStrPool64(::TSize _MxBfL=0,::TSize _GrowBy=16 *1024 *1024)
static bool IsIpStr(const TStr &IpStr, uint &Ip, const char &SplitCh= '.')
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
static int GetSecHashCd(const char *p)
int ChangeChAll(const char &SrcCh, const char &DstCh)
void SaveXml(TSOut &SOut, const TStr &Nm) const
static bool GetValFromStr(const TStr &Str)
void SaveXml(TSOut &SOut, const TStr &Nm) const
void SaveXml(TSOut &SOut, const TStr &Nm) const
bool Empty() const
Tests whether the vector is empty.
TStr GetTokStr(const bool &XmlP=true) const
double GetGammaDev(const int &Order)
TStr GetWcMatch(const TStr &WcStr, const int &StarStrN=0) const
void SplitOnCh(TStr &LStr, const char &SplitCh, TStr &RStr) const
TStrPool64 & operator=(const TStrPool64 &StrPool)
static const TStr FalseStr
void SaveXml(TSOut &SOut, const TStr &Nm) const
#define __TEST(from, to, len)
static bool GetBoolArg(const PXmlTok &XmlTok, const TStr &Nm)
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
int SearchChBack(const char &Ch, int BChN=-1) const
static bool IsWs(const char &Ch)
static TStr AddToFMid(const TStr &FNm, const TStr &ExtFMid)
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
int PutBf(const void *LBf, const TSize &LBfL)
int ChangeStrAll(const TStr &SrcStr, const TStr &DstStr, const bool &FromStartP=false)
static TStr & GetDChStr(const char &Ch1, const char &Ch2)
static int GetMn(const int &Int1, const int &Int2)
static int GetSecHashCd(const char *CStr)
#define XSaveBETagArg4(Nm, ArgNm1, ArgVal1, ArgNm2, ArgVal2, ArgNm3, ArgVal3, ArgNm4, ArgVal4)
static TStr GetNrAbsFPath(const TStr &FPath, const TStr &BaseFPath=TStr())
bool IsPrefix(const char *CStr, const int &BChN=0) const
bool IsBool(bool &Val) const
unsigned long long uint64
int CountCh(const char &Ch, const int &BChN=0) const
void SaveTxt(const PSOut &SOut) const
int SearchStr(const TStr &Str, const int &BChN=0) const
bool IsSuffix(const char *Str) const
bool IsWcMatch(const int &StrBChN, const TStr &WcStr, const int &WcStrBChN, TStrV &StarStrV, const char &StarCh='*', const char &QuestCh='?') const
bool DoFitStr(const TStr &Str) const
TChA(const int &_MxBfL=256)
static PSIn New(const TStr &Str)
void Resize(const int &_MxBfL)
TMemIn(const TMem &_Mem, const int &_BfC=0)
static int GetNum(const char &Ch)
uint GetUniDevUInt(const uint &Range=0)
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
static TRStr * GetNullRStr()
static void TestFrugalInt()
void AddBf(const void *Bf, const int &BfL)
TStr RightOf(const char &SplitCh) const
TStr & ConvUsFromYuAscii()
static double GetFltArg(const PXmlTok &XmlTok, const TStr &Nm)
TChA GetSubStr(const int &BChN, const int &EChN) const
static TStr & GetChStr(const char &Ch)
static TStr PutFBaseIfEmpty(const TStr &FNm, const TStr &FBase)
bool IsWord(const bool &WsPrefixP=true, const bool &FirstUcAllowedP=true) const
TStr & operator=(const TStr &Str)
void Del(const int &BChN, const int &EChN)
void SaveXml(TSOut &SOut, const TStr &Nm) const
static TStr GetNrFPath(const TStr &FPath)
static TStr GetNrFExt(const TStr &FExt)
static TRStr * GetRStr(const char *CStr)
void SaveBf(const void *Bf, const TSize &BfL)
char GetCh(const int &ChN) const
TChA & operator+=(const TMem &Mem)
char GetCh(const int &ChN) const
void SaveXml(TSOut &SOut, const TStr &Nm) const
void DelSubStr(const int &BChN, const int &EChN)
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
void Save(const bool &Bool)
TRnd(const int &_Seed=1, const int &Steps=0)
bool GetNextLnBf(TChA &LnChA)
static TStr PutFBase(const TStr &FNm, const TStr &FBase)
double GetPoissonDev(const double &Mean)
void SaveXml(TSOut &SOut, const TStr &Nm) const
void SaveXml(TSOut &SOut, const TStr &Nm) const
void Move(const int &Steps)
void Resize(const ::TSize &_MxBfL)
static int GetIntArg(const PXmlTok &XmlTok, const TStr &Nm)
void SaveTxt(TOLx &Lx) const
static TStr GetNumFNm(const TStr &FNm, const int &Num)
uint64 AddStr(const TStr &Str)
void PutSeed(const int &_Seed)
static bool IsAlNum(const char &Ch)
TStr LeftOf(const char &SplitCh) const
void SplitOnNonAlNum(TStrV &StrV) const
int SearchCh(const char &Ch, const int &BChN=0) const
static char * LoadFrugalInt(char *pSrc, int &i)
static bool IsValStr(const TStr &Str)
double GetBinomialDev(const double &Prb, const int &Trials)
static double GetMn(const double &Flt1, const double &Flt2)
int ChangeCh(const char &SrcCh, const char &DstCh, const int &BChN=0)
static bool IsAlpha(const char &Ch)
TStr GetStr(const uint64 &StrId) const
TChA & operator=(const TChA &ChA)
TStr LeftOfLast(const char &SplitCh) const
static TStr Fmt(const char *FmtStr,...)
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
void Swap(const int &ChN1, const int &ChN2)
int PutStr(const char *CStr)
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
void SplitOnAllCh(const char &SplitCh, TStrV &StrV, const bool &SkipEmpty=true) const
void LoadBf(const void *Bf, const TSize &BfL)
void SaveXml(TSOut &SOut, const TStr &Nm) const
bool IsSuffix(const char *CStr) const
#define EAssertR(Cond, MsgStr)
static char GetUsFromYuAscii(const char &Ch)
static bool Intersection(const TFltRect &Rect1, const TFltRect &Rect2)
static TStr GetNrNumFExt(const int &FExtN)
static TStr GetStr(const bool &Val)
void Reserve(const int &_MxBfL, const bool &DoClr=true)
void SaveXml(TSOut &SOut, const TStr &Nm) const
void Reverse()
Reverses the order of the elements in the vector.
bool DoFitLen(const int &LBfL) const
void SaveXml(TSOut &SOut, const TStr &Nm) const
static void LoadFrugalIntV(TSIn &SIn, TVec< TInt, int > &IntV, bool ClrP=true)
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
TMem(const int &_MxBfL=0)
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
int GetUniDevInt(const int &Range=0)
static TStr PutFExt(const TStr &FNm, const TStr &FExt)
void SplitOnStr(const TStr &SplitStr, TStrV &StrV) const
bool GetNextLnBf(TChA &LnChA)
void PutCh(const int &ChN, const char &Ch)
static TStr GetStr(const ldouble &Val, const int &Width=-1, const int &Prec=-1)
void SplitOnWs(TStrV &StrV) const
static char IsUc(const char &Ch)
TStr operator+(const TStr &LStr, const TStr &RStr)
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
int GetBf(const void *LBf, const TSize &LBfL)
void SplitOnLastCh(TStr &LStr, const char &SplitCh, TStr &RStr) const
uint AddStr(const char *Str, const uint &Len)
static uint GetUIntFromIpStr(const TStr &IpStr, const char &SplitCh= '.')
int GetPrimHashCd() const
void SplitOnAllAnyCh(const TStr &SplitChStr, TStrV &StrV, const bool &SkipEmpty=true) const
void InsStr(const int &BChN, const TStr &Str)
int CountCh(const char &Ch, const int &BChN=0) const
static const TStr TrueStr
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
bool GetNextLnBf(TChA &LnChA)
TStr RightOfLast(const char &SplitCh) const
void Gen(const TSizeTy &_XDim, const TSizeTy &_YDim)
static bool IsAbsFPath(const TStr &FPath)
TStrPool(const uint &MxBfLen=0, const uint &_GrowBy=16 *1024 *1024)
int ChangeStr(const TStr &SrcStr, const TStr &DstStr, const int &BChN=0)
static int GetPrimHashCd(const char *p)
void ChangeCh(const char &SrcCh, const char &DstCh)
void SaveXml(TSOut &SOut, const TStr &Nm) const
const TVal & At(const TSizeTy &X, const TSizeTy &Y) const
static TStr GetFNmStr(const TStr &Str, const bool &AlNumOnlyP=true)
TStrPool & operator=(const TStrPool &Pool)
static TStr GetXmlStrFromPlainStr(const TChA &PlainChA)
void Clr(const bool &DoDel=true)