4 /* Copyright (C) 2002 The gtkmm Development Team
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <glibmm/stringutils.h>
22 #include <glibmm/utility.h>
26 #include <glibmmconfig.h>
28 GLIBMM_USING_STD(out_of_range)
29 GLIBMM_USING_STD(overflow_error)
30 GLIBMM_USING_STD(underflow_error)
33 bool Glib::str_has_prefix(const std::string& str, const std::string& prefix)
35 return g_str_has_prefix(str.c_str(), prefix.c_str());
38 bool Glib::str_has_suffix(const std::string& str, const std::string& suffix)
40 return g_str_has_suffix(str.c_str(), suffix.c_str());
43 double Glib::Ascii::strtod(const std::string& str)
45 std::string::size_type dummy;
46 return Glib::Ascii::strtod(str, dummy, 0);
49 double Glib::Ascii::strtod(const std::string& str,
50 std::string::size_type& end_index,
51 std::string::size_type start_index)
53 if(start_index > str.size())
54 throw std::out_of_range("out of range (strtod): start_index > str.size()");
56 const char *const bufptr = str.c_str();
59 const double result = g_ascii_strtod(bufptr + start_index, &endptr);
60 const int err_no = errno;
64 g_return_val_if_fail(err_no == ERANGE, result);
67 throw std::overflow_error("overflow (strtod): positive number too large");
70 throw std::overflow_error("overflow (strtod): negative number too large");
72 throw std::underflow_error("underflow (strtod): number too small");
76 end_index = endptr - bufptr;
78 end_index = str.size();
83 std::string Glib::Ascii::dtostr(double d)
85 char buf[G_ASCII_DTOSTR_BUF_SIZE];
87 return g_ascii_dtostr(buf, sizeof(buf), d);
90 std::string Glib::strescape(const std::string& source)
92 const Glib::ScopedPtr<char> buf (g_strescape(source.c_str(), 0));
96 std::string Glib::strescape(const std::string& source, const std::string& exceptions)
98 const Glib::ScopedPtr<char> buf (g_strescape(source.c_str(), exceptions.c_str()));
102 std::string Glib::strcompress(const std::string& source)
104 const Glib::ScopedPtr<char> buf (g_strcompress(source.c_str()));
108 Glib::ustring Glib::strerror(int errnum)
110 return g_strerror(errnum);
113 Glib::ustring Glib::strsignal(int signum)
115 return g_strsignal(signum);