66 lines
1.7 KiB
C
66 lines
1.7 KiB
C
|
#pragma once
|
||
|
|
||
|
#include <iostream>
|
||
|
|
||
|
namespace mipt {
|
||
|
|
||
|
class String
|
||
|
{
|
||
|
private:
|
||
|
size_t mSize {0};
|
||
|
size_t mCapacity {0};
|
||
|
char* mpData {nullptr};
|
||
|
public:
|
||
|
String(const char* str);
|
||
|
String();
|
||
|
String(const String& s);
|
||
|
String(const mipt::StringView& sv);
|
||
|
String(size_t n, char a);
|
||
|
~String();
|
||
|
void reserve(size_t capacity);
|
||
|
void resize(size_t size);
|
||
|
String& operator=(const String& right);
|
||
|
String operator+(const String& b);
|
||
|
String& operator+=(const String& right);
|
||
|
bool operator==(const String& right) const;
|
||
|
bool operator<(const String& right) const;
|
||
|
bool operator<=(const String& right) const;
|
||
|
bool operator!=(const String& right) const;
|
||
|
bool operator>(const String& right) const;
|
||
|
bool operator>=(const String& right) const;
|
||
|
char& operator[](size_t i);
|
||
|
const char& operator[](size_t i) const;
|
||
|
char& at(size_t i);
|
||
|
void clear();
|
||
|
void addCharacter(char c);
|
||
|
size_t getSize() const;
|
||
|
size_t getCapacity() const;
|
||
|
const char* cStr() const;
|
||
|
};
|
||
|
|
||
|
std::ostream& operator<<(std::ostream& out, const 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);
|
||
|
|
||
|
}
|