finished stringview
This commit is contained in:
		
							parent
							
								
									ec50d811ff
								
							
						
					
					
						commit
						2da7623dd3
					
				
					 5 changed files with 40 additions and 32 deletions
				
			
		|  | @ -1,8 +1,6 @@ | ||||||
| #include <iostream> | #include <iostream> | ||||||
| //#include "miptstring.cpp"
 | #include "miptstring.h" | ||||||
| //#include "miptstringview.cpp"
 | #include "miptstringview.h" | ||||||
| #include "mipt.h" |  | ||||||
| 
 |  | ||||||
| using namespace std; | using namespace std; | ||||||
| 
 | 
 | ||||||
| int main() { | int main() { | ||||||
|  | @ -13,6 +11,8 @@ int main() { | ||||||
|     //cout << (b < a) << endl;
 |     //cout << (b < a) << endl;
 | ||||||
|     //cout << (bv < av) << endl;
 |     //cout << (bv < av) << endl;
 | ||||||
|     cout << av.substr(1,10) << endl;  |     cout << av.substr(1,10) << endl;  | ||||||
|     av.remove_suffix(5); |     av.remove_suffix(2); | ||||||
|     cout << av << endl; |     cout << av << endl; | ||||||
|  |     mipt::String meow = av; | ||||||
|  |     cout << "sv to string: " << meow << endl; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -2,7 +2,8 @@ | ||||||
| #include <algorithm> | #include <algorithm> | ||||||
| #include <cstdlib> | #include <cstdlib> | ||||||
| #include <cstring> | #include <cstring> | ||||||
| #include "mipt.h" | #include "miptstring.h" | ||||||
|  | #include "miptstringview.h" | ||||||
| using std::cout, std::cin, std::endl, std::size_t; | using std::cout, std::cin, std::endl, std::size_t; | ||||||
| 
 | 
 | ||||||
| namespace mipt{ | namespace mipt{ | ||||||
|  | @ -29,12 +30,12 @@ String::String() : String("") {} | ||||||
| String::String(const String& s) : String(s.cStr()) {} | String::String(const String& s) : String(s.cStr()) {} | ||||||
| String::String(const StringView& sv) { | String::String(const StringView& sv) { | ||||||
|         mSize = sv.size(); |         mSize = sv.size(); | ||||||
|         self.reserve(mSize); |         (*this).reserve(mSize); | ||||||
|         for(int i = 0; i < mSize; ++i) |         for(int i = 0; i < mSize; ++i) | ||||||
|             mpData[i] = sv[i]; |             mpData[i] = sv[i]; | ||||||
|         mpData[mSize] = '\0'; |         mpData[mSize] = '\0'; | ||||||
|          |          | ||||||
|     } | } | ||||||
| 
 | 
 | ||||||
| String::String(size_t n, char a) | String::String(size_t n, char a) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -1,9 +1,9 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 |  | ||||||
| #include <iostream> | #include <iostream> | ||||||
| 
 | 
 | ||||||
| namespace mipt { | namespace mipt { | ||||||
| 
 | 
 | ||||||
|  | class StringView; | ||||||
| class String  | class String  | ||||||
| { | { | ||||||
| private: | private: | ||||||
|  | @ -40,26 +40,4 @@ public: | ||||||
| 
 | 
 | ||||||
| std::ostream& operator<<(std::ostream& out, const String& s); | std::ostream& operator<<(std::ostream& out, const String& s); | ||||||
| std::istream& operator>>(std::istream& in, String& s);  | std::istream& operator>>(std::istream& in, String& s);  | ||||||
| 
 |  | ||||||
| class StringView  |  | ||||||
| { |  | ||||||
| private: |  | ||||||
|     const char* mpData; |  | ||||||
|     size_t mSize; |  | ||||||
| public:   |  | ||||||
|     StringView(); |  | ||||||
|     StringView(const StringView& str); |  | ||||||
|     StringView(const mipt::String& s); |  | ||||||
|     StringView(const char* s); |  | ||||||
|     const char& at(size_t i); |  | ||||||
|     const char& operator[](size_t i) const; |  | ||||||
|     bool operator<(const StringView& right) const; |  | ||||||
|     size_t size() const; |  | ||||||
|     StringView substr(size_t pos, size_t count); |  | ||||||
|     void remove_prefix(size_t n);  |  | ||||||
|     void remove_suffix(size_t n); |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| std::ostream& operator<<(std::ostream& out, const StringView& sv); |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  | @ -2,7 +2,8 @@ | ||||||
| #include <algorithm> | #include <algorithm> | ||||||
| #include <cstdlib> | #include <cstdlib> | ||||||
| #include <cstring> | #include <cstring> | ||||||
| #include "mipt.h" | #include "miptstring.h" | ||||||
|  | #include "miptstringview.h" | ||||||
| using std::cout, std::cin, std::endl, std::size_t; | using std::cout, std::cin, std::endl, std::size_t; | ||||||
| 
 | 
 | ||||||
| namespace mipt { | namespace mipt { | ||||||
|  |  | ||||||
							
								
								
									
										28
									
								
								seminar03_initialization/08_stringview/miptstringview.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								seminar03_initialization/08_stringview/miptstringview.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,28 @@ | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <iostream> | ||||||
|  | 
 | ||||||
|  | namespace mipt { | ||||||
|  | class String; | ||||||
|  | class StringView  | ||||||
|  | { | ||||||
|  | private: | ||||||
|  |     const char* mpData; | ||||||
|  |     size_t mSize; | ||||||
|  | public:   | ||||||
|  |     StringView(); | ||||||
|  |     StringView(const StringView& str); | ||||||
|  |     StringView(const mipt::String& s); | ||||||
|  |     StringView(const char* s); | ||||||
|  |     const char& at(size_t i); | ||||||
|  |     const char& operator[](size_t i) const; | ||||||
|  |     bool operator<(const StringView& right) const; | ||||||
|  |     size_t size() const; | ||||||
|  |     StringView substr(size_t pos, size_t count); | ||||||
|  |     void remove_prefix(size_t n);  | ||||||
|  |     void remove_suffix(size_t n); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | std::ostream& operator<<(std::ostream& out, const StringView& sv); | ||||||
|  | 
 | ||||||
|  | } | ||||||
		Reference in a new issue