You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.5 KiB
71 lines
1.5 KiB
2 years ago
|
//
|
||
|
// Created by lenfrex on 2022/4/4.
|
||
|
//
|
||
|
|
||
|
#ifndef WORK20220401_STRING_H
|
||
|
#define WORK20220401_STRING_H
|
||
|
|
||
|
#include <iostream>
|
||
|
#include <string>
|
||
|
#include "utility"
|
||
|
|
||
|
using namespace std::rel_ops;
|
||
|
|
||
|
class String {
|
||
|
private:
|
||
|
// 字符数组做字符串
|
||
|
char *data = nullptr;
|
||
|
|
||
|
// 字符串实际长度
|
||
|
int length = 0;
|
||
|
|
||
|
// 已分配的字符数量
|
||
|
int allocSize = 0;
|
||
|
|
||
|
void copyData(const char *source, int sourceLength);
|
||
|
|
||
|
bool equals(const char *source, int sourceLength) const;
|
||
|
|
||
|
void addString(const char *source, int sourceLength);
|
||
|
public:
|
||
|
explicit String(int size);
|
||
|
|
||
|
String(const char *data, int length);
|
||
|
|
||
|
explicit String(const char *source);
|
||
|
|
||
|
String(const String &source);
|
||
|
|
||
|
String();
|
||
|
|
||
|
~String();
|
||
|
|
||
|
bool operator==(const String &source) const;
|
||
|
|
||
|
bool operator==(const char *source) const;
|
||
|
|
||
|
bool operator>(const String &compareString) const;
|
||
|
|
||
|
String &operator+=(const String &source);
|
||
|
|
||
|
String &operator+=(const char *source);
|
||
|
|
||
|
String &operator=(const String &source);
|
||
|
|
||
|
String &operator=(const char *source);
|
||
|
|
||
|
String &operator+(const char *source);
|
||
|
|
||
|
String &operator+(const String &source);
|
||
|
|
||
|
friend std::ostream &operator<<(std::ostream &outputStream, const String &source);
|
||
|
|
||
|
friend std::istream &operator>>(std::istream &outputStream, String &source);
|
||
|
|
||
|
char operator[](int i);
|
||
|
|
||
|
int Length() const;
|
||
|
|
||
|
};
|
||
|
|
||
|
#endif //WORK20220401_STRING_H
|