.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Cyborg Factory > United Bot
United Bot The ultimate beast is being given birth right here! Half-Life 2

Reply
 
Thread Tools
Strings In United Bot
Old
  (#1)
Magnus
Guest
 
Status:
Posts: n/a
Default Strings In United Bot - 24-05-2004

I have a string class which I have been developing for a year, it is very advanced amd could be used in United Bot, for example in Kicking a bot you just type kick Magnus instead of the whole "[United Bot] Magnus rocks etc etc etc (Skill=Infinity).
Here i have posted it:
Code:
 
/*--------------------------------------------------------------------
					 String Class
			  For the Ease of Use of the String functions.
			  Incorporates the String Functions into an
			  object oriented design.
			  
  Author: Jamal Abid; 16; Oman.
 //As of 12th December 2003, I became 17
 //Yay.
  Nationality: Pakistani;
  Update History: 17 June 2003 --Created
				   ->Basic Declarations Added
				   ->Barebones Structure erected
					 -->Basic String Operations can be performerd
					 -->Dont expect string.h level functionality, yet
				   ->Optimized the structure
					-->For efficiency.
					-->For readability.
				  18 June 2003 --Adding Functionality
				   ->Added the Split function
					-->Allows you to split a string into two.
					-->You may even pass through again to split it 
					   into many, many parts
				  24 June 2003 --More Functionality
				   ->Added the print function
					--> Allows you to print out the string in DOS
				   ->Overloaded the - operator in two ways
					-->One takes a string and wipes instances of that
					   String from the main string.
					-->The other takes a char and deletes that char
					   once from the string and reports the place
					-->NOTE: EXPERIMENTAL, NOT IMPLEMENTED IN THIS 
					   RELEASE, JUST CONCEPTUALIZED!
				  27 June 2003 --A long day of programming...
				   ->Overloaded the = operator to accept pointers to 
					 chars(char arrays) also.
					-->Created the Ctor private function to share 
					   code between overloaded versions of the 
					   constructor and the = function which both take
					   the same parameter and do the same thing...
				   ->Fixed a major bug in the Split function which
					 rendered 50% of it useless; the second string
					 had a null character added to its first char,
					 which made sure it was always a null string.
				   ->Partially implemented the operator - function;
					 rest will be completed later
					-->Renamed it to Delete, it took more parameters
					   than the arity of the applicable operators
					   permitted
					-->Enumerated the deletion type
				   ->Whoops! The Print method was not needed, the 
					 GetString function was present, must have 
					 overlooked it...
				   ->Created the Compare function
					-->No more strcmp, Yay!
					-->Compares Irrespective of case and/or
					   disregards punctuations if so desired.
					-->Enumerated the compare type.
					-->Added the FullCompare private function.
					-->Added the CompareNoPunc private function.
				   ->Added the Capitalize function.
				   ->Added the MakeSmall function.
				   ->Too Tired... Will do the Delete function later.
					 Oh Cozy bedroom.. where art thou?
				  28 June 2003 --Completion of basic structure
				   ->Completed the Delete Function today
					-->Now has three overloaded functions
					 --->One takes a string
					 --->The other takes a char array
					 --->And the last takes one char
				   ->Removed 56 bugs!
					-->These were the errors, things that stopped the
					   compilation, I am expecting LOTS of runtime
					   bugs as well
				   ->Will optimize it tomorrow
					-->Optimizing approx. 700 something lines of code
					   is no joke!
				   -> As of today, almost everything basic has been 
					  coded
					--> BUT Delete and Compare DONT WORK!
					 ---> Trying to sort this out will probably take
						  a whole day to comb through this mess
					  ---->Never write uncommented code
					   ----->This has now been proven! It takes me a 
							 few mins to make out what it is doing..
				   -> Started Commenting the whole code today
					--> YUCK!
				  29 June 2003 --MAJOR Debugging
				   ->I do not want to comment any further; will do so
					 later when the class is stable and works
				   ->Now everything runs
					-->But there are bugs to be ironed out
					 --->Compare and delete dont work fully
					 --->I am trying to fix them.
					  ---->But i think this will take two days...
				   ->The Progress of Fixing (I will write as I fix)
					-->Fixed the full compare, now it actually does
					   compare... 3 bugs were working together to 
					   mess up the result...
					-->The problems in delete werent as severe and
					   hard to track as i thought, fixed the delete,
					   now it does what its supposed to. Yay!
					 --->Just found a small bug, gonna fix it NOW.
					  ---->FIXED!!!
					-->Now fixed the ALL Part, the Once part remains
				  30 June 2003 --More Debugging
				   ->Fixed the ALL part of Delete
				   ->I cant get the Delete(String) to work...
					-->I am trying to find a way to make sure the
					   whole string exists.
					-->It is not impossible but expect it to be 
					   memory intensive, with many string objects
					   flying around, especially in the ALL part
				   ->Added the CalcLen private function
					-->Calculates the length of a string
					-->string.h is not needed now!!
				   ->Made the String(Len) constructor private
				  1 July 2003 --Its gone too far
				   ->I am taking a two day break, no more work for
					 today and tomorrow
					-->That does NOT mean I wont be touching the code
					-->I will be going through it, every now and then
					-->But I WONT make any modifications
					 --->I will just note the problems down and worry
						 about them later.
				   ->Forget about the break, I am working again
				   ->Now implmented and prefected the functions which
					 make String.hpp independent
					-->string.h now has no use if you want basic 
					   functions
				   ->Its time to optimize
					-->I will keep you updated on the process
					-->unsigned short int has now been replaced by
					   unsigned long int
					 --->Now you can make LONG strings
					 --->Enjoy!
					-->The length is now stored on the free store
					 --->No big deal
					 --->The time consuming part was modifying all the
						 lines of code that want to take its value
					  ---->Had to add ()s and *s to them
					-->Now I am trying to get the code to use the 
					   heap
				  2 July 2003 --The beginning of the End
				   ->Now fully uses the heap.
				   ->On to Optimization
					-->Tried Compiling the new "heapified" code
					   118 ERRORS!!! Will take some time to 
					   correct
					-->Down to 20 errors...
					-->Errors Gone, Let the optimization begin!
					-->Uh oh! Forgot the freeing memory part
					-->Will take some time(again...)
				  4 July 2003 --A day with no comments
				   ->Been working all day yesterday, ironing out the
					 errors and optimizing, will be doing the 
					 same thing today..
				   ->I have a new design idea, if it works out,
					 string.h level functionality could be one step 
					 closer in a week of coding. That is IF it works 
					 out, I wil be testing it today and tomorrow 
					 and probably start the actual implementation
					 on the day after tomorrow.
				   ->Wrote the Find function, its a blast to work
					 with, enter a char, a start position and an 
					 ending position for the search and tell it 
					 how many of the same chars it finds to skip,
					 and it returns the position of that char
					 Cool eh?
				  6 July --Delays and problems
				   ->Went out with family day before yesterday, 
					 little time for coding
				   ->Yesterday the PC refused to boot, on further 
					 ivestigation I found out it had blown its
					 Power box, got a new one fitted, no coding
					 done yesterday.
				   ->Today, the Delete Engine shall be completely
					 overhauled -IF IT IS NOT EFFICIENT-
				  7 July --Getting back into the groove
				   ->The new Delete Engine Concept works and is more
					 efficient and faster than before, not to mention
					 cleaner.
				   ->Now I am going to complete another part of the
					 delete engine.
				  8 July --Trying hard to get back into the groove
				   ->Had to go out with family yesterday, again.
				   ->Work is going slow, I hope it picks up pace
				   ->Delete was never so CLEAN!!
				   ->Implementing the concept further...
				   ->Delete is causing a LOT of problems, I hope it
					 works soon...
				  9 July --Programming Delays
				   ->Went out again yesterday.
				   ->Will have to go out tomorrow again.
				   ->Today I am trying to squeeze in as much 
					 programming as my hands and eyes allow.
				   ->Find has a nasty bug which I cannot find and
					 is messing every dependent function up...
					-->Will probably start from scratch, again
					-->But I wont change the parameters and return
					   type they are the best possible
				   ->Am going to change the whole structure from
					 C++ Style zero style [] operators to 1 style
					 for example the first element from now on
					 will not be [0] but [1], this is done to make
					 the class easier and more natural to use.
				  10 July --Relief, At Last!
				   ->I fixed the bug in find which messed delete up
					 it took more than three days to track it down,
					 but its fixed, actually it was a compound bug
					 helped by no less than 4 lines of code, all of
					 them equally guilty!
				   ->Still thinking about whether to convert the
					 structure to 1 style...
				   ->Delete All still doesnt work!!
				  11 July --oh great
				   ->Went out yesterday TWO TIMES!
				   ->Luckily, I have two days today and tomorrow
					 before we go out again...
				   ->The problem was also with delete(offset), I 
					 fixed that too... Now on to delete(all), once
					 seems to work fine...
				   ->Fixed the Delete, now everything works!
				   ->I can FINALLY start focusing on adding 
					 functionality
				   ->I have an append function in mind, lets see 
					 how that works out...
				  12 July --Bad Code
				   ->I am having the worst case of code-rot possible,
					 all my functions which worked fine just a 
					 fortnight ago, now have all simultaneously 
					 broken down, I am fixing them one by one
					-->I think what has happened is that my changing
					   of the basic Engine, has invalidated the 
					   old calls, causing a major break-down
					 --->But the shocking thing is that there were 
						 no compiler errors...
					-->This may be shocking but I think I'll need
					   a week to fix this mess, its the biggest
					   I've ever seen.
					-->I fixed the problem, whew. It was'nt any 
					   engine malfunctions, just a flawed concept,
					   let me take a few lines to explain...
					 --->You see when I coded the operator+ function,
						 GetString was non-existent, so I used a loop
						 to get the data, which worked, due to a little
						 glitch, a null was added in between the two
						 concatenated strings, literally ending the 
						 string! I fixed it, it took a lot of 
						 debugging with a lot of variable watching
						 but its done...
					-->I can now (again) concentrate on adding more
					   features
					-->NEW FEATURES!!
					 --->GetPartial gets the string from a start 
						 position to an end position, neat eh?
					 --->Overloaded + operator now can take quite a 
						 load now, whereas before only String
						 Addidtion was possible, now you can add 
						 C style strings AND chars.   
					 --->I have stumbled upon a technique which makes
						 code super-efficient, maybe with further 
						 testing I may be able to implement it.
				  13 July 2003  --Adding Polish
				   ->Did some tweaking here and there to polish up 
					 the code.
				  19 December 2003 --Long time no see++
				   ->WOW! 6 months with no C++, i forgot everything 
					 about the language
					-->Am trying to recover and start work on project
					   again
				   ->Fixed the operator+= function
					-->It didnt actually add....
					-->Dont know how i did it, but i did it
					 --->probably due to my completely forgetting 
						 about the C++ Language
				   ->Completed the GetPartial Function
					-->Renamed it to GetString
					 --->Now it is an overloaded function
					 --->It is a part of my plans to overload all the
						 GetStrings to operator<<s
				   ->I have been reading through my old comments and
					 somewhere i sid that it is going to take a week
					 to repair everything, it hs been six months and 
					 the functions are so broken that the WHOLE delete
					 needs to rewritten, I have removed the old code
					 and am wroking on the new function
				   ->There are a LOT of greatly flawed concepts here
					-->There is only one way out, reanalyze, strip, 
					   recode, test, repeat until done.
					 --->BUT! TOMORROW...
				   ->Surprisingly, I havent coded a Find String
					 Function, will do
				  24 December 2003 --Christmas Eve
				   ->Merry Christmas to all you Christians
				   ->Compare NoPunc Fixed
				   ->New functionality for Compare
					-->Embodies all the features of the other compares
					-->Is more Robust
				   ->Find now works for strings
					-->Uses a complex compare algorithm
					-->Returns the position of first char of string
					   found.
					-->Last char position can be worked out by the 
					   user of the String Class by adding the
					   length of the String that was entered in the 
					   find argument
					25 December --Christmas
					 ->Merry Christmas, again
					 ->Stripped and modified a lot of functions
					  -->Mainly, Find and Delete
					  -->For the stripped functions the idea has been
						 penned and will be coded shortly
					 ->There you have it, a spanking new, efficient, 
					   350HP Beast that is Compare. Fully retooled to
					   perfection
					26 December --IT COMPILES!
					 ->After exactly one week of retooling, this 
					   behemoth class actually compiles
					 ->My heart cries whenever i see so many functions
					   that have no body or just return a dummy value
					  -->It is because they were inefficient,
						 malfunctioning (pun unintended)or just plain
						 bad screwed up
					 ->A lot of redundant functions that have no use
					   now are lingering around like FullCompare, 
					   CompareNoPunc and CompareNoCase.
					  -->A lot of code uses them so todays task is
						 adapting the rest of the code to work with
						 the new and improved engine
					  -->Done
					 27 December 2003--Find me a solution!
					  ->Been working all day with the damned Find
					   -->Delete depends on it
					  ->Will be testing today
					  ->Code needs serious optimization
					   -->Maybe tomorrow
					 28 December 2003--Merry Bug Fix Day!
					  ->I finally picked out the bug which was messing
						the WHOLE CLASS up
					   -->It was in the Delete(ULI, ULI) function
					   -->It lead me to doubt my complex string 
						  delete algorithm!
					 29 December 2003 --Big Changes
					  ->Further development of the class now depends
						on changing it from 0-style to 1-style
					   -->It may be easier or more difficult to use
						  depending on how much 0-style C++ Arrays
						  are hard-wired into your brain
					   -->But I am compelled to do it for a variety of
						  reasons
						--->1.Returning no value found. What do find
							find functions return if nothing is found?
							0. So, zero should not be a valid position
						--->2.It is more natural to the human brain
					   -->I am expecting 100% chaotic breakdown once i
						  do this
						--->So i am waiting till the weekend (Thursday
							and Friday over here) to do this dirty work
					 4 January 2004 --Of Men, Strings And War
					  ->I am going to start the 1 style conversion
					   -->Let the battle begin!
					   -->I am making a backup, incase i mess this up
					   -->Better than rewriting this monster for a
						  second time!
						--->I said rewriting for a second time which
							writing for the third time! 
					 
  Legal Stuff:  (c) Jamal Abid 2003-Infinity (forever). 
				
		 Terms and Conditions (License Agreement)
				
				You CAN Modify this file BUT
				 ->You have to give give credit to me AND any
				   previous modifiers who have their modifications
				   added to the file you receive.
				 ->You have to add your own credits (so that any
				   future modifiers can include your name).
				 ->Give full explanations of your modifications and 
				   date them. You can use the layout used in the 
				   author's comments
				 ->You may not prevent someone else from having 
				   the exact same rights as you.
				  -->That is you can not give more rights nor
					 deny them to future recipients of this file
				You MAY NOT use this file in the following types 
				of programs
				 ->Programs that are made for any department of the
				   Government of any country.
				 ->In areas where the failure of this project can 
				   incur heavy personal, financal or any other types 
				   of losses.
				 ->In projects which are illegal or help any other
				   illegal project as dictated by the laws of the 
				   country in  which this project is being worked on.
				You MAY use this program in any other type of
				projects (Yes, even commercial projects)
				You MAY charge for a modified version of this program.
				But you MAY NOT remove or modify this comment
				block  marked off and surrounded by ----s.
				You can also not modify any of the other authors
				comments, and you are not allowed to give the right
				to others to modify your comment block. Doing so or
				modifying these comments is a breach of the 
				copyright law and this will persecuted to the fullest
				extent.
				Added your comments in a different comment block 
				above or below this.
				Also, I accept no liability for any losses, nor do I 
				demand any royalties or a share in the profit, this, 
				original , version of the file is free. Feel
				free to report problems and suggestions etc. to
				da_monster@hotmail.com
				All rights not expressly granted are reserved by me,
				Jamal Abid. 
				 
				Please read the license before reading 
				any further, modifying or incorporating
				this file. By reading further, modifying, 
				incorporating and by any means using or transmitting 
				this file you express that you have read the agreement 
				and agree to abide by its terms.
				Also, I may create a new version of licese and it is 
				your responsibility to ask for the lastest version of
				it. I have no liability or responsibility of notifying
				any of the recipients of this file of the change in 
				license or in the file itself. The latest version of
				the license will be enforced. I reserve the right to
				make any changes to this license.
				Any and all violations shall be persecuted under 
				the fullest extent of the law.
				Report Violations at da_monster@hotmail.com
TO DO: Make Me on the heap and use references to access the 
	   operator[] function.
--------------------------------------------------------------------*/
#include <iostream>
using namespace std;
typedef unsigned long int ULI;
class String
{
 public:
  String();
  String(const char*);
  String(const String&);
  ~String();
  void Split(String&, String&, ULI);
  bool Compare(const String&, bool, bool);
  void Capitalize();
  void MakeSmall();
  char operator[](ULI) const; //For Data reading
  char &operator[](ULI); //For Data writing
  //const char *operator<<();
  String operator+(const String&);
  String operator+(const char*);
  String operator+(char);
  void operator+=(const String&);
  void Delete(const String&, bool, bool, bool, ULI);
  void Delete(const char*, bool, bool, bool, ULI);
  void Delete(ULI, ULI);
  void Delete(ULI);
  String &operator=(const String&);
  String &operator=(const char*); 
  ULI GetLen() const;
  String GetString(ULI, ULI) const;
  const char *GetString() const; //Use this to get the string, for now
  ULI Find(char, ULI, ULI, ULI);
  ULI Find(const char*, ULI, ULI, bool, bool, ULI);
  ULI Find(const String&, ULI, ULI, bool, bool, ULI);
 private:
  String(ULI Len);
  void Ctor(const char*);
  void DeletePunc();
  ULI CalcLen(const char*) const;
  char *itsString;
  ULI *itsLen;
};
String::String()
{
 itsString=new char[1];
 itsString[0]='\0';
 itsLen=new ULI(0);
}
String::String(const char *TheString)
{
 itsLen=new ULI(0);
 Ctor(TheString);
}
String::String(const String &TheString)
{
 itsLen=new ULI(TheString.GetLen());
 itsString=new char[(*itsLen)+1];
 ULI *i=new ULI(0);
 for (*i=0; (*i)<(*itsLen);(*i)++)
 {
  itsString[(*i)]=TheString[(*i)];
 }
 delete i;
 itsString[GetLen()]='\0';
}
String::String(ULI Len)
{
 itsString=new char[Len+1];
 ULI *i=new ULI(0);
 for (*i=0; (*i)<=Len; (*i)++)
 {
  itsString[(*i)]='\0';
 }
 delete i;
 itsLen=new ULI(Len);
}
String::~String ()
{
 delete[] itsString;
 delete itsLen;
}
void String::Split(String &FirstString, String &SecondString, ULI Place)
{
 ULI *i=new ULI(0);
 const String &Me=*this;
 String *FirstHeap=new String(Place);
 String &First=*FirstHeap;
 for((*i)=0; (*i)<(First.GetLen()); (*i)++)
 {
  First[(*i)]=Me[(*i)];
 }
 ULI *MyLen=new ULI(this->GetLen());
 ULI *LenStringTwo=new ULI(((*MyLen)-Place));
 String *SecondHeap=new String((*LenStringTwo)-1);
 String &Second=*SecondHeap;
 ULI *j=new ULI(0);
 for((*j)=0; (*j)<(*LenStringTwo); (*i)++, (*j)++)
 {
  Second[(*j)]=Me[(*i)];
 }
 delete i;
 delete j;
 delete MyLen;
 delete LenStringTwo;
 FirstString=First;
 SecondString=Second;
 delete FirstHeap;
 delete SecondHeap;
}
bool String::Compare(const String &TheString, bool CaseSensitive, bool PuncSensitive)
{
 String *MeHeap=new String(*this);
 String *CompareStringHeap=new String(TheString);
 String &Me=*MeHeap;
 String &CompareString=*CompareStringHeap;
 ULI *MyLen=new ULI(Me.GetLen());
 ULI *YourLen=new ULI(CompareString.GetLen());
 bool Result=false;
 if((*MyLen)==(*YourLen))
 {
  if(!CaseSensitive)
  {
   Me.Capitalize();
   CompareString.Capitalize();
  }
  if(!PuncSensitive)
  {
   Me.DeletePunc();
   CompareString.DeletePunc();
  }
  ULI *i=new ULI(0);
  ULI *CharsCaught=new ULI(0);
  for((*i)=0; (*i)<(*MyLen); (*i)++)
  {
   if(Me[(*i)]==TheString[(*i)])
   {
	(*CharsCaught)++;
   }
  }
  if((*CharsCaught)==(*MyLen))
  {
   Result=true;
  }
  delete CharsCaught;
 }
 delete MeHeap;
 delete CompareStringHeap;
 return Result;
}
void String::Capitalize()
{
 String *MeHeap=new String(*this);
 String &Me=*MeHeap;
 ULI *MyLen=new ULI(Me.GetLen());
 char *Mine=new char('\0');
 int *MyASCII=new int(0);
 ULI *i=new ULI(0);
 for(*i=0; (*i)<(*MyLen); (*i)++)
 {
  *Mine=Me[(*i)];
  *MyASCII=int(*Mine);
  if((*MyASCII)==97)
  {
   Me[(*i)]='A';
  }
  if((*MyASCII)==98)
  {
   Me[(*i)]='B';
  }
  if((*MyASCII)==99)
  {
   Me[(*i)]='C';
  }
  if((*MyASCII)==100)
  {
   Me[(*i)]='D';
  }
  if((*MyASCII)==101)
  {
   Me[(*i)]='E';
  }
  if((*MyASCII)==102)
  {
   Me[(*i)]='F';
  }
  if((*MyASCII)==103)
  {
   Me[(*i)]='G';
  }
  if((*MyASCII)==104)
  {
   Me[(*i)]='H';
  }
  if((*MyASCII)==105)
  {
   Me[(*i)]='I';
  }
  if((*MyASCII)==106)
  {
   Me[(*i)]='J';
  }
  if((*MyASCII)==107)
  {
   Me[(*i)]='K';
  }
  if((*MyASCII)==108)
  {
   Me[(*i)]='L';
  }
  if((*MyASCII)==109)
  {
   Me[(*i)]='M';
  }
  if((*MyASCII)==110)
  {
   Me[(*i)]='N';
  }
  if((*MyASCII)==111)
  {
   Me[(*i)]='O';
  }
  if((*MyASCII)==112)
  {
   Me[(*i)]='P';
  }
  if((*MyASCII)==113)
  {
   Me[(*i)]='Q';
  }
  if((*MyASCII)==114)
  {
   Me[(*i)]='R';
  }
  if((*MyASCII)==115)
  {
   Me[(*i)]='S';
  }
  if((*MyASCII)==116)
  {
   Me[(*i)]='T';
  }
  if((*MyASCII)==117)
  {
   Me[(*i)]='U';
  }
  if((*MyASCII)==118)
  {
   Me[(*i)]='V';
  }
  if((*MyASCII)==119)
  {
   Me[(*i)]='W';
  }
  if((*MyASCII)==120)
  {
   Me[(*i)]='X';
  }
  if((*MyASCII)==121)
  {
   Me[(*i)]='Y';
  }
  if((*MyASCII)==122)
  {
   Me[(*i)]='Z';
  }
 }
 *this=Me;
 delete MeHeap;
 delete MyLen;
 delete Mine;
 delete MyASCII;
}
void String::MakeSmall()
{
 String *MeHeap=new String(*this);
 String &Me=*MeHeap;
 ULI *MyLen=new ULI(Me.GetLen());
 char *Mine=new char('\0');
 int *MyASCII=new int(0);
 ULI *i=new ULI(0);
 for(*i=0; (*i)<(*MyLen); (*i)++)
 {
  *Mine=Me[(*i)];
  *MyASCII=int(*Mine);
  if((*MyASCII)==65)
  {
   Me[(*i)]='a';
  }
  if((*MyASCII)==66)
  {
   Me[(*i)]='b';
  }
  if((*MyASCII)==67)
  {
   Me[(*i)]='c';
  }
  if((*MyASCII)==68)
  {
   Me[(*i)]='d';
  }
  if((*MyASCII)==69)
  {
   Me[(*i)]='e';
  }
  if((*MyASCII)==70)
  {
   Me[(*i)]='f';
  }
  if((*MyASCII)==71)
  {
   Me[(*i)]='g';
  }
  if((*MyASCII)==72)
  {
   Me[(*i)]='h';
  }
  if((*MyASCII)==73)
  {
   Me[(*i)]='i';
  }
  if((*MyASCII)==74)
  {
   Me[(*i)]='j';
  }
  if((*MyASCII)==75)
  {
   Me[(*i)]='k';
  }
  if((*MyASCII)==76)
  {
   Me[(*i)]='l';
  }
  if((*MyASCII)==77)
  {
   Me[(*i)]='m';
  }
  if((*MyASCII)==78)
  {
   Me[(*i)]='n';
  }
  if((*MyASCII)==79)
  {
   Me[(*i)]='o';
  }
  if((*MyASCII)==80)
  {
   Me[(*i)]='p';
  }
  if((*MyASCII)==81)
  {
   Me[(*i)]='q';
  }
  if((*MyASCII)==82)
  {
   Me[(*i)]='r';
  }
  if((*MyASCII)==83)
  {
   Me[(*i)]='s';
  }
  if((*MyASCII)==84)
  {
   Me[(*i)]='t';
  }
  if((*MyASCII)==85)
  {
   Me[(*i)]='u';
  }
  if((*MyASCII)==86)
  {
   Me[(*i)]='v';
  }
  if((*MyASCII)==87)
  {
   Me[(*i)]='w';
  }
  if((*MyASCII)==88)
  {
   Me[(*i)]='x';
  }
  if((*MyASCII)==89)
  {
   Me[(*i)]='y';
  }
  if((*MyASCII)==90)
  {
   Me[(*i)]='z';
  }
 }
 *this=Me;
 delete MeHeap;
 delete MyLen;
 delete Mine;
 delete MyASCII;
 delete i;
}
char String::operator[](ULI Number) const
{
 if (Number>(*itsLen))
 {
  return itsString[(*itsLen)];
 }
 else
 {
  return itsString[Number];
 }
}
char &String::operator[](ULI Number)
{
 if (Number>(*itsLen))
 {
  return itsString[(*itsLen)];
 }
 else
 {
  return itsString[Number];
 }
}
/*
const char *String::operator<<()
{
 return itsString;
}
*/
String String::operator+(const String &TheString)
{
 String *MeHeap=new String(*this);
 String &Me=*MeHeap;
 ULI *TotalLen=new ULI(Me.GetLen()+TheString.GetLen());
 String AddedString(*TotalLen);
 delete TotalLen;
 ULI *i=new ULI(0);
 for(*i=0; (*i)<(Me.GetLen()-1); (*i)++)
 {
  AddedString[(*i)]=Me[(*i)];
 }
 delete MeHeap;
 ULI *j=new ULI(0);
 for(*j=0; (*j)<TheString.GetLen(); (*i)++, (*j)++)
 {
  AddedString[(*i)]=TheString[(*j)];
 }
 delete i;
 delete j;
 return AddedString;
}
String String::operator+(const char *CharString)
{
 String *TheStringHeap=new String(*CharString);
 String &TheString=*TheStringHeap;
 String Return((*this)+CharString);
 delete TheStringHeap;
 return Return;
}
String String::operator+(char TheChar)
{ 
}
void String::operator+=(const String &TheString)
{
 ULI *TheStringLen=new ULI(TheString.GetLen()-1);
 ULI *MyLen=new ULI((*itsLen)-1);
 ULI *TotalLen=new ULI((*MyLen)+(*TheStringLen));
 String *NewStringHeap=new String((*TotalLen)+1);
 String &NewString=*NewStringHeap;
 ULI *i=new ULI(0);
 ULI *j=new ULI(0);
 for (*i=0; (*i)<(*MyLen); (*i)++)
 {
  NewString[(*i)]=itsString[(*i)];
 }
 for (*j=0; (*j)<(*TheStringLen); (*i)++, (*j)++)
 {
  NewString[(*i)]=TheString[(*j)];
 }
 NewString[(*TotalLen)]='\0';
 *this=NewString;
 delete TheStringLen;
 delete MyLen;
 delete TotalLen;
 delete NewStringHeap;
 delete i;
 delete j;
}
void String::Delete(const String &TheString, bool CaseSensitive, bool PuncSensitive, bool All, ULI Skip)
{
 //TODO: Find a way to ignore case and punctuation marks without
 //	  actually altering the string.
 //FOUND A WAY: USE THE FIND FUNCTION AND PASS THE PUNC AND CASE
 //			 SENSITIVE ARGUMENTS OVER TO THE FIND FUNCTION AND
 //			 ACT ON THAT
 //PROBLEM WITH CONCEPT: PUNCTUATION CHANGES LENGTH HOW TO COMPUTE NEW
 //					  LENGTH AND WHERE IS THE PUNCTUATION??
 //TODO: Implement a skip feature also.
 if(PuncSensitive)
 {
  String *Me=new String(*this);
  String *DeleteString=new String(TheString);
  ULI *StartPos=new ULI(0);
  ULI *EndPos=new ULI(0);
  if(All)
  {
   do
   {
	Delete(TheString, CaseSensitive, PuncSensitive,0, Skip);
   }
   while(!((*StartPos)==0)); //while a new string is found
  }
  else
  {
   *StartPos=Find(TheString, 0, Me->GetLen(), CaseSensitive, PuncSensitive, Skip);
   *EndPos=((*StartPos)+TheString.GetLen())-2;
   Delete(*StartPos, *EndPos);   
  }
  delete StartPos;
  delete EndPos;
  delete Me;
  delete DeleteString;
 }
 else
 {
  /*
  //Pseudo Code: (for task understanding)
  //Test Where the Punctuation is
  //See by how the string changes
  // 
  String *MeHeap=new String(*this);
  String &Me=*MeHeap;
  ULI *MyLen=new ULI(Me.GetLen());
  Me.DeletePunc();
  ULI *MyLenNoPunc=new ULI(Me.GetLen());
  ULI *NoOfPuncs=new ULI((*MyLen)-(*MyLenNoPunc));
  ULI *PuncPos=new ULI[(*NoOfPuncs)][2];
  ULI *i=new ULI(0);
  ULI *j=new ULI(0);
  ULI *k=new ULI(0);
  int *Type=new int(0);
  ULI *Pos=new ULI(0);
  for((*i)=0; (*i)<(*NoOfPuncs); (*i)++)
  {
   PuncPos[(*i)][0]=0;
   PuncPos[(*i)[1]=0;
  }
  ULI *Skip=new ULI(0);
  do
  {
   *Pos=Find(',', 0, Me.GetLen(), 1, 1, *Skip);
   (*Skip)++;
   *PuncPos[0][0]=
  }
  while(!((*Pos)==0));
  delete Skip;
  delete Type;
  delete MeHeap;
  delete MyLen;
  delete MyLenNoPunc;
  delete NoOfPuncs;
  delete Pos;
  delete i;
  delete j;
  delete k;
  */
 }
}
void String::Delete(const char *TheString, bool CaseSensitive, bool PuncSensitive, bool All, ULI Skip)
{
 String *NewString=new String(TheString);
 Delete(*NewString, CaseSensitive, PuncSensitive, All, Skip);
 delete NewString;
}
void String::Delete(ULI StartPos, ULI EndPos)
{
 ULI *i=new ULI(StartPos);
 ULI *j=new ULI(*i);
 for((*i)=StartPos; (*i)<=EndPos; (*i)++)
 {
  Delete(*j);
 }
 delete i;
 delete j;
}
String &String::operator=(const String &TheString)
{
 if (this==&TheString)
 {
  return *this;
 }
 else
 {
  delete[] itsString;
  delete itsLen;
  itsLen=new ULI(TheString.GetLen());
  itsString=new char[(*itsLen)+1];
  ULI *i=new ULI(0);
  for (*i=0; (*i)<(*itsLen); (*i)++)
  {
   itsString[(*i)]=TheString[(*i)];
  }
  itsString[(*itsLen)]='\0';
  return *this;
  delete i;
 }
}
String &String::operator=(const char *CharArray)
{
 delete[] itsString;
 Ctor(CharArray);
}
ULI String::GetLen() const
{
 return *itsLen;
}
String String::GetString(ULI StartPos, ULI EndPos) const
{
 if(StartPos>EndPos)
 {
  String *MeHeap=new String(*this);
  String &Me=*MeHeap;
  String *PartialHeap=new String((EndPos-StartPos)+1);
  String &Partial=*PartialHeap;
  ULI *i=new ULI(StartPos-1);
  for(*i=(StartPos-1); (*i)<(EndPos-1); (*i)++)
  {
   Partial[(*i)]=Me[(*i)];
  }
   delete MeHeap;
   delete PartialHeap;
   delete i;  
  return Partial;
 }
 else
 {
  return String(""); 
 }
}
const char *String::GetString() const //OBSOLETE!! WILL BE DELETED SOON
{
 return itsString;
}
void String::Ctor(const char *TheString)
{
 *itsLen=CalcLen(TheString);
 itsString=new char[(*itsLen)+1];
 ULI *i=new ULI(0);
 for (*i=0; (*i)<(*itsLen); (*i)++)
 {
  itsString[(*i)]=TheString[(*i)];
 }
 itsString[(*itsLen)]='\0';
 delete i;
}
ULI String::CalcLen(const char *TheString) const
{ 
 char *Null=new char('a');
 ULI Counter=0;
 while(!((*Null)=='\0'))
 {
  *Null=TheString[Counter];
  ++Counter;
 }
 delete Null;
 return Counter;
}
ULI String::Find(char TheChar, ULI StartPos, ULI EndPos, ULI Skip)
{
 String *MeHeap=new String(*this);
 String &Me=*MeHeap;
 ULI *MyLen=new ULI(Me.GetLen());
 ULI *CharsCaught=new ULI(0);
 ULI *Start=new ULI(StartPos-1);
 ULI *Stop=new ULI(EndPos-1);
 ULI *i=new ULI(*Start);
 ULI Pos=0;
 ULI *Prev=new ULI(Pos);
 Skip++;
 for((*i)=(*Start); (*i)<=(*Stop); (*i)++)
 {
  if(Me[(*i)]==TheChar)
  {
   if((*CharsCaught)<Skip)
   {
	Pos=*i;
	++(*CharsCaught);
   }
  }
 }
 if((*CharsCaught)<=(Skip-1))
 {
  Pos=Me.GetLen();
 }
 delete Prev;
 delete MeHeap;
 delete MyLen;
 delete CharsCaught;
 delete i;
 return Pos;
}
ULI String::Find(const String &TheString, ULI StartPos, ULI EndPos, bool CaseSensitive, bool PuncSensitive, ULI Skip)
{
 String *MeHeap=new String(*this);
 String &Me=*MeHeap;
 String *FindStringHeap=new String(TheString);
 String &FindString=*FindStringHeap;
 ULI MyLen=Me.GetLen();
 ULI TheStringLen=TheString.GetLen();
 char MyChar='\0';
 char TheStringChar='\0';
 int i=0;
 int j=0;
 int Pos=0;
 if(!CaseSensitive)
 {
  Me.Capitalize();
  FindString.Capitalize();
 }
 for(i=0; i<MyLen; i++)
 {
  MyChar=Me[i];
  TheStringChar=FindString[j];
  if(MyChar==TheStringChar)
  {
   if(j==0) //If it is first char found, record its position
   {
	Pos=i;
   }
   j++;
  }
  else
  {
   j=0;
  }
  if(j==(TheStringLen/*-1*/))
  {
   if(Skip==0)
   {
	delete MeHeap;
	delete FindStringHeap;
	return Pos;
   }
   else
   {
	Skip--;
   }
  }
 }
 delete MeHeap;
 delete FindStringHeap;
 return 0;
}
ULI String::Find(const char *TheString, ULI StartPos, ULI EndPos, bool CaseSensitive, bool PuncSensitive, ULI Skip)
{
 ULI Pos=0;
 String *FindString=new String(TheString);
 Pos=Find(*FindString, StartPos, EndPos, CaseSensitive, PuncSensitive, Skip);
 delete FindString;
 return Pos;
}
void String::Delete(ULI Pos)
{
 String *MeHeap=new String(*this);
 String &Me=*MeHeap;
 String *NewStringHeap=new String(Me.GetLen()-1);
 String &NewString=*NewStringHeap;
 ULI *i=new ULI(0);
 ULI *j=new ULI(0);
 while((*i)<Pos)
 {
  NewString[(*i)]=Me[(*i)];
  ++(*i);
 }
 *j=*i;
 (*i)++;
 for(*j=(*i)-1; (*j)<Me.GetLen(); (*i)++, (*j)++)
 {
  NewString[(*j)]=Me[(*i)];
 }
 delete MeHeap;
 *this=NewString;
 delete NewStringHeap;
 delete i;
 delete j;
}
void String::DeletePunc()
{
 this->Delete(',', 0, 0, 1, 0);
 this->Delete('.', 0, 0, 1, 0);
 this->Delete('\'', 0, 0, 1, 0);
 this->Delete('-', 0, 0, 1, 0);
 this->Delete('_', 0, 0, 1, 0);
 this->Delete('\"', 0, 0, 1, 0);
 this->Delete('(', 0, 0, 1, 0);
 this->Delete(')', 0, 0, 1, 0);
 this->Delete('?', 0, 0, 1, 0);
 this->Delete('!', 0, 0, 1, 0);
 this->Delete(',', 0, 0, 1, 0);
}
This is from a backup i took in January, the new version has most functions stripped out and is in the progress of streamlining so this backup is posted.
So is it of any use, i would be delighted to offer more snippets on anything, just tell me, i would like to give 100% of what i can offer to United Bot Development.
-Jamal
  
Reply With Quote
Re: Strings In United Bot
Old
  (#2)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: Strings In United Bot - 24-05-2004

what are the advantages over the std string class from #include <string> ? why not use the std one and write an own one ?

just curious


  
Reply With Quote
Re: Strings In United Bot
Old
  (#3)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Strings In United Bot - 24-05-2004

His own seems to have "advanced" search/replacement token capabilities, of which I don't know if the standard C++ strings are capable. However, 2 points:

1.- Using an own class dedicated to strings is slow, and we want the fastest code we can get (without coding the bot in ASM, of course) ;
2.- For portability and cleanliness, it is best to use Unicode, this class is not Unicode capable as I see it.



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: Strings In United Bot
Old
  (#4)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: Strings In United Bot - 24-05-2004

well, too slow ? hm, maybe we should have the option of fixed sized strings, but strlen(szWhatever) shouldnt be faster than string.length() I guess. Dynamic allocation for appending something to the string might be using some time, but this operations are not used that often, and could be avoided by telling how many elements we wanna allocate in the constructor ...
about that unicode stuff : just replace all chars with some typedef type, so that the class can easily be recompiled for unicode without having to search the whole code

but I know PMB, you believe that C++ is always slower, I know, so I guess I should stop here


  
Reply With Quote
Re: Strings In United Bot
Old
  (#5)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Strings In United Bot - 24-05-2004

nagger

I don't believe "just replacing all chars with some typedef type" would work ; if you notice, in ANSI C Unicode and classical characters are a completely different topic, which call completely different functions. You just can't use strstr, strlen, strrchr, strcpy and the likes properly on a typedef'ed char type. C99 which is the latest ANSI C defines the WCHAR type, and recommends the use of wstrstr, wstrlen, wstrrchr, wstrcpy etc. which are all suited for Unicode and belong to all standard C libs since 1999.

Anyway, dynamic allocation of string bits is what I was referring to. We must avoid as much new() and malloc()s as possible. We could use the same technique as HL1: have a string table and only reference constant strings by their pointer.

The bot chat engine (whether Eliza or a MegaHal bastard) usually requires a lot of dynamic string allocations so I guess we'll have to handle this issue cleverly.



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: Strings In United Bot
Old
  (#6)
Magnus
Guest
 
Status:
Posts: n/a
Default Re: Strings In United Bot - 25-05-2004

Yeah, you are right, I actually coded this for past-time, i will see if i can come up with an extremely light version of this. Could you give me the amount of bytes of memory we need to be working in so i can start from scratch with that in mind. I ddont know much about Unicode, could someone direct me to some material (free of course) on the 'net to help me continue developing the string engine for United Bot,
  
Reply With Quote
Re: Strings In United Bot
Old
  (#7)
botman
Super Moderator
 
Status: Offline
Posts: 280
Join Date: Jan 2004
Location: Plano, TX
Default Re: Strings In United Bot - 26-05-2004

In general, it's almost ALWAYS better to use standard libraries for commonly used code (like Strings). Using the Standard Template Library (stl) means that you already have thousands of people testing out the available functions and you won't have to worry about finding and fixing bugs in your code.

You generally shouldn't re-invent the wheel unless you have a specific problem that hasn't been solved by someone else.

If you want to do this as an exercise for yourself, that's fine, but, I for one, would much rather use the stl string class for any string management code (since it's very stable and very efficient).

botman
  
Reply With Quote
Re: Strings In United Bot
Old
  (#8)
Magnus
Guest
 
Status:
Posts: n/a
Default Re: Strings In United Bot - 26-05-2004

Ok Thanks, I amgoing to go ahead and come up with the string anyway, i have found the stl version of string to be quite inadequate myself as i was learning C++, you had to deal with the null characer there were lengths including null and without and what not, i thought making the user forget the null would lead to lesser buffer overflows and would be easier to use. United Bot could use an advanced yet light string engine as kicking and singling out bots ofr actions are very painful in the other bots (except RealBot) and you loase the data by turning the [] Clan Tags and () Skill Tags off. I think testing should not be a problem, we have a large, user-base at our disposal, dont we?
  
Reply With Quote
Re: Strings In United Bot
Old
  (#9)
botmeister
Ex-Council Member
 
botmeister's Avatar
 
Status: Offline
Posts: 1,090
Join Date: Nov 2003
Location: Canada
Default Re: Strings In United Bot - 27-05-2004

Quote:
Originally Posted by Magnus
Ok Thanks, I amgoing to go ahead and come up with the string anyway, i have found the stl version of string to be quite inadequate myself as i was learning C++, you had to deal with the null characer there were lengths including null and without and what not, i thought making the user forget the null would lead to lesser buffer overflows and would be easier to use. United Bot could use an advanced yet light string engine as kicking and singling out bots ofr actions are very painful in the other bots (except RealBot) and you loase the data by turning the [] Clan Tags and () Skill Tags off. I think testing should not be a problem, we have a large, user-base at our disposal, dont we?
I recommend that you simply extend the std string class instead of writing a new one from scratch.


Maker of the (mEAn) Bot.Admin Manager

"In theory, there is no difference between theory and practice. But, in practice, there is." - Jan L.A. van de Snepscheut
  
Reply With Quote
Re: Strings In United Bot
Old
  (#10)
Magnus
Guest
 
Status:
Posts: n/a
Default Re: Strings In United Bot - 27-05-2004

Sir, Yes Sir.
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com