20130420
[gdash.git] / src / misc / util.hpp
blobc39bc346b7774f9a09abcc0f6adf53164ec79f77
1 /*
2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
19 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef UTIL_HPP_INCLUDED
24 #define UTIL_HPP_INCLUDED
26 #include "config.h"
28 #include <string>
29 #include <vector>
31 /// find file, looking in user directory and install directory
32 /// @return full path of file if found, "" if not
33 std::string gd_find_data_file(const std::string &filename, const std::vector<std::string>& dirs);
35 /// create a string form a char*, and free it with g_free
36 std::string gd_tostring_free(char *str);
38 /// @brief Wrap a text to lines of specified maximum width.
39 /// Honors original newlines as well.
40 /// @param input The UTF-8 text to wrap. May contain UTF-8 characters, and GD_COLOR_SETCOLOR characters.
41 /// @param width The maximum length of lines.
42 /// @return The vector of lines.
43 std::vector<std::string> gd_wrap_text(const char *input, int width);
45 /// @brief Returns current date in 2008-12-04 format.
46 std::string gd_get_current_date();
48 /// @brief Returns current date in 2008-12-04 12:34 format.
49 std::string gd_get_current_date_time();
51 /// clamp integer into range
52 int gd_clamp(int val, int min, int max);
54 /// remove leading and trailing spaces from s
55 void gd_strchomp(std::string &s);
57 /// compare two strings, ignoring case for ascii characters
58 int gd_str_ascii_casecmp(const std::string &s1, const std::string &s2);
60 bool gd_str_ascii_caseequal(const std::string &s1, const std::string &s2);
62 bool gd_str_equal(const char *a, const char *b);
64 bool gd_str_ascii_prefix(const std::string &str, const std::string &prefix);
66 #endif