void exstring::readfile(char* target)
{
   ifstream inf; inf.open(target);              //define a stream
   if(inf.fail())                               //test file
   {
      cout<<"Readfile error: target ["<<target<<"] does not exist.\n";
      return;                                   //fail -> bail
   }

   char dummy;                                  //dummy char for filesize checking
   int filesize=0;                              //counts up size necessary to allocate
   inf.get(dummy);
   while(!inf.eof())
   {
      filesize++;
      inf.get(dummy);
   }

   if(mylength>=EXSTRINGSIZE)
   {
      inf.close();
      cout<<"Readfile error: target ["<<target<<"] is too large!\n";
      return;
   }

   mylength=filesize;                           //store string length
   //delete[] mystring;                         //destroy current string
   //mystring=new char[mylength+1];             //allocate enough for file

   inf.close();                                 //reset file stream to beginning
   inf.open(target);                            //and proceed to assign char data

   int offset=-1;
   inf.get(dummy);
   while(!inf.eof())
   {
      offset++;                                 //step index "pointer"
      mystring[offset]=dummy;                   //set character
      inf.get(dummy);
   }                                            //at loopend, offset "should" == mylength

   mystring[mylength]='\0';                     //set last character to \0

   inf.close();                                 //kill stream to prevent weird errors
}

void exstring::print()
{
   cout<<mystring<<endl;
}

int exstring::conv_int()
//converts the incorporated string into an integer format and returns it
{
   bool sign=false;                    //0 positive // 1 negative
   if(mystring[0]=='-')
      sign=true;

   int ret=0;
   for(int i=0; i<length(); i++)       //consider entire string
      if('0'<=mystring[i] && mystring[i]<='9')  //considers any digit valid
      {
         ret*=10;                               //bump up an order
         ret+=int(mystring[i])-0x30;            //append digit
      }
   return (sign*-2+1)*ret;                      //return this value
}

void exstring::substring(exstring &ret, int first, int Length)
//beginning with first, returns a substring containing length characters.
//if length is 0 or less, the function returns the rest of the string less 0-length
//characters.
{
   //delete[] ret.mystring;                       //and strip it
   int newlength;                               //length of new string to create

   if(Length>0)                                 //for relative lengths
      newlength=Length;
   else                                         //for absolute eof-length
      newlength=length()+Length-first;
   //ret.mystring=new char[newlength+1];           //allocate space for new substring

   ret.mylength=newlength;
   ret.mystring[newlength]='\0';                //negate final byte
   for(int i=0; i<newlength; i++)
      ret.mystring[i]=this->mystring[first+i];  //sequentially move data over
}

void exstring::between(exstring &ret, char* beginmark, char* endmark)
//copies everything between beginmark and endmark, EXCLUSIVELY
{
   int beginindex=findme(beginmark);            //helps look for things in mystring
   int endindex=findme(endmark); //offset to find END of endmark

   if(endindex<=beginindex ||                   //if sections are out of sync,
      beginindex==-1 ||                         //or either substring
      endindex==-1)                             //is not found, then
      substring(ret,mylength,0);                //return blank

   else
      substring(ret,
                beginindex+strlen(beginmark),           //otherwise,
                endindex-beginindex-strlen(beginmark)); //simply call substring function
}                                                       //and do not include any mark data

int exstring::findme(char* target)
//locates first occurrence of target inside of mystring
//and returns index of that occurrence
//returns -1 if search failed.
{
   char* compareme;
   compareme=new char[strlen(target)+1];        //allocate space and
   compareme[strlen(target)]='\0';              //set last position to null

   int pos;                                     //keeps track of position in mystring
   for(pos=0; pos<strlen(target) && pos<mylength; pos++)
      compareme[pos]=mystring[pos];             //copy over first x chars if that's possible

   while(pos<=mylength)                         //bails out when pos points at null char
   {
      //int comp=strcmp(compareme,target);
      //cout<<pos<<" ~ "<<compareme<<" ~ "<<target<<" -> "<<comp<<endl;
      if(strcmp(compareme,target)==0)           //if strings match,
      {
         delete[] compareme;
         return pos-strlen(target);             //return index of first character matched
      }

      for(int i=0; i<strlen(target)-1; i++)     //scoot over all data in current test set
         compareme[i]=compareme[i+1];
      compareme[strlen(target)-1]=mystring[pos]; //push current pos char on to back
      pos++;
   }
   delete[] compareme;
   return -1;
}
