22 #include <stk_util/diag/StringUtil.hpp> 26 #define SIERRA_STRING_UNIT_TEST 0 38 std::string std_string;
41 s = std_string.c_str();
51 for ( ; ; c1++, c2++) {
52 if ( std::tolower(*c1) != std::tolower(*c2) )
53 return ( std::tolower(*c1) - std::tolower(*c2) ) ;
72 return std::tolower(*c1) - std::tolower(*(c2 - 1));
91 const char *t2 =
find;
93 for ( ; std::tolower(*t1) && std::tolower(*t2) && !(std::tolower(*t1) - std::tolower(*t2)); ++t1, ++t2)
108 const std::string & s)
112 bool all_upper =
true;
113 bool all_lower =
true;
115 bool next_upper =
true;
116 for (std::string::iterator c = t.begin(); c != t.end(); ++c) {
117 all_upper &= (*c == std::toupper(*c));
118 all_lower &= (*c == std::tolower(*c));
120 *c = std::toupper(*c);
122 *c = std::tolower(*c);
123 next_upper = !isalpha(*c);
126 if (all_upper || all_lower)
133 template <
typename T>
138 std::ostringstream os;
143 template std::string to_string<double>(
const double &);
144 template std::string to_string<float>(
const float &);
145 template std::string to_string<int>(
const int &);
146 template std::string to_string<unsigned>(
const unsigned &);
147 template std::string to_string<long>(
const long &);
148 template std::string to_string<unsigned long>(
const unsigned long &);
155 std::ostringstream os;
157 return std::string(os.str());
166 std::ostringstream os;
168 return std::string(os.str());
177 time_t time = (time_t) t;
180 ::strftime(s,
sizeof(s), format, ::localtime(&time));
182 return std::string(s);
188 std::ostream & os)
const 191 os << m_plural <<
" no " << m_noun <<
"s";
193 os << m_singular <<
" 1 " << m_noun;
195 os << m_plural <<
" " << m_n <<
" " << m_noun <<
"s";
201 object_phrase::operator std::string()
const 203 std::ostringstream strout;
212 std::string::const_iterator
214 std::string::const_iterator p,
215 std::string::const_iterator end,
218 while (p != end && *p != c)
223 std::string::const_iterator
225 std::string::const_iterator p,
226 std::string::const_iterator end,
229 while (p != end && *p == c)
234 inline std::string::const_iterator find_next_space(std::string::const_iterator p, std::string::const_iterator end) {
235 return find_next_char(p, end,
' ');
238 inline std::string::const_iterator find_next_endl(std::string::const_iterator p, std::string::const_iterator end) {
239 return find_next_char(p, end,
'\n');
242 inline std::string::const_iterator find_next_nonspace(std::string::const_iterator p, std::string::const_iterator end) {
243 return find_next_not_char(p, end,
' ');
250 const std::string & s,
251 unsigned int line_length,
252 const std::string & prefix,
253 const std::string & prefix_first_line)
256 const std::string *u = &prefix_first_line;
258 std::string::const_iterator p0, p1, p2, p3;
259 p0 = p1 = p2 = s.begin();
261 while (p2 != s.end() ) {
264 p1 = find_next_nonspace(p0, s.end());
265 p3 = find_next_endl(p0, s.end());
266 p2 = p1 = find_next_space(p1, s.end());
268 p1 = find_next_nonspace(p1, s.end());
269 p1 = find_next_space(p1, s.end());
274 if ((
unsigned int) (p1 - p0) > (line_length - u->size()))
277 }
while (p2 != s.end());
279 t.append(*u).append(p0, p2).append(
"\n");
282 u = &prefix_first_line;
297 std::istringstream is(s.c_str());
303 std::ostringstream msg;
304 msg <<
"Unable to convert \"" << s <<
"\" to type " <<
typeid(T).name();
305 throw std::runtime_error(msg.str().c_str());
std::string title(const std::string &s)
Function title returns a first letter of each word capitalized of the string.
std::ostream & print(std::ostream &os) const
Member function print writes the object phrase to the output stream.
std::istream & getline(std::istream &is, sierra::String &s, char eol)
Function getline returns a string from the input stream which has been terminated by the newline char...
_setprecision setprecision(int precision)
Function setprecision sets the numeric precision as a manipulator.
T convert_cast(const String &s)
Class specialization hash_nocase for std::string.
std::string format_time(double t, const char *format)
Function format_time encodes the time using the format specified. The format is described in stdftime...
std::string word_wrap(const std::string &s, unsigned int line_length, const std::string &prefix, const std::string &prefix_first_line)
Function word_wrap reformats a string into multiple lines, none longer that line_length, the first line prefixed with prefix_first_line and the remaining lines prefixed with prefix.
Part * find(const PartVector &parts, const std::string &name)
Find a part by name in a collection of parts.
int case_strcmp(const char *c1, const char *c2)
Function case_strcmp compares two null terminated strings case insenstively. It returns zero if they ...
std::string to_string(const T &t)