String.h
/*
* $Id: String.h 3383 2012-08-22 13:18:02Z karijes $
*
* A simple string class
* Copyright (c) 2005-2007 edelib authors
*
* This library 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 2 of the License, or (at your option) any later version.
*
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __EDELIB_STRING_H__
#define __EDELIB_STRING_H__
#include "edelib-global.h"
#include <string.h>
EDELIB_NS_BEGIN
class EDELIB_API String {
public:
#ifndef SKIP_DOCS
typedef unsigned int size_type;
#endif
private:
#ifndef SKIP_DOCS
struct StringData {
size_type length;
size_type capacity;
char *chars;
};
#endif
static StringData null_data;
StringData* sdata;
void init(size_type len, size_type cap);
void dispose(void);
public:
static const size_type npos;
String();
String(const char* str);
String(const String& str);
~String();
String& assign(const char* str, size_type len);
String& assign(const char* str);
String& assign(const String& str);
String& append(const char* str, size_type len);
String& append(const char* str);
String& append(const String& str);
String& append(size_type num, const char& ch);
void reserve(size_type len);
void swap(String& from);
String substr(size_type index, size_type num = npos) const;
size_type find(const char* str, size_type offset) const;
size_type find(char ch, size_type offset) const;
size_type find(const char* str) const;
void clear(void);
void printf(const char* fmt, ...);
void trim_left(void);
void trim_right(void);
void trim(void);
const char* c_str(void) { return sdata->chars; }
const char* c_str(void) const { return sdata->chars; }
const char* data(void) const { return sdata->chars; }
size_type length(void) const { return sdata->length; }
size_type capacity(void) const { return sdata->capacity; }
bool empty(void) const { return length() == 0; }
String& replace(char c1, char c2);
char& operator[](size_type index);
char operator[](size_type index) const;
String& operator=(const char* str);
String& operator=(const String& str);
String& operator+=(const char* str);
String& operator+=(const String& str);
String& operator+=(const char& ch);
};
EDELIB_API String operator+(const String& s1, const String& s2);
EDELIB_API String operator+(const char* s1, const String& s2);
EDELIB_API String operator+(const String& s1, const char* s2);
inline bool operator==(const String& str1, const char* str2) { return (strcmp(str1.c_str(), str2) == 0); }
inline bool operator!=(const String& str1, const char* str2) { return (strcmp(str1.c_str(), str2) != 0); }
inline bool operator>(const String& str1, const char* str2) { return (strcmp(str1.c_str(), str2) > 0); }
inline bool operator>=(const String& str1, const char* str2) { return (strcmp(str1.c_str(), str2) >= 0); }
inline bool operator<(const String& str1, const char* str2) { return (strcmp(str1.c_str(), str2) < 0); }
inline bool operator<=(const String& str1, const char* str2) { return (strcmp(str1.c_str(), str2) <= 0); }
inline bool operator==(const char* str1, const String& str2) { return (strcmp(str1, str2.c_str()) == 0); }
inline bool operator!=(const char* str1, const String& str2) { return (strcmp(str1, str2.c_str()) != 0); }
inline bool operator>(const char* str1, const String& str2) { return (strcmp(str1, str2.c_str()) > 0); }
inline bool operator>=(const char* str1, const String& str2) { return (strcmp(str1, str2.c_str()) >= 0); }
inline bool operator<(const char* str1, const String& str2) { return (strcmp(str1, str2.c_str()) < 0); }
inline bool operator<=(const char* str1, const String& str2) { return (strcmp(str1, str2.c_str()) <= 0); }
inline bool operator==(const String& str1, const String& str2)
{ return (str1.length() == str2.length()) && (strcmp(str1.c_str(), str2.c_str()) == 0); }
inline bool operator!=(const String& str1, const String& str2) { return (strcmp(str1.c_str(), str2.c_str()) != 0); }
inline bool operator>(const String& str1, const String& str2) { return (strcmp(str1.c_str(), str2.c_str()) > 0); }
inline bool operator>=(const String& str1, const String& str2) { return (strcmp(str1.c_str(), str2.c_str()) >= 0); }
inline bool operator<(const String& str1, const String& str2) { return (strcmp(str1.c_str(), str2.c_str()) < 0); }
inline bool operator<=(const String& str1, const String& str2) { return (strcmp(str1.c_str(), str2.c_str()) <= 0); }
EDELIB_NS_END
#endif
edelib::String::empty
bool empty(void) const
Definition: String.h:298
edelib::String::operator<=
bool operator<=(const String &str1, const String &str2)
Definition: String.h:456
edelib::String::operator>
bool operator>(const String &str1, const String &str2)
Definition: String.h:438
edelib::String::operator>=
bool operator>=(const char *str1, const String &str2)
Definition: String.h:407
edelib::String::c_str
const char * c_str(void) const
Definition: String.h:282
edelib::String::operator>
bool operator>(const String &str1, const char *str2)
Definition: String.h:365
edelib::String::operator==
bool operator==(const char *str1, const String &str2)
Definition: String.h:389
edelib::String::operator==
bool operator==(const String &str1, const char *str2)
Definition: String.h:353
edelib::String::c_str
const char * c_str(void)
Definition: String.h:279
edelib::String::operator==
bool operator==(const String &str1, const String &str2)
Definition: String.h:425
edelib::String::operator>
bool operator>(const char *str1, const String &str2)
Definition: String.h:401
edelib::String::operator<=
bool operator<=(const char *str1, const String &str2)
Definition: String.h:419
edelib::String::operator<
bool operator<(const char *str1, const String &str2)
Definition: String.h:413
edelib::String::operator<=
bool operator<=(const String &str1, const char *str2)
Definition: String.h:383
edelib::String::operator>=
bool operator>=(const String &str1, const String &str2)
Definition: String.h:444
edelib::String::length
size_type length(void) const
Definition: String.h:292
edelib::String
A (relatively simple) string implementation.
Definition: String.h:82
edelib::String::data
const char * data(void) const
Definition: String.h:289
edelib::String::operator!=
bool operator!=(const String &str1, const String &str2)
Definition: String.h:432
edelib::String::npos
static const size_type npos
Definition: String.h:111
edelib::String::operator!=
bool operator!=(const String &str1, const char *str2)
Definition: String.h:359
edelib::String::operator<
bool operator<(const String &str1, const String &str2)
Definition: String.h:450
edelib::String::capacity
size_type capacity(void) const
Definition: String.h:295
edelib::String::operator<
bool operator<(const String &str1, const char *str2)
Definition: String.h:377
edelib::String::operator>=
bool operator>=(const String &str1, const char *str2)
Definition: String.h:371
edelib::String::operator!=
bool operator!=(const char *str1, const String &str2)
Definition: String.h:395