Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- enum
- {
- EXP_VALUE = 2
- };
- class String
- {
- class Buffer;
- Buffer* buffer = nullptr;
- public:
- String(const char* s = nullptr)
- {
- size_t len = strlen(s);
- if (len != 0)
- {
- }
- }
- String(const String& copy_string)
- {
- }
- ~String()
- {
- }
- String& operator= (const String& assign_string)
- {
- }
- String& operator+= (const String& concat_string)
- {
- }
- char& operator[] (const size_t index)
- {
- return buffer->get_index(index);
- }
- char operator[] (const size_t index) const
- {
- }
- };
- class String::Buffer
- {
- void* owner_address = nullptr;
- char* data = nullptr;
- size_t length = 0;
- size_t capacity = 0;
- void make_correct_for_length(size_t required_length)
- {
- if (required_length >= capacity)
- {
- capacity = EXP_VALUE * capacity + 1;
- char* new_data = new char[capacity];
- for (size_t i = 0; i < length; i++)
- {
- new_data[i] = data[i];
- }
- delete[] data;
- data = new_data;
- }
- }
- public:
- void add(const char* text, size_t len)
- {
- make_correct_for_length(length + len);
- for (size_t i = 0; i < len; i++)
- {
- data[length + i] = text[i];
- }
- }
- char& get_index(size_t index) const
- {
- return data[index];
- }
- Buffer() {};
- ~Buffer()
- {
- if (length != 0)
- {
- delete[] data;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement