Add and complete strip methods to Tairon::Core::String class.
[tairon.git] / src / core / string.cpp
blobc27a409fcfbf193fcf725be3a3a405332a0c4573
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 #include <cctype>
18 #include <sstream>
20 #include "string.h"
22 namespace Tairon {
24 namespace Core {
26 String String::null;
28 /* {{{ String::lstrip() */
29 String &String::lstrip()
31 size_t pos = 0;
32 while (isspace((*this)[pos]) && (pos < length()))
33 ++pos;
34 erase(0, pos);
36 return *this;
38 /* }}} */
40 /* {{{ String::number(int32_t) */
41 String String::number(int32_t num)
43 std::stringstream str;
44 str << num;
45 return str.str();
47 /* }}} */
49 /* {{{ String::number(uint32_t) */
50 String String::number(uint32_t num)
52 std::stringstream str;
53 str << num;
54 return str.str();
56 /* }}} */
58 /* {{{ String::number(int64_t) */
59 String String::number(int64_t num)
61 std::stringstream str;
62 str << num;
63 return str.str();
65 /* }}} */
67 /* {{{ String::number(uint64_t) */
68 String String::number(uint64_t num)
70 std::stringstream str;
71 str << num;
72 return str.str();
74 /* }}} */
76 /* {{{ String::readLine() */
77 String String::readLine()
79 size_t n = find('\n');
80 if (n == npos)
81 return String();
83 String ret = substr(0, n);
84 erase(0, n + 1);
85 return ret;
87 /* }}} */
89 /* {{{ String::rstrip() */
90 String &String::rstrip()
92 size_t pos = length() - 1;
93 while (isspace((*this)[pos]) && (pos != npos))
94 --pos;
95 erase(pos + 1);
97 return *this;
99 /* }}} */
101 /* {{{ String::strip() */
102 String &String::strip()
104 return lstrip().rstrip();
106 /* }}} */
108 }; // namespace Core
110 }; // namespace Tairon
112 // vim: ai sw=4 ts=4 noet fdm=marker