datastring.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef __DATASTRING_H
  2. #define __DATASTRING_H
  3. // A read-only string of data.
  4. class datastring
  5. {
  6. public:
  7. char *data;
  8. int length;
  9. bool null_terminated; // Is this string null terminated?
  10. void remove_bytes_from_front(int number_of_bytes); // removes some bytes from the front of the string.
  11. datastring substr(int start);
  12. datastring substr(int start,int len);
  13. void print();
  14. void println();
  15. void clear();
  16. void null_terminate(); // Make sure this string is null terminated.
  17. void sha_256(datastring &output); // It assumes output.length == SHA256_BLOCK_SIZE * 2
  18. int compare(const char *item);
  19. int compare(datastring &item);
  20. static datastring anemptystring(); // Returns an empty string.
  21. datastring &operator=(const char *item);
  22. bool operator==(datastring &item) { return compare(item)==0; };
  23. bool operator!=(datastring &item) { return compare(item)!=0; };
  24. bool operator>(datastring &item) { return compare(item)>0; };
  25. bool operator<(datastring &item) { return compare(item)<0; };
  26. bool operator>=(datastring &item) { return compare(item)>=0; };
  27. bool operator<=(datastring &item) { return compare(item)<=0; };
  28. bool operator==(const char *item) { return compare(item)==0; };
  29. bool operator!=(const char *item) { return compare(item)!=0; };
  30. bool operator>(const char *item) { return compare(item)>0; };
  31. bool operator<(const char *item) { return compare(item)<0; };
  32. bool operator>=(const char *item) { return compare(item)>=0; };
  33. bool operator<=(const char *item) { return compare(item)<=0; };
  34. };
  35. #endif