vimix

string.h

May 23rd, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. //Venix Cador
  2. //String ADT
  3. //CS23001
  4.  
  5. #ifndef STRING_HEADER
  6. #define STRING_HEADER
  7. #include <iostream>
  8. #include <cstdlib>
  9.  
  10. #define MaxString 100
  11.  
  12. class String {
  13.  
  14. public:
  15.  
  16. String(int cap = MaxString);
  17.  
  18. String(const char, int cap = MaxString);
  19.  
  20. String (const char[], int cap = MaxString);
  21.  
  22. ~String();
  23.  
  24. //copy constructor
  25. //Ex: str1 = str2;
  26. String(const String&, int cap = MaxString);
  27.  
  28. int getlength()const {return length;};
  29.  
  30. int getsize()const {return size;};
  31.  
  32. /*
  33. *returns the character from a given index
  34. * Ex: char d = str[1];
  35. */
  36. char operator [] (int) const;
  37.  
  38. char& operator [] (int);
  39.  
  40. /*
  41. *Finds the first occurence of a char in a string with zero offset
  42. *Ex: str.findchar('d');
  43. */
  44. int findchar(char)const;
  45.  
  46. int findstr(const String&)const;
  47.  
  48. String substr(int, int right = 0) const;
  49.  
  50. /*
  51. *compares a string to a character array
  52. *Ex:str =='abc';
  53. *Ex:str != 'abc';
  54. */
  55. bool operator==(const String&)const;
  56. bool operator !=(const String& rhs) const { return !(*this == rhs);};
  57. bool operator==(const char rhs[]) const { return *this == String(rhs); };
  58. bool operator!=(const char rhs[]) const { return !(*this == String(rhs)); };
  59. /*
  60. *compares if two Strings are less or grater than the others
  61. *Ex: str1 > str2;
  62. *Ex: str1 >= str2;
  63. *Ex: str1 < str2;
  64. *Ex: str1 <= str2;
  65. */
  66. bool operator <(const String&)const;
  67.  
  68. bool operator >(const String& rhs )const {return rhs < *this; } ;
  69.  
  70. bool operator >=(const String& rhs) const {return (*this < rhs ) || (*this == rhs);};
  71.  
  72. bool operator <=(const String& rhs) const {return (*this > rhs) ||(*this == rhs);};
  73.  
  74. bool isclosed() const {return s[length] == '\0';};
  75.  
  76. void reallocate(const int);
  77.  
  78. void swap(String&);
  79.  
  80. /*
  81. * add two strings together
  82. *Ex: String result = left + right;
  83. *Ex: String str1 += str2;
  84. *Ex: String result = left + " ! !";
  85. *Ex: String result = left + ' ! '
  86. */
  87. String operator + (const String&) const;
  88. String operator + (const char rhs[]) const {return *this + String(rhs);};
  89. String operator + (const char rhs) const {return *this + String(rhs);};
  90. String& operator += (const String& rhs) {return *this = *this + rhs;};
  91. String& operator += (const char rhs[]) {return *this = *this + String (rhs);};
  92. String& operator += (const char rhs){return *this = *this + String (rhs);}
  93. String& operator = (String);
  94.  
  95. //the function for the nextblank
  96. int nextBlank(int d = 0) const;
  97.  
  98. //function prototype for find the nesxnonblank
  99.  
  100. int nextNonBlank(int x = 0) const;
  101.  
  102. String justify(const in) const;
  103.  
  104. String justifyFile(std::ifstream in, std::ofstream& out, left, right);
  105. int getLength() const { return length; };
  106.  
  107. private:
  108.  
  109. char *s;
  110.  
  111. int size;
  112.  
  113. int length;
  114.  
  115.  
  116. };
  117.  
  118. std::istream& operator >>(std::istream&, String&);
  119. std::ostream& operator <<(std::ostream&, const String&);
  120.  
  121. #endif
Advertisement
Add Comment
Please, Sign In to add comment