[beast: 21/24] BSE: use Rapicorn's string_format()



commit 53c72df269093bee7f1edbf3ef33ba5a8dba41ef
Author: Tim Janik <timj gnu org>
Date:   Wed Sep 23 20:56:52 2015 +0200

    BSE: use Rapicorn's string_format()

 bse/bsecontainer.cc    |   18 ++++++------------
 bse/bsemidinotifier.cc |    7 +------
 bse/bseutils.cc        |    4 +---
 3 files changed, 8 insertions(+), 21 deletions(-)
---
diff --git a/bse/bsecontainer.cc b/bse/bsecontainer.cc
index e19201d..d0e5812 100644
--- a/bse/bsecontainer.cc
+++ b/bse/bsecontainer.cc
@@ -232,11 +232,8 @@ bse_container_add_item (BseContainer *container,
    */
   if (!uname || bse_container_lookup_item (container, uname))
     {
-      gchar *buffer, *p;
-      guint i = 0, l;
-
       if (!uname)
-        uname = (char*) g_object_get_data (G_OBJECT (container), "BseContainer-base-name");
+        uname = (const char*) g_object_get_data (G_OBJECT (container), "BseContainer-base-name");
       if (!uname)
         {
           uname = BSE_OBJECT_TYPE_NAME (item);
@@ -246,16 +243,13 @@ bse_container_add_item (BseContainer *container,
             uname += 3;                 /* strip Bse namespace for convenient naming */
         }
 
-      l = strlen (uname);
-      buffer = g_new (gchar, l + 12);
-      strcpy (buffer, uname);
-      p = buffer + l;
+      String next_name;
+      uint i = 0;
       do
-        g_snprintf (p, 11, "-%u", ++i);
-      while (bse_container_lookup_item (container, buffer));
+        next_name = string_format ("%s-%u", uname, ++i);
+      while (bse_container_lookup_item (container, next_name.c_str()));
 
-      g_object_set (item, "uname", buffer, NULL); /* no undo */
-      g_free (buffer);
+      g_object_set (item, "uname", next_name.c_str(), NULL); /* no undo */
     }
   g_object_set_data (G_OBJECT (container), "BseContainer-base-name", NULL);
 
diff --git a/bse/bsemidinotifier.cc b/bse/bsemidinotifier.cc
index b17efdd..797ea5b 100644
--- a/bse/bsemidinotifier.cc
+++ b/bse/bsemidinotifier.cc
@@ -52,12 +52,7 @@ bse_midi_notifier_class_init (BseMidiNotifierClass *klass)
   gobject_class->finalize = bse_midi_notifier_finalize;
 
   for (i = 0; i < BSE_MIDI_MAX_CHANNELS; i++)
-    {
-      gchar buffer[32];
-
-      g_snprintf (buffer, 32, "%u", i);
-      number_quarks[i] = g_quark_from_string (buffer);
-    }
+    number_quarks[i] = g_quark_from_string (string_format ("%u", i).c_str());
 
   signal_midi_event = bse_object_class_add_dsignal (object_class, "midi-event",
                                                    G_TYPE_NONE, 1,
diff --git a/bse/bseutils.cc b/bse/bseutils.cc
index 52e5f58..9696a94 100644
--- a/bse/bseutils.cc
+++ b/bse/bseutils.cc
@@ -501,9 +501,7 @@ bse_xinfos_add_num (gchar          **xinfos,
                     const gchar     *key,
                     SfiNum           num)
 {
-  gchar buffer[128];
-  g_snprintf (buffer, sizeof (buffer), "%lld", num);
-  return bse_xinfos_add_value (xinfos, key, buffer);
+  return bse_xinfos_add_value (xinfos, key, string_format ("%d", num).c_str());
 }
 
 const gchar*


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