code format
This commit is contained in:
@@ -3,24 +3,24 @@
|
||||
* \brief
|
||||
* \~english C-String class
|
||||
* \~russian Класс C-строки
|
||||
*/
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
C-String class
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
C-String class
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PICONSTCHARS_H
|
||||
@@ -35,7 +35,6 @@
|
||||
//! \~russian Класс C-строки.
|
||||
class PIP_EXPORT PIConstChars {
|
||||
public:
|
||||
|
||||
//! \~english Contructs an null string.
|
||||
//! \~russian Создает нулевую строку.
|
||||
PIConstChars() {}
|
||||
@@ -64,27 +63,27 @@ public:
|
||||
|
||||
//! \~english Read-only access to character by `index`.
|
||||
//! \~russian Доступ на чтение к символу по индексу `index`.
|
||||
inline char operator [](size_t index) const {return str[index];}
|
||||
inline char operator[](size_t index) const { return str[index]; }
|
||||
|
||||
//! \~english Read-only access to character by `index`.
|
||||
//! \~russian Доступ на чтение к символу по индексу `index`.
|
||||
inline char at(size_t index) const {return str[index];}
|
||||
inline char at(size_t index) const { return str[index]; }
|
||||
|
||||
//! \~english Returns \c char * string pointer.
|
||||
//! \~russian Возвращает \c char * указатель строки.
|
||||
inline const char * data() const {return str;}
|
||||
inline const char * data() const { return str; }
|
||||
|
||||
//! \~english Returns \c true if string doesn`t have any data.
|
||||
//! \~russian Возвращает \c true если строка не имеет данных.
|
||||
inline bool isNull() const {return !str;}
|
||||
inline bool isNull() const { return !str; }
|
||||
|
||||
//! \~english Returns \c true if string is empty, i.e. length = 0, or null.
|
||||
//! \~russian Возвращает \c true если строка пустая, т.е. длина = 0, или нулевая.
|
||||
inline bool isEmpty() const {return len == 0;}
|
||||
inline bool isEmpty() const { return len == 0; }
|
||||
|
||||
//! \~english Returns \c true if string is not empty, i.e. length > 0.
|
||||
//! \~russian Возвращает \c true если строка непустая, т.е. длина > 0.
|
||||
inline bool isNotEmpty() const {return len > 0;}
|
||||
inline bool isNotEmpty() const { return len > 0; }
|
||||
|
||||
//! \~english Returns \c true if string contains character "c".
|
||||
//! \~russian Возвращает \c true если строка содержит символ "c".
|
||||
@@ -92,15 +91,15 @@ public:
|
||||
|
||||
//! \~english Returns characters length of string.
|
||||
//! \~russian Возвращает длину строки в символах.
|
||||
inline size_t length() const {return len;}
|
||||
inline size_t length() const { return len; }
|
||||
|
||||
//! \~english Returns characters length of string.
|
||||
//! \~russian Возвращает длину строки в символах.
|
||||
inline size_t size() const {return len;}
|
||||
inline size_t size() const { return len; }
|
||||
|
||||
//! \~english Returns characters length of string.
|
||||
//! \~russian Возвращает длину строки в символах.
|
||||
inline ssize_t size_s() const {return len;}
|
||||
inline ssize_t size_s() const { return len; }
|
||||
|
||||
//! \~english Returns if string starts with "str".
|
||||
//! \~russian Возвращает начинается ли строка со "str".
|
||||
@@ -161,7 +160,7 @@ public:
|
||||
//! \~english Returns copy of this string without spaces at the start and at the end.
|
||||
//! \~russian Возвращает копию этой строки без пробельных символов с начала и конца.
|
||||
//! \~\sa \a trim()
|
||||
PIConstChars trimmed() const {return PIConstChars(*this).trim();}
|
||||
PIConstChars trimmed() const { return PIConstChars(*this).trim(); }
|
||||
|
||||
//! \~english Returns as PIString.
|
||||
//! \~russian Возвращает как PIString.
|
||||
@@ -169,7 +168,7 @@ public:
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
inline PIConstChars & operator =(const PIConstChars & s) {
|
||||
inline PIConstChars & operator=(const PIConstChars & s) {
|
||||
if (this == &s) return *this;
|
||||
len = s.len;
|
||||
str = s.str;
|
||||
@@ -178,14 +177,14 @@ public:
|
||||
|
||||
//! \~english Assign move operator.
|
||||
//! \~russian Оператор перемещающего присваивания.
|
||||
inline PIConstChars & operator =(PIConstChars && s) {
|
||||
inline PIConstChars & operator=(PIConstChars && s) {
|
||||
swap(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
inline PIConstChars & operator =(const char * s) {
|
||||
inline PIConstChars & operator=(const char * s) {
|
||||
str = s;
|
||||
len = strlen(s);
|
||||
return *this;
|
||||
@@ -193,7 +192,7 @@ public:
|
||||
|
||||
//! \~english Compare operator.
|
||||
//! \~russian Оператор сравнения.
|
||||
inline bool operator ==(const PIConstChars & s) const {
|
||||
inline bool operator==(const PIConstChars & s) const {
|
||||
if (isNull() && s.isNull()) return true;
|
||||
if (isNull() xor s.isNull()) return false;
|
||||
if (size() != s.size()) return false;
|
||||
@@ -202,27 +201,25 @@ public:
|
||||
|
||||
//! \~english Compare operator.
|
||||
//! \~russian Оператор сравнения.
|
||||
inline bool operator !=(const PIConstChars & s) const {return !(*this == s);}
|
||||
inline bool operator!=(const PIConstChars & s) const { return !(*this == s); }
|
||||
|
||||
//! \~english Compare operator.
|
||||
//! \~russian Оператор сравнения.
|
||||
inline bool operator <(const PIConstChars & s) const {
|
||||
if ( isNull() && s.isNull()) return false;
|
||||
if ( isNull() && !s.isNull()) return true ;
|
||||
if (!isNull() && s.isNull()) return false;
|
||||
if (size() == s.size())
|
||||
return strcmp(str, s.str) < 0;
|
||||
inline bool operator<(const PIConstChars & s) const {
|
||||
if (isNull() && s.isNull()) return false;
|
||||
if (isNull() && !s.isNull()) return true;
|
||||
if (!isNull() && s.isNull()) return false;
|
||||
if (size() == s.size()) return strcmp(str, s.str) < 0;
|
||||
return size() < s.size();
|
||||
}
|
||||
|
||||
//! \~english Compare operator.
|
||||
//! \~russian Оператор сравнения.
|
||||
inline bool operator >(const PIConstChars & s) const {
|
||||
if ( isNull() && s.isNull()) return false;
|
||||
if ( isNull() && !s.isNull()) return false;
|
||||
if (!isNull() && s.isNull()) return true ;
|
||||
if (size() == s.size())
|
||||
return strcmp(str, s.str) > 0;
|
||||
inline bool operator>(const PIConstChars & s) const {
|
||||
if (isNull() && s.isNull()) return false;
|
||||
if (isNull() && !s.isNull()) return false;
|
||||
if (!isNull() && s.isNull()) return true;
|
||||
if (size() == s.size()) return strcmp(str, s.str) > 0;
|
||||
return size() > s.size();
|
||||
}
|
||||
|
||||
@@ -233,21 +230,21 @@ public:
|
||||
return piHashData((const uchar *)str, len);
|
||||
}
|
||||
|
||||
inline void swap(PIConstChars& v) {
|
||||
inline void swap(PIConstChars & v) {
|
||||
piSwap<const char *>(str, v.str);
|
||||
piSwap<size_t>(len, v.len);
|
||||
}
|
||||
|
||||
private:
|
||||
const char * str = nullptr;
|
||||
size_t len = 0;
|
||||
size_t len = 0;
|
||||
};
|
||||
|
||||
|
||||
//! \relatesalso PICout
|
||||
//! \~english Output operator to \a PICout.
|
||||
//! \~russian Оператор вывода в \a PICout.
|
||||
inline PICout operator <<(PICout s, const PIConstChars & v) {
|
||||
inline PICout operator<<(PICout s, const PIConstChars & v) {
|
||||
s.space();
|
||||
if (v.isNull())
|
||||
s.write("(null)");
|
||||
@@ -260,7 +257,10 @@ inline PICout operator <<(PICout s, const PIConstChars & v) {
|
||||
}
|
||||
|
||||
|
||||
template<> inline uint piHash(const PIConstChars & s) {return s.hash();}
|
||||
template<>
|
||||
inline uint piHash(const PIConstChars & s) {
|
||||
return s.hash();
|
||||
}
|
||||
|
||||
|
||||
#endif // PICONSTCHARS_H
|
||||
|
||||
Reference in New Issue
Block a user