This repository has been archived on 2023-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
mipt_cpp/seminar03_initialization/08_stringview/mipt.h

66 lines
1.7 KiB
C
Raw Normal View History

2022-10-22 21:32:50 +03:00
#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);
}