101 lines
2.7 KiB
C
101 lines
2.7 KiB
C
|
#ifndef KYLINSTRING_H
|
||
|
#define KYLINSTRING_H
|
||
|
|
||
|
#include "Object.h"
|
||
|
#include <string.h>
|
||
|
|
||
|
namespace Kylin {
|
||
|
|
||
|
class String : public Object {
|
||
|
public:
|
||
|
String();
|
||
|
String(const char c);
|
||
|
String(const char *str);
|
||
|
String(const String &str);
|
||
|
String(String &&other);
|
||
|
~String();
|
||
|
String &operator=(const String &str);
|
||
|
String &operator=(const char *str);
|
||
|
inline const char *str() const { return m_str; }
|
||
|
inline size_t length() const { return m_length; }
|
||
|
|
||
|
bool startWith(const char *s) const;
|
||
|
bool startWith(const String &s) const;
|
||
|
bool endOf(const char *s) const;
|
||
|
bool endOf(const String &s) const;
|
||
|
String &insert(size_t index, const char *s);
|
||
|
String &insert(size_t index, const String &s);
|
||
|
String &trim();
|
||
|
|
||
|
int indexOf(const char *s) const;
|
||
|
int indexOf(const String &s) const;
|
||
|
|
||
|
String &remove(size_t index, size_t length);
|
||
|
String &remove(const char *s);
|
||
|
String &remove(const String &s);
|
||
|
|
||
|
String &replace(const char *t, const char *s);
|
||
|
String &replace(const String &t, const char *s);
|
||
|
String &replace(const char *t, const String &s);
|
||
|
String &replace(const String &t, const String &s);
|
||
|
|
||
|
String substr(size_t index, size_t length) const;
|
||
|
|
||
|
char &operator[](size_t index);
|
||
|
char operator[](size_t index) const;
|
||
|
|
||
|
bool operator<(const char *str) const;
|
||
|
bool operator<(const String &str) const;
|
||
|
|
||
|
bool operator>=(const char *str) const;
|
||
|
bool operator>=(const String &str) const;
|
||
|
|
||
|
bool operator>(const char *str) const;
|
||
|
bool operator>(const String &str) const;
|
||
|
|
||
|
bool operator<=(const char *str) const;
|
||
|
bool operator<=(const String &str) const;
|
||
|
|
||
|
bool operator==(const char *str) const;
|
||
|
bool operator==(const String &str) const;
|
||
|
|
||
|
bool operator!=(const char *str) const;
|
||
|
bool operator!=(const String &str) const;
|
||
|
|
||
|
String &operator+=(const char *str);
|
||
|
String &operator+=(const String &str);
|
||
|
|
||
|
String operator+(const char *str) const;
|
||
|
String operator+(const String &str) const;
|
||
|
|
||
|
String &operator-=(const char *str);
|
||
|
String &operator-=(const String &str);
|
||
|
|
||
|
String operator-(const char *str) const;
|
||
|
String operator-(const String &str) const;
|
||
|
|
||
|
protected:
|
||
|
void init(const char *str);
|
||
|
static size_t *make_pmt(const char *p);
|
||
|
static int kmp(const char *s, const char *p);
|
||
|
|
||
|
public:
|
||
|
static int sunday(const char *str, const char *pattern);
|
||
|
|
||
|
private:
|
||
|
char *m_str = nullptr;
|
||
|
size_t m_length = 0;
|
||
|
};
|
||
|
} // namespace Kylin
|
||
|
|
||
|
#include <ostream>
|
||
|
namespace std {
|
||
|
inline std::ostream &operator<<(std::ostream &stream, const Kylin::String &string) {
|
||
|
stream << string.str();
|
||
|
return stream;
|
||
|
}
|
||
|
|
||
|
} // namespace std
|
||
|
|
||
|
#endif // KYLINSTRING_H
|