/usr/include/glibmm-utils-1.0/glibmm-utils/ustring.h is in libglibmm-utils-dev 0.4.1-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* Copyright (C) 2005-2006 Dodji Seketeli
* 2007 Marko Anastasov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __GLIBMM_USTRING_UTILS_H__
#define __GLIBMM_USTRING_UTILS_H__
#include <sstream>
#include <typeinfo>
#include <vector>
#include <glibmm/ustring.h>
#include "exception.h"
namespace Glib {
namespace Util {
/// \brief Conversion exception.
class BadConversion : public Exception
{
public:
BadConversion(const Glib::ustring& msg) : Exception(msg) {}
};
/// \brief Splits a string into tokens.
std::vector<Glib::ustring> split(const Glib::ustring& str,
const Glib::ustring& delim);
/// \brief Splits a string by whitespace (after skipping any leading
/// whitespace) - like Perl's split function without the pattern.
std::vector<Glib::ustring> split(const Glib::ustring& str);
/// \brief Trims left hand side whitespace
void trim_left(Glib::ustring& str);
/// \brief Trims right hand side whitespace
void trim_right(Glib::ustring& str);
/// \brief Trims any whitespace from the string
void trim(Glib::ustring& str);
/// \brief Converts an ostream-able type to a Glib::ustring
template<typename T>
inline Glib::ustring stringify(const T& x)
{
std::ostringstream os;
if (! (os << x))
throw BadConversion(
"Cannot convert " + Glib::ustring(typeid(x).name()) + " to string");
return os.str();
}
/// \brief Converts a string to an arbitrary type that supports iostream.
/// Inspired by the C++ FAQ.
/// \param str the string to convert
/// \param x the object to hold converted value
/// \param fail_if_leftover_chars if set to true, the function will
/// throw a BadConversion exception if any characters are remaining after
/// the conversion
template<typename T>
inline void convert_to(const Glib::ustring& str,
T& x,
bool fail_if_leftover_chars = true)
{
std::istringstream is(str.raw());
char c;
if ((! (is >> x)) || (fail_if_leftover_chars && is.get(c)))
throw BadConversion(str);
}
/// \brief Converts a string to an arbitrary type that supports iostream
/// by returning by value.
/// This is a convenience function which is handy for conversions to
/// primitive types.
/// \param str the string to convert
/// \param fail_if_leftover_chars if set to true, the function will
/// throw a BadConversion exception if any characters are remaining after
/// the conversion
/// \return the object with converted value
template<typename T>
inline T convert_to(const Glib::ustring& str,
bool fail_if_leftover_chars = true)
{
T x;
convert_to(str, x, fail_if_leftover_chars);
return x;
}
/// \brief a printf() that returns a Glib::ustring
Glib::ustring uprintf(const Glib::ustring& format, ...);
} // namespace Util
} // namespace Glib
#endif // __GLIBMM_USTRING_UTILS_H__
|