تطبيق بسيط قابل للتخصيص لفئة سلسلة يحاكي وظائف Std :: String ، بما في ذلك التكرار.
using size_type = size_t; // size_type for positions of char in cstring
using const_pointer = const_iterator;
using pointer = iterator;
using const_reverse_pointer = const_reverse_iterator;
using reverse_pointer = reverse_iterator;
String(); // default constructor
String(const String &); // copy constructor
String(const String& other, size_type pos, size_t len = npos); // substring constructor
String(String &&); // move constructor
String(const char *); // from c-string
String(const char* s, size_t n); // from buffer
String(size_t n, char c);// fill constructor
String(const const_iterator first, const const_iterator second); // range constructor
String & operator= (const String &); // copy assignment
String & operator = (String &&); // move assignment
~String();
إرجاع ايتراتور/const_iterator إلى الحرف الأول
iterator begin();
const_iterator begin() const;
إرجاع ايتراتور/const_iterator يشير إلى الطابع الماضي من السلسلة
iterator end();
const_iterator end() const;
إرجاع const_iterator يشير إلى الحرف الأول / الحرف الماضي من السلسلة
const_iterator cbegin() const;
const_iterator cend() const;
إرجاع revers_iterator/const_reverse_iterator إلى الحرف الأخير
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
إرجاع revers_iterator/const_reverse_iterator يشير إلى عكس الحرف الماضي من السلسلة
reverse_iterator rend();
const_reverse_iterator rend() const;
إرجاع const_reverse_iterator يشير إلى الحرف الأخير / العكسي في الماضي الحرف من السلسلة
const_reverse_iterator crbegin() const;
const_reverse_iterator crend() const;
احصل على حرف من السلسلة
const char & operator [] (size_type) const;
char & operator [] (size_type);
احصل على حرف في سلسلة
const char & at(size_type) const;
char & at(size_type);
الوصول إلى الشخصية الأولى
const char & front() const;
char & front();
الوصول إلى الشخصية الأخيرة
const char & back() const;
char & back();
إلحاق للسلسلة
String & operator += (const String &); // string (1)
String & operator += (const char *); // c - string (2)
String & operator += (char); // char (3)
إلحاق للسلسلة
String& append(const String& str); // string (1)
String& append(const String& str, size_type subpos, size_t sublen = npos); // substring (2)
String& append(const char* s); // c - string (3)
String& append(const char* s, size_t n); // buffer(4)
String& append(size_type n, char c); // fill(5)
String& append(const const_iterator first, const const_iterator second); // range(6)
String & push_back(char);
أدخل في سلسلة
String& insert(size_type pos, const String& other); // string(1)
String& insert(size_type pos, const String& other, size_type subpos, size_t sublen = npos); // substring(2)
String& insert(size_type pos, const char* other); // c - string(3)
String& insert(size_type pos, const char* s, size_t n); // buffer(4)
String& insert(size_type pos, size_t n, char c); // fill(5)
void insert(iterator p, size_t n, char c); // fill(6)
iterator insert(iterator p, char c); // single character(7)
void insert(iterator p, const const_iterator first, const const_iterator last); // range(8)
محو الأحرف من String
String& erase(size_type pos = 0, size_t len = npos); // sequence(1)
iterator erase(const_iterator p); // character(2)
iterator erase(const_iterator first, const_iterator last); // range(3)
استبدال جزء من السلسلة
String& replace(size_type pos, size_t len, const String& other); // string(1)
String& replace(const_iterator i1, const_iterator i2, const String& other); // string(2)
String& replace(size_type pos, size_t len, const String& other, size_type subpos, size_t sublen = npos); // substring(3)
String& replace(size_type pos, size_t len, const char* s); // c - string(4)
String& replace(const_iterator i1, const_iterator i2, const char* other); // c - string(5)
String& replace(size_type pos, size_t len, const char* other, size_t n); // buffer(6)
String& replace(const_iterator i1, const_iterator i2, const char* other, size_t n); // buffer(7)
String& replace(size_type pos, size_t len, size_t n, char c); // fill(8)
String& replace(const_iterator i1, const_iterator i2, size_type n, char c); // fill(9)
String& replace(const_iterator i1, const_iterator i2, const_iterator first, const_iterator second); // range(10)
مبادلة القيم السلسلة
void swap(String &);
حذف الشخصية الأخيرة
String & pop_back();
احصل على ما يعادل سلسلة C
const char * c_str() const;
نسخ تسلسل الأحرف من السلسلة
size_t copy(char* s, size_t len, size_type pos = 0) const;
ابحث عن المحتوى في السلسلة
size_type find(const String& other, size_type pos = 0) const; //string(1)
size_type find(const char* s, size_type pos = 0) const; // c - string(2)
size_type find(const char* s, size_type pos, size_type n) const; // buffer(3)
size_type find(char c, size_type pos = 0) const; // character(4)
ابحث عن حدث المحتوى الأخير في السلسلة
size_type rfind(const String& other, size_type pos = npos) const; // string(1)
size_type rfind(const char* s, size_type pos = npos) const; // c - string(2)
size_type rfind(const char* s, size_type pos, size_t n) const; // buffer(3)
size_type rfind(char c, size_type pos = npos) const; // character(4)
ابحث عن الحرف في السلسلة
size_type find_first_of(const String& other, size_type pos = 0) const; // string(1)
size_type find_first_of(const char* other, size_type pos = 0) const; // c - string(2)
size_type find_first_of(const char* other, size_type pos, size_t n) const; // buffer(3)
size_type find_first_of(char c, size_type pos = 0) const; // character(4)
ابحث عن حرف في سلسلة من النهاية
size_type find_last_of(const String& other, size_type pos = String::npos) const; // string(1)
size_type find_last_of(const char* other, size_type pos = String::npos) const; // c - string(2)
size_type find_last_of(const char* other, size_type pos, size_t n) const; // buffer(3)
size_type find_last_of(char c, size_type pos = String::npos) const; // character(4)
العثور على غياب الحرف في السلسلة
size_type find_first_not_of(const String& other, size_type pos = 0) const; // string(1)
size_type find_first_not_of(const char* other, size_type pos = 0) const; // c - string(2)
size_type find_first_not_of(const char* other, size_type pos, size_t n) const; // buffer(3)
size_type find_first_not_of(char c, size_type pos = 0) const; // character(4)
ابحث عن حرف غير متطابق في سلسلة من النهاية
size_type find_last_not_of(const String& other, size_type pos = String::npos) const; // string(1)
size_type find_last_not_of(const char* other, size_type pos = String::npos) const; // c - string(2)
size_type find_last_not_of(const char* other, size_type pos, size_t n) const; // buffer(3)
size_type find_last_not_of(char c, size_type pos = String::npos) const; // character(4)
توليد فرعية
String substr(size_type pos = 0, size_t len = npos) const;
إرجاع طول السلسلة
size_t length() const;
size_t size() const;
إرجاع الحد الأقصى لحجم السلسلة
size_t max_size() const;
تغيير حجم السلسلة
void resize(size_t n);
void resize(size_type n, char c);
حجم الإرجاع للتخزين المخصص
size_t capacity() const;
طلب تغيير في السعة
void reserve(size_t n = 0);
سلسلة واضحة
void clear();
الإرجاع true هي سلسلة فارغة
bool empty() const;
تقلص لتناسب
void shrink_to_fit();
static const size_t npos = -1; // Maximum value for size_t
المقارنة
// Size is compared and if equal then comapred lexicographically
friend bool operator == (const String &, const String &);
friend bool operator != (const String &, const String &);
friend bool operator < (const String &, const String &);
friend bool operator > (const String &, const String &);
friend bool operator <= (const String &, const String &);
friend bool operator >= (const String &, const String &);
تبادل قيم سلسلتين
void swap(String& x, String& y);
إرجاع السلاسل المتسلسلة
String operator+ (const String& lhs, const String& rhs);
String operator+ (const String& lhs, const char* rhs);
String operator+ (const char* lhs, const String& rhs);
String operator+ (const String& lhs, char rhs);
String operator+ (char lhs, const String& rhs);
أدخل السلسلة في الدفق
std::ostream& operator<< (std::ostream& os, const _JD String& str);
استخراج السلسلة من الدفق
std::istream& operator>> (std::istream& is, _JD String& str);
احصل على خط من الدفق إلى سلسلة
std::istream& getline(std::istream& is, _JD String& str, char delim);
std::istream& getline(std::istream& is, _JD String& str);