Nemiver  0.3
nmv-str-utils.h
Go to the documentation of this file.
1 // Author: Dodji Seketeli
2 /*
3  *This file is part of the Nemiver project
4  *
5  *Nemiver is free software; you can redistribute
6  *it and/or modify it under the terms of
7  *the GNU General Public License as published by the
8  *Free Software Foundation; either version 2,
9  *or (at your option) any later version.
10  *
11  *Nemiver is distributed in the hope that it will
12  *be useful, but WITHOUT ANY WARRANTY;
13  *without even the implied warranty of
14  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *See the GNU General Public License for more details.
16  *
17  *You should have received a copy of the
18  *GNU General Public License along with Nemiver;
19  *see the file COPYING.
20  *If not, write to the Free Software Foundation,
21  *Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  *See COPYRIGHT file copyright information.
24  */
25 #ifndef __NMV_STR_UTILS_H__
26 #define __NMV_STR_UTILS_H__
27 #include "nmv-ustring.h"
28 
29 NEMIVER_BEGIN_NAMESPACE (nemiver)
30 NEMIVER_BEGIN_NAMESPACE (str_utils)
31 
32 using nemiver::common::UString;
33 
34 bool extract_path_and_line_num_from_location (const std::string &a_location,
35  std::string &a_file_path,
36  std::string &a_line_num);
37 
38 bool parse_host_and_port (const std::string &a,
39  std::string &a_host,
40  unsigned &a_port);
41 
42 size_t hexa_to_int (const string &a_hexa_str);
43 std::string int_to_string (size_t an_int);
44 bool string_is_number (const string&);
45 bool string_is_decimal_number (const string&);
46 bool string_is_hexa_number (const string &a_str);
47 vector<UString> split (const UString &a_string, const UString &a_delim);
48 vector<UString> split_set (const UString &a_string, const UString &a_delim_set);
49 UString join (const vector<UString> &a_elements,
50  const UString &a_delim=" ");
51 UString join (vector<UString>::const_iterator &a_from,
52  vector<UString>::const_iterator &a_to,
53  const UString &a_delim=" ");
54 
55 template<typename S>
56 void
57 chomp (S &a_string)
58 {
59  if (!a_string.size ()) {return;}
60 
61  Glib::ustring::size_type i = 0;
62 
63  // remove the ws from the beginning of the string.
64  while (!a_string.empty () && isspace (a_string.at (0))) {
65  a_string.erase (0, 1);
66  }
67 
68  // remove the ws from the end of the string.
69  i = a_string.size ();
70  if (!i) {return;}
71  --i;
72  while (i > 0 && isspace (a_string.at (i))) {
73  a_string.erase (i, 1);
74  i = a_string.size ();
75  if (!i) {return;}
76  --i;
77  }
78  if (i == 0 && isspace (a_string.at (i))) {a_string.erase (0, 1);}
79 }
80 
81 UString::size_type get_number_of_lines (const UString &a_string);
82 
83 UString::size_type get_number_of_words (const UString &a_string);
84 
85 UString printf (const UString &a_format, ...);
86 
87 UString vprintf (const UString &a_format, va_list a_args);
88 
89 bool is_buffer_valid_utf8 (const char *a_buffer, unsigned a_len);
90 
91 bool ensure_buffer_is_in_utf8 (const std::string &a_input,
92  const std::list<std::string> &supported_encodings,
93  UString &a_output);
94 
95 
96 NEMIVER_END_NAMESPACE (str_utils)
97 NEMIVER_END_NAMESPACE (nemiver)
98 
99 #endif // __NMV_STR_UTILS_H__
nemiver::str_utils::get_number_of_words
UString::size_type get_number_of_words(const UString &a_string)
nemiver
Definition: nmv-address.h:31
nemiver::str_utils::join
UString join(vector< UString >::const_iterator &a_from, vector< UString >::const_iterator &a_to, const UString &a_delim=" ")
nmv-ustring.h
nemiver::str_utils::split
vector< UString > split(const UString &a_string, const UString &a_delim)
nemiver::str_utils::is_buffer_valid_utf8
bool is_buffer_valid_utf8(const char *a_buffer, unsigned a_len)
nemiver::common::UString
Definition: nmv-ustring.h:45
nemiver::str_utils::chomp
void chomp(S &a_string)
Definition: nmv-str-utils.h:57
nemiver::str_utils::string_is_decimal_number
bool string_is_decimal_number(const string &)
nemiver::str_utils::string_is_number
bool string_is_number(const string &)
nemiver::str_utils::hexa_to_int
size_t hexa_to_int(const string &a_hexa_str)
nemiver::str_utils::vprintf
UString vprintf(const UString &a_format, va_list a_args)
nemiver::str_utils::ensure_buffer_is_in_utf8
bool ensure_buffer_is_in_utf8(const std::string &a_input, const std::list< std::string > &supported_encodings, UString &a_output)
nemiver::str_utils::int_to_string
std::string int_to_string(size_t an_int)
nemiver::str_utils::printf
UString printf(const UString &a_format,...)
nemiver::str_utils::parse_host_and_port
bool parse_host_and_port(const std::string &a, std::string &a_host, unsigned &a_port)
nemiver::str_utils::get_number_of_lines
UString::size_type get_number_of_lines(const UString &a_string)
nemiver::str_utils::extract_path_and_line_num_from_location
bool extract_path_and_line_num_from_location(const std::string &a_location, std::string &a_file_path, std::string &a_line_num)
nemiver::str_utils::string_is_hexa_number
bool string_is_hexa_number(const string &a_str)
nemiver::str_utils::split_set
vector< UString > split_set(const UString &a_string, const UString &a_delim_set)
common
Definition: nmv-proc-list-dialog.h:32