[beast/devel: 16/77] BIRNET: remove utf8 and string functions which Rapicorn provides



commit 842ce640b6c7b9099a55adbc15da601baba8dccf
Author: Tim Janik <timj gnu org>
Date:   Fri Mar 29 00:41:16 2013 +0000

    BIRNET: remove utf8 and string functions which Rapicorn provides

 birnet/Makefile.am    |    2 -
 birnet/birnet.hh      |    1 -
 birnet/birnetutf8.cc  |  277 -------------------------------------------------
 birnet/birnetutf8.hh  |  175 -------------------------------
 birnet/birnetutils.cc |  240 +------------------------------------------
 birnet/birnetutils.hh |   56 ++--------
 6 files changed, 11 insertions(+), 740 deletions(-)
---
diff --git a/birnet/Makefile.am b/birnet/Makefile.am
index 94e0cf7..d90f2cd 100644
--- a/birnet/Makefile.am
+++ b/birnet/Makefile.am
@@ -14,14 +14,12 @@ birnet_headers = $(strip            \
        birnetmsg.hh                    \
        birnettests.h                   \
        birnetmath.hh                   \
-       birnetutf8.hh                   \
        birnetutils.hh                  \
 )
 birnet_sources = $(strip               \
        birnetdebugtools.cc             \
        birnetmsg.cc                    \
        birnetmath.cc                   \
-       birnetutf8.cc                   \
        birnetutils.cc                  \
 )
 birnet_private_headers = $(strip       \
diff --git a/birnet/birnet.hh b/birnet/birnet.hh
index 9f6a095..6287e10 100644
--- a/birnet/birnet.hh
+++ b/birnet/birnet.hh
@@ -5,7 +5,6 @@
 #include <birnet/birnetdebugtools.hh>
 #include <birnet/birnetmsg.hh>
 #include <birnet/birnetmath.hh>
-#include <birnet/birnetutf8.hh>
 #include <birnet/birnetutils.hh>
 
 // We're migrating to Bse for everything and use Rapicorn core for the lower level stuff
diff --git a/birnet/birnetutils.cc b/birnet/birnetutils.cc
index 4dc92ec..cbf8ca1 100644
--- a/birnet/birnetutils.cc
+++ b/birnet/birnetutils.cc
@@ -1,7 +1,6 @@
 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
 #include <glib.h>
 #include "birnetutils.hh"
-#include "birnetutf8.hh"
 #include "birnetmsg.hh"
 #include <unistd.h>
 #include <errno.h>
@@ -345,244 +344,7 @@ VirtualTypeid::cxx_demangle (const char *mangled_identifier)
     free (malloced_result);
   return result;
 }
-/* --- string utils --- */
-String
-string_tolower (const String &str)
-{
-  String s (str);
-  for (uint i = 0; i < s.size(); i++)
-    s[i] = Unichar::tolower (s[i]);
-  return s;
-}
-String
-string_toupper (const String &str)
-{
-  String s (str);
-  for (uint i = 0; i < s.size(); i++)
-    s[i] = Unichar::toupper (s[i]);
-  return s;
-}
-String
-string_totitle (const String &str)
-{
-  String s (str);
-  for (uint i = 0; i < s.size(); i++)
-    s[i] = Unichar::totitle (s[i]);
-  return s;
-}
-String
-string_printf (const char *format,
-               ...)
-{
-  String str;
-  va_list args;
-  va_start (args, format);
-  str = string_vprintf (format, args);
-  va_end (args);
-  return str;
-}
-String
-string_vprintf (const char *format,
-                va_list     vargs)
-{
-  char *str = NULL;
-  if (vasprintf (&str, format, vargs) >= 0 && str)
-    {
-      String s = str;
-      free (str);
-      return s;
-    }
-  else
-    return format;
-}
-String
-string_strip (const String &str)
-{
-  const char *cstr = str.c_str();
-  uint start = 0, end = str.size();
-  while (end and strchr (" \t\n\r", cstr[end-1]))
-    end--;
-  while (strchr (" \t\n\r", cstr[start]))
-    start++;
-  return String (cstr + start, end - start);
-}
-bool
-string_to_bool (const String &string)
-{
-  static const char *spaces = " \t\n\r";
-  const char *p = string.c_str();
-  /* skip spaces */
-  while (*p && strchr (spaces, *p))
-    p++;
-  /* ignore signs */
-  if (p[0] == '-' || p[0] == '+')
-    {
-      p++;
-      /* skip spaces */
-      while (*p && strchr (spaces, *p))
-        p++;
-    }
-  /* handle numbers */
-  if (p[0] >= '0' && p[0] <= '9')
-    return 0 != string_to_uint (p);
-  /* handle special words */
-  if (strncasecmp (p, "ON", 2) == 0)
-    return 1;
-  if (strncasecmp (p, "OFF", 3) == 0)
-    return 0;
-  /* handle non-numbers */
-  return !(p[0] == 0 ||
-           p[0] == 'f' || p[0] == 'F' ||
-           p[0] == 'n' || p[0] == 'N');
-}
-String
-string_from_bool (bool value)
-{
-  return String (value ? "1" : "0");
-}
-uint64
-string_to_uint (const String &string,
-                uint          base)
-{
-  const char *p = string.c_str();
-  while (*p == ' ' || *p == '\n' || *p == '\t' || *p == '\r')
-    p++;
-  bool hex = p[0] == '0' && (p[1] == 'X' || p[1] == 'x');
-  return strtoull (hex ? p + 2 : p, NULL, hex ? 16 : base);
-}
-String
-string_from_uint (uint64 value)
-{
-  return string_printf ("%llu", value);
-}
-bool
-string_has_int (const String &string)
-{
-  const char *p = string.c_str();
-  while (*p == ' ' || *p == '\n' || *p == '\t' || *p == '\r')
-    p++;
-  return p[0] >= '0' && p[0] <= '9';
-}
-int64
-string_to_int (const String &string,
-               uint          base)
-{
-  const char *p = string.c_str();
-  while (*p == ' ' || *p == '\n' || *p == '\t' || *p == '\r')
-    p++;
-  bool hex = p[0] == '0' && (p[1] == 'X' || p[1] == 'x');
-  return strtoll (hex ? p + 2 : p, NULL, hex ? 16 : base);
-}
-String
-string_from_int (int64 value)
-{
-  return string_printf ("%lld", value);
-}
-double
-string_to_double (const String &string)
-{
-  return g_ascii_strtod (string.c_str(), NULL);
-}
-String
-string_from_float (float value)
-{
-  char numbuf[G_ASCII_DTOSTR_BUF_SIZE + 1] = { 0, };
-  g_ascii_formatd (numbuf, G_ASCII_DTOSTR_BUF_SIZE, "%.7g", value);
-  return String (numbuf);
-}
-String
-string_from_double (double value)
-{
-  char numbuf[G_ASCII_DTOSTR_BUF_SIZE + 1] = { 0, };
-  g_ascii_formatd (numbuf, G_ASCII_DTOSTR_BUF_SIZE, "%.17g", value);
-  return String (numbuf);
-}
-vector<double>
-string_to_vector (const String &string)
-{
-  vector<double> dvec;
-  const char *spaces = " \t\n";
-  const char *obrace = "{([";
-  const char *delims = ";";
-  const char *cbrace = "])}";
-  const char *number = "+-0123456789eE.,";
-  const char *s = string.c_str();
-  /* skip spaces */
-  while (*s && strchr (spaces, *s))
-    s++;
-  /* skip opening brace */
-  if (*s && strchr (obrace, *s))
-    s++;
-  const char *d = s;
-  while (*d && !strchr (cbrace, *d))
-    {
-      while (*d && strchr (spaces, *d))         /* skip spaces */
-        d++;
-      s = d;                                    /* start of number */
-      if (!*d || (!strchr (number, *d) &&       /* ... if any */
-                  !strchr (delims, *d)))
-        break;
-      while (*d && strchr (number, *d))         /* pass across number */
-        d++;
-      dvec.push_back (string_to_double (String (s, d - s)));
-      while (*d && strchr (spaces, *d))         /* skip spaces */
-        d++;
-      if (*d && strchr (delims, *d))
-        d++;                                    /* eat delimiter */
-    }
-  // printf ("vector: %d: %s\n", dvec.size(), string_from_vector (dvec).c_str());
-  return dvec;
-}
-String
-string_from_vector (const vector<double> &dvec,
-                    const String         &delim)
-{
-  String s;
-  for (uint i = 0; i < dvec.size(); i++)
-    {
-      if (i > 0)
-        s += delim;
-      s += string_from_double (dvec[i]);
-    }
-  return s;
-}
-String
-string_from_errno (int errno_val)
-{
-  char buffer[1024] = { 0, };
-  /* strerror_r() is broken on GNU systems, especially if _GNU_SOURCE is defined, so fall back to strerror() 
*/
-  if (strerror_r (errno_val, buffer, sizeof (buffer)) < 0 || !buffer[0])
-    return strerror (errno_val);
-  return buffer;
-}
-bool
-string_is_uuid (const String &uuid_string) /* check uuid formatting */
-{
-  int i, l = uuid_string.size();
-  if (l != 36)
-    return false;
-  // 00000000-0000-0000-0000-000000000000
-  for (i = 0; i < l; i++)
-    if (i == 8 || i == 13 || i == 18 || i == 23)
-      {
-        if (uuid_string[i] != '-')
-          return false;
-        continue;
-      }
-    else if ((uuid_string[i] >= '0' && uuid_string[i] <= '9') ||
-             (uuid_string[i] >= 'a' && uuid_string[i] <= 'f') ||
-             (uuid_string[i] >= 'A' && uuid_string[i] <= 'F'))
-      continue;
-    else
-      return false;
-  return true;
-}
-int
-string_cmp_uuid (const String &uuid_string1,
-                 const String &uuid_string2) /* -1=smaller, 0=equal, +1=greater (assuming valid uuid 
strings) */
-{
-  return strcasecmp (uuid_string1.c_str(), uuid_string2.c_str()); /* good enough for numeric equality and 
defines stable order */
-}
+
 /* --- file utils --- */
 /**
  * @namespace Birnet::Path
diff --git a/birnet/birnetutils.hh b/birnet/birnetutils.hh
index c4e39c8..8a3ffc3 100644
--- a/birnet/birnetutils.hh
+++ b/birnet/birnetutils.hh
@@ -8,7 +8,16 @@
 #include <vector>
 #include <map>
 #include <stdarg.h>
+
+// We're migrating to Bse for everything and use Rapicorn core for the lower level stuff
+#include <rapicorn-core.hh>
+namespace Bse {
+using namespace Rapicorn;
+} // Bse
+
 namespace Birnet {
+using namespace Rapicorn;
+
 /* --- short integer types --- */
 typedef BirnetUInt8   uint8;
 typedef BirnetUInt16  uint16;
@@ -91,52 +100,7 @@ void    raise_sigtrap           ();
 #else   /* !__i386__ && !__alpha__ */
 //extern inline void BREAKPOINT() { raise_sigtrap(); }
 #endif  /* __i386__ */
-/* --- string functionality --- */
-String                         string_tolower           (const String &str);
-String                         string_toupper           (const String &str);
-String                         string_totitle           (const String &str);
-String                         string_printf            (const char *format, ...) BIRNET_PRINTF (1, 2);
-String                         string_vprintf           (const char *format, va_list vargs);
-String                         string_strip             (const String &str);
-bool                           string_to_bool           (const String &string);
-String                         string_from_bool         (bool value);
-uint64                         string_to_uint           (const String &string, uint base = 10);
-String                         string_from_uint         (uint64 value);
-bool                           string_has_int           (const String &string);
-int64                          string_to_int            (const String &string, uint base = 10);
-String                         string_from_int          (int64 value);
-String                         string_from_float        (float value);
-double                         string_to_double         (const String &string);
-String                          string_from_double       (double value);
-inline String                   string_from_float        (double value)         { return string_from_double 
(value); }
-inline double                   string_to_float          (const String &string) { return string_to_double 
(string); }
-template<typename Type> Type    string_to_type           (const String &string);
-template<typename Type> String  string_from_type         (Type          value);
-template<> inline double        string_to_type<double>   (const String &string) { return string_to_double 
(string); }
-template<> inline String        string_from_type<double> (double         value) { return string_from_double 
(value); }
-template<> inline float         string_to_type<float>    (const String &string) { return string_to_float 
(string); }
-template<> inline String        string_from_type<float>  (float         value)  { return string_from_float 
(value); }
-template<> inline bool          string_to_type<bool>     (const String &string) { return string_to_bool 
(string); }
-template<> inline String        string_from_type<bool>   (bool         value)   { return string_from_bool 
(value); }
-template<> inline int16         string_to_type<int16>    (const String &string) { return string_to_int 
(string); }
-template<> inline String        string_from_type<int16>  (int16         value)  { return string_from_int 
(value); }
-template<> inline uint16        string_to_type<uint16>   (const String &string) { return string_to_uint 
(string); }
-template<> inline String        string_from_type<uint16> (uint16        value)  { return string_from_uint 
(value); }
-template<> inline int           string_to_type<int>      (const String &string) { return string_to_int 
(string); }
-template<> inline String        string_from_type<int>    (int         value)    { return string_from_int 
(value); }
-template<> inline uint          string_to_type<uint>     (const String &string) { return string_to_uint 
(string); }
-template<> inline String        string_from_type<uint>   (uint           value) { return string_from_uint 
(value); }
-template<> inline int64         string_to_type<int64>    (const String &string) { return string_to_int 
(string); }
-template<> inline String        string_from_type<int64>  (int64         value)  { return string_from_int 
(value); }
-template<> inline uint64        string_to_type<uint64>   (const String &string) { return string_to_uint 
(string); }
-template<> inline String        string_from_type<uint64> (uint64         value) { return string_from_uint 
(value); }
-vector<double>                  string_to_vector         (const String         &string);
-String                          string_from_vector       (const vector<double> &dvec,
-                                                          const String         &delim = " ");
-String                         string_from_errno        (int         errno_val);
-bool                            string_is_uuid           (const String &uuid_string); /* check uuid 
formatting */
-int                             string_cmp_uuid          (const String &uuid_string1,
-                                                          const String &uuid_string2); /* -1=smaller, 
0=equal, +1=greater (assuming valid uuid strings) */
+
 /* --- file/path functionality --- */
 namespace Path {
 const String    dirname   (const String &path);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]