Add and complete strip methods to Tairon::Core::String class.
[tairon.git] / src / core / string.h
blob31af435dc793eea6e7813e2297e5fe80531198e2
1 /***************************************************************************
2 * *
3 * Copyright (C) 2006 David Brodsky *
4 * *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Library General Public *
7 * License as published by the Free Software Foundation and appearing *
8 * in the file LICENSE.LGPL included in the packaging of this file. *
9 * *
10 * This library is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * Library General Public License for more details. *
14 * *
15 ***************************************************************************/
17 #ifndef _tairon_core_string_h
18 #define _tairon_core_string_h
20 #include <string>
21 #include <stdint.h>
23 namespace Tairon
26 namespace Core
29 /** \brief Just wrapper class around std::string.
31 * It is here because of preparation to later optimization with implicitly
32 * shared data.
34 class String : public std::string
36 public:
37 String() : std::string() {} ;
39 String(const std::string &str) : std::string(str) {};
41 String(const String &str, size_t pos, size_t count = npos) : std::string(str, pos, count) {};
43 String(const char *str, size_t size) : std::string(str, size) {};
45 String(const char *str) : std::string(str) {};
47 bool canReadLine() {
48 return contains('\n');
51 /** Returns true if the string contains given one.
53 bool contains(const String &what) const {
54 return find(what) != npos;
57 /** Returns true if the string contains given character.
59 bool contains(char what) const {
60 return find(what) != npos;
63 /** Removes all leading whitespaces. Returns reference to *this.
65 String &lstrip();
67 /** Converts given number into a string.
69 static String number(int32_t num);
71 /** Converts given number into a string.
73 static String number(uint32_t num);
75 /** Converts given number into a string.
77 static String number(int64_t num);
79 /** Converts given number into a string.
81 static String number(uint64_t num);
83 /** Cast operator.
85 operator const char *() const {
86 return c_str();
89 /** Returns string containing characters up to first newline character.
90 * The beginning of this string with newline character is removed. If
91 * there is no newline character then this method returns empty string.
93 String readLine();
95 /** Removes all trailing whitespaces from the end of the string.
96 * Returns reference to *this.
98 String &rstrip();
100 /** Removes all whitespaces from the beginning and end of the string.
101 * Returns reference to *this.
103 String &strip();
105 public:
106 static String null;
109 }; // namespace Core
111 }; // namespace Tairon
113 #endif
115 // vim: ai sw=4 ts=4 noet fdm=marker