Rapicorn - Experimental UI Toolkit - Source Code 10.08.1
strings.hh
Go to the documentation of this file.
00001 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
00002 #ifndef __RAPICORN_STRINGS_HH__
00003 #define __RAPICORN_STRINGS_HH__
00004 
00005 #include <rcore/utilities.hh>
00006 #include <string>
00007 
00008 namespace Rapicorn {
00009 
00010 // == i18n ==
00011 const char*                     rapicorn_gettext        (const char *text) RAPICORN_FORMAT (1);
00012 #ifdef __RAPICORN_BUILD__
00013 #define _(str)  rapicorn_gettext (str)
00014 #define N_(str) (str)
00015 #endif
00016 
00017 // == String ==
00018 String                          string_multiply          (const String &s,
00019                                                           uint64       count);
00020 String                          string_tolower           (const String &str);
00021 String                          string_toupper           (const String &str);
00022 String                          string_totitle           (const String &str);
00023 String                          string_printf            (const char *format, ...) RAPICORN_PRINTF (1, 2);
00024 String                          string_vprintf           (const char *format, va_list vargs);
00025 StringVector                    string_split             (const String       &string,
00026                                                           const String       &splitter = "");
00027 String                          string_join              (const String       &junctor,
00028                                                           const StringVector &strvec);
00029 bool                            string_to_bool           (const String &string);
00030 String                          string_from_bool         (bool value);
00031 uint64                          string_to_uint           (const String &string, uint base = 10);
00032 String                          string_from_uint         (uint64 value);
00033 bool                            string_has_int           (const String &string);
00034 int64                           string_to_int            (const String &string, uint base = 10);
00035 String                          string_from_int          (int64 value);
00036 String                          string_from_float        (float value);
00037 double                          string_to_double         (const String &string);
00038 double                          string_to_double         (const char  *dblstring,
00039                                                           const char **endptr);
00040 String                          string_from_double       (double value);
00041 inline String                   string_from_float        (double value)         { return string_from_double (value); }
00042 inline double                   string_to_float          (const String &string) { return string_to_double (string); }
00043 template<typename Type> Type    string_to_type           (const String &string);
00044 template<typename Type> String  string_from_type         (Type          value);
00045 template<> inline double        string_to_type<double>   (const String &string) { return string_to_double (string); }
00046 template<> inline String        string_from_type<double> (double         value) { return string_from_double (value); }
00047 template<> inline float         string_to_type<float>    (const String &string) { return string_to_float (string); }
00048 template<> inline String        string_from_type<float>  (float         value)  { return string_from_float (value); }
00049 template<> inline bool          string_to_type<bool>     (const String &string) { return string_to_bool (string); }
00050 template<> inline String        string_from_type<bool>   (bool         value)   { return string_from_bool (value); }
00051 template<> inline int16         string_to_type<int16>    (const String &string) { return string_to_int (string); }
00052 template<> inline String        string_from_type<int16>  (int16         value)  { return string_from_int (value); }
00053 template<> inline uint16        string_to_type<uint16>   (const String &string) { return string_to_uint (string); }
00054 template<> inline String        string_from_type<uint16> (uint16        value)  { return string_from_uint (value); }
00055 template<> inline int           string_to_type<int>      (const String &string) { return string_to_int (string); }
00056 template<> inline String        string_from_type<int>    (int         value)    { return string_from_int (value); }
00057 template<> inline uint          string_to_type<uint>     (const String &string) { return string_to_uint (string); }
00058 template<> inline String        string_from_type<uint>   (uint           value) { return string_from_uint (value); }
00059 template<> inline int64         string_to_type<int64>    (const String &string) { return string_to_int (string); }
00060 template<> inline String        string_from_type<int64>  (int64         value)  { return string_from_int (value); }
00061 template<> inline uint64        string_to_type<uint64>   (const String &string) { return string_to_uint (string); }
00062 template<> inline String        string_from_type<uint64> (uint64         value) { return string_from_uint (value); }
00063 template<> inline String        string_to_type<String>   (const String &string) { return string; }
00064 template<> inline String        string_from_type<String> (String         value) { return value; }
00065 vector<double>                  string_to_vector         (const String         &string);
00066 String                          string_from_vector       (const vector<double> &dvec,
00067                                                           const String         &delim = " ");
00068 String                          string_from_errno        (int         errno_val);
00069 bool                            string_is_uuid           (const String &uuid_string); /* check uuid formatting */
00070 int                             string_cmp_uuid          (const String &uuid_string1,
00071                                                           const String &uuid_string2); /* -1=smaller, 0=equal, +1=greater (assuming valid uuid strings) */
00072 String  string_from_pretty_function_name                 (const char *gnuc_pretty_function);
00073 String  string_to_cescape                                (const String &str);
00074 String  string_to_cquote                                 (const String &str);
00075 String  string_from_cquote                               (const String &input);
00076 String  string_lstrip                                    (const String &input);
00077 String  string_rstrip                                    (const String &input);
00078 String  string_strip                                     (const String &input);
00079 String  string_substitute_char                           (const String &input,
00080                                                           const char    match,
00081                                                           const char    subst);
00082 void    memset4            (uint32              *mem,
00083                             uint32               filler,
00084                             uint                 length);
00085 String  string_vector_find (const StringVector  &svector,
00086                             const String        &key,
00087                             const String        &fallback);
00088 StringVector cstrings_to_vector (const char*, ...) RAPICORN_SENTINEL;
00089 
00090 // == String Options ==
00091 bool    string_option_check     (const String   &option_string,
00092                                  const String   &option);
00093 String  string_option_get       (const String   &option_string,
00094                                  const String   &option);
00095 
00096 // == Strings ==
00097 class Strings : public std::vector<std::string> 
00098 {
00099   typedef const std::string CS;
00100 public:
00101   explicit Strings (CS &s1);
00102   explicit Strings (CS &s1, CS &s2);
00103   explicit Strings (CS &s1, CS &s2, CS &s3);
00104   explicit Strings (CS &s1, CS &s2, CS &s3, CS &s4);
00105   explicit Strings (CS &s1, CS &s2, CS &s3, CS &s4, CS &s5);
00106   explicit Strings (CS &s1, CS &s2, CS &s3, CS &s4, CS &s5, CS &s6);
00107   explicit Strings (CS &s1, CS &s2, CS &s3, CS &s4, CS &s5, CS &s6, CS &s7);
00108   explicit Strings (CS &s1, CS &s2, CS &s3, CS &s4, CS &s5, CS &s6, CS &s7, CS &s8);
00109   explicit Strings (CS &s1, CS &s2, CS &s3, CS &s4, CS &s5, CS &s6, CS &s7, CS &s8, CS &s9);
00110   explicit Strings (CS &s1, CS &s2, CS &s3, CS &s4, CS &s5, CS &s6, CS &s7, CS &s8, CS &s9, CS &sA);
00111   explicit Strings (CS &s1, CS &s2, CS &s3, CS &s4, CS &s5, CS &s6, CS &s7, CS &s8, CS &s9, CS &sA, CS &sB);
00112   explicit Strings (CS &s1, CS &s2, CS &s3, CS &s4, CS &s5, CS &s6, CS &s7, CS &s8, CS &s9, CS &sA, CS &sB, CS &sC);
00113 };
00114 
00115 // == Charset Conversions ==
00116 bool    text_convert    (const String &to_charset,
00117                          String       &output_string,
00118                          const String &from_charset,
00119                          const String &input_string,
00120                          const String &fallback_charset = "ISO-8859-15",
00121                          const String &output_mark = "");
00122 
00123 // == StringVector ==
00124 #define RAPICORN_STRING_VECTOR_FROM_ARRAY(ConstCharArray)               ({ \
00125   Rapicorn::StringVector __a;                                           \
00126   const Rapicorn::uint64 __l = RAPICORN_ARRAY_SIZE (ConstCharArray);    \
00127   for (Rapicorn::uint64 __ai = 0; __ai < __l; __ai++)                   \
00128     __a.push_back (ConstCharArray[__ai]);                               \
00129   __a; })
00130 
00131 } // Rapicorn
00132 
00133 #endif /* __RAPICORN_STRINGS_HH__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines