String
String
String
// jared bruni
// my string algorithims :)
#include "masterstring.h"
// string copy
void stringcopy(char* input,char* output)
{
strcpy(input,output);
}
// string attach
void stringattach(char* input,char* output)
{
strcat(input,output);
}
// left copy
void leftcopy(char* input,char* output,int pos)
{
int index = 0;
for(int i = 0; i < pos; i++)
{
output[index] = input[i];
index++;
}
output[index] = 0;
}
// right copy
void rightcopy(char* input,char* output,int pos)
{
int index = 0;
int len = strlen(input);
for(int i = pos; i < len; i++)
{
output[index] = input[i];
index++;
}
output[index] = 0;
}
// mid copy
void midcopy(char* input,char* output,int start_pos, int stop_pos)
{
int index = 0;
for(int i = start_pos; i < stop_pos; i++)
{
output[index] = input[i];
index++;
}
output[index] = 0;
}
int index = 0;
for(int z = 0; z < len; z++)
{
if(ptemp[z] != ' ')
{
buffer[index] = ptemp[z];
index++;
}
}
buffer[index] = 0;
delete [] ptemp;
}
if(ichk == true)
{
return i;
}
}
}
if(ichk == true)
{
return i;
}
}
}
if(ichk == true)
{
return i; // found it
}
}
}
return -1; // failure
}
// find inside backwards string loop
int ifindstrb(int startx, char* body,char* search)
{
int len = strlen(body);
int len2 = strlen(search);
if(ichk == true)
{
return i; // found it
}
}
}
return -1; // failure
}
// forward search string (controled range)
int fsearchstr(int start,int stop,char* buff,char* search)
{
int len = strlen(buff);
int len2 = strlen(search);
if(ichk == true)
{
return i; // found it
}
}
}
if(ichk == true)
{
return i; // found it;
}
}
}
// lowercase letter
int lcasel(char c)
{
return tolower(c);
}
}
else
{
ic = false;
}
}
if(ic == true)
{
f[f_i] = i;
f_i++;
}
}
}
dloc->create_array(f_i);
dloc->setstr(buff);
dloc->setsearchstr(search);
for(int p = 0; p < f_i; p++)
{
dloc->dindex[p] = f[p];
}
delete [] f;
if(f_i != 0)
{
dloc->setstatus(true);
return true; // we got some locations
}
else
{
dloc->setstatus(false);
return false; // not found
}
}
// find string location forward search
bool findstrlocf(char* buff,char* search,MasStrDataLoc* dloc)
{
return findstrloc(buff,search,dloc);
}
// find string location backwards search
bool findstrlocb(char* buff,char* search,MasStrDataLoc* dloc)
{
int len = strlen(buff);
int len2 = strlen(search);
int* f;
int f_i = 0;
f = new int[len+1];// big just in case
}
else
{
ic = false;
}
}
if(ic == true)
{
f[f_i] = i;
f_i++;
}
}
}
dloc->create_array(f_i);
dloc->setstr(buff);
dloc->setsearchstr(search);
for(int p = 0; p < f_i; p++)
{
dloc->dindex[p] = f[p];
}
delete [] f;
if(f_i != 0)
{
dloc->setstatus(true);
return true; // we got some locations
}
else
{
dloc->setstatus(false);
return false; // not found
}
}
if(ik == true)
{
mrang->SetRange(i,i+len2);
return true;
}
}
}
mrang->SetRange(0,0);
return false;
}
// string range manipluation ex (i)
bool isearchrange(int startx, char* buff,char* search,MasStrRange* mrang)
{
int len;
int len2;
len = strlen(buff);
len2 = strlen(search);
if(ik == true)
{
mrang->SetRange(i,i+len2);
return true;
}
}
}
mrang->SetRange(0,0);
return false;
}
int occ = 0;
if(ic == true)
{
occ++;
}
}
}
if(occ == 0)
{
}
else
{
return occ;
}
}
if(hi_lox == MRANGE_HI)
{
cy = mrangx->GetRangeHI();
}
else
{
cy =mrangx->GetRangeLO();
}
midcopy(input,output,cx,cy);
}
if(occ == -1)
{
return; // failure
}
list->create(occ);
int occ_i = 0;
MasStrDataLoc dloc;
if(findstrloc(buff,search,&dloc))
{
int pre_pos = 0;
charwrap cwrapx(buff,true);
rightcopy(buff,cwrapx.get(),pre_pos);
list->strings[occ_i].set(cwrapx.get());
occ_i++;
}
return;
}
// conversion of integers
void convertinteger(int integer,char* buff,int base)
{
itoa(integer,buff,base);
}
// conversion of strings
int convertstring(char* buff)
{
return atoi(buff);
}
// could this be a hexidecimal digit?
bool ishexc(char c)
{
c = lcasel(c);
switch(c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
return true;
break;
}
return false;
}
// does this string contain a non-hexidecimal digit?
bool ishex(char* buff)
{
int len;
len = strlen(buff);
c = lcasel(c);
switch(c)
{
case '0':
return 0;
break;
case '1':
return 1;
break;
case '2':
return 2;
break;
case '3':
return 3;
break;
case '4':
return 4;
break;
case '5':
return 5;
break;
case '6':
return 6;
break;
case '7':
return 7;
break;
case '8':
return 8;
break;
case '9':
return 9;
break;
case 'a':
return 10;
break;
case 'b':
return 11;
case 'c':
return 12;
case 'd':
return 13;
case 'e':
return 14;
case 'f':
return 15;
}
return -1; // failure ? never would get here
}
if(buff[1] == 0)
{
return hextointc(buff[0]);
}
int index = 0;
rt = rt + cur;
}
delete [] hexval;
return rt;
}
}
}
}
}
}
}
// replace single instance of a character
void replacechar(char* buff,char findchr,char replace)
{
int len;
len = strlen(buff);
int xt = ifindstr(NOPREV,buff,findstr);
char* temp;
temp = new char[strlen(buff)+1];
stringcopy(temp,buff);
char* ltemp;
char* rtemp;
leftcopy(buff,ltemp,xt);
rightcopy(buff,rtemp,xt+strlen(findstr));
cout << "\n#: " << ltemp << replacex << rtemp << endl;
strcpy(output,ltemp);
strcat(output,replacex);
strcat(output,rtemp);
delete [] temp;
delete [] ltemp;
delete [] rtemp;
}
// replace string
void replacestr(char* buff,char* findstr,char* replacex,char* output)
{
int xt;
xt = ifindstr(0,buff,findstr);
if(xt == -1)
{
return; // failure no string to replace
}
char* ptemp;
char* outtemp;
ptemp = new char[strlen(buff) + 500];
outtemp = new char[strlen(buff) + 500];
stringcopy(ptemp,buff);
while(1)
{
int xr;
xr = ifindstr(0,ptemp,findstr);
if(xr == -1)
{
break;
}
else
{
rmvinst(ptemp,findstr,replacex,outtemp);
stringcopy(ptemp,outtemp);
}
}
stringcopy(output,ptemp);
delete [] ptemp;
delete [] outtemp;
// random char
char randomchar(int max)
{
int x;
x = rand()%max;
char c;
c = x;
return c;
}
// random char + up
char randomchar(int max,int up)
{
int x;
x = rand()%max+up;
char c;
c = x;
return c;
}
// random string
void randomstr(char* buff,int max, int size)
{
for(int i = 0; i < size; i++)
{
if(rand()%2)
{
buff[i] = randomchar(max);
}
else
{
buff[i] = randomchar(max,rand()%10);
}
}
}
// remove char
void removechar(char* in,char* out,char c)
{
int len;
len = strlen(in);
int ic = 0;
for(int i = 0; i < len; i++)
{
if(in[i] != c)
{
out[ic] = in[i];
ic++;
}
}
out[ic] = 0;
}
return -1;
}
// find single char backward
int findcharb(char* str,char c)
{
int len;
len = strlen(str);
for(int i = len; i > 0; i--)
{
if(str[i] == c)
{
return i;
}
}
return -1;
}
// find single char backward
int ifindcharb(int start,char* str,char c)
{
int len;
len = strlen(str);
for(int i = start-1; i > 0; i--)
{
if(str[i] == c)
{
return i;
}
}
return -1;
}
int xt;
xt = ifindstr(NULLPOS,buff,findstr);
if(xt == -1)
{
return; // failure no string to replace
}
char* ptemp;
char* outtemp;
ptemp = new char[strlen(buff) + 500];
outtemp = new char[strlen(buff) + 500];
stringcopy(ptemp,buff);
while(1)
{
int xr;
xr = ifindstr(0,ptemp,findstr);
if(xr == -1)
{
break;
}
else
{
rmvstrx(ptemp,findstr,outtemp);
stringcopy(ptemp,outtemp);
}
}
stringcopy(output,ptemp);
delete [] ptemp;
delete [] outtemp;
}
void rmvstrx(char* buff,char* output,char* string)
{
int xt = ifindstr(NOPREV,buff,string);
char* temp;
temp = new char[strlen(buff)+1];
stringcopy(temp,buff);
char* ltemp;
char* rtemp;
leftcopy(buff,ltemp,xt);
rightcopy(buff,rtemp,xt+strlen(string));
strcpy(output,ltemp);
strcat(output,rtemp);
delete [] temp;
delete [] ltemp;
delete [] rtemp;
}
fout.close();
}
fin.close();
return count;
return -1;
}
output[str_i] = 0;
return true;
}
else
{
return false;
}
return false;
}
output[fcount] = 0;
}
return false;
}
if(fout)
{
fout.write((char*)&mini,sizeof(mini));
fout.close();
return true;
}
fout.close();
return false;
}
// Load master INI
bool LoadMasterINI(char* filename,MasterINI* mini)
{
ifstream fin(filename,ios::binary);
if(fin)
{
fin.read((char*)&mini,sizeof(mini));
}
fin.close();
return false;
}
if(len != len2)
{
return false; // not equal length
}
return true;
}
if(len != len2)
{
return false; // not equal length
}
return true;
}
if(chk == -1)
{
return false;
}
return true;
}
stringcopy(pbuff1,buff1);
stringcopy(pbuff2,buff2);
lcase(pbuff1);
lcase(pbuff2);
int chk;
chk = findstr(pbuff1,buff2);
delete [] pbuff1;
delete [] pbuff2;
pbuff1 = 0;
pbuff2 = 0;
if(chk == -1)
{
return false;
}
return true;
}
// string seperation from 2 points
void strsep(char* str, char* sleft, int go_left, char* sright, int go_right)
{
leftcopy(str,sleft,go_left);
rightcopy(str,sright,go_right);
}
void strsetnull(char* str,int pos)
{
str[pos] = 0;
}
if(str[z] == stop_c)
{
iadd = true;
}
if(iadd == true)
{
output[index] = str[z];
index++;
}
}
output[index] = 0;
}