[beast: 9/12] BEAST: introduce bst_path_leaf_index() to find the last path string segment



commit 6b1ea229b3a43ba305f8c4556ac7667cae2ef8a5
Author: Tim Janik <timj gnu org>
Date:   Sun Sep 20 21:12:15 2015 +0200

    BEAST: introduce bst_path_leaf_index() to find the last path string segment

 beast-gtk/bstbseutils.cc    |   11 ++++++++++-
 beast-gtk/bstbseutils.hh    |    2 ++
 beast-gtk/bstusermessage.cc |    2 +-
 3 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/beast-gtk/bstbseutils.cc b/beast-gtk/bstbseutils.cc
index 899286e..5837a63 100644
--- a/beast-gtk/bstbseutils.cc
+++ b/beast-gtk/bstbseutils.cc
@@ -59,11 +59,20 @@ bst_procedure_get_title (const gchar *procedure)
     {
       BseCategorySeq *cseq = bse_categories_match_typed ("*", procedure);
       if (cseq->n_cats)
-        return cseq->cats[0]->category + cseq->cats[0]->lindex + 1;
+        return cseq->cats[0]->category + bst_path_leaf_index (cseq->cats[0]->category);
     }
   return NULL;
 }
 
+/// Return the character index of the last string segment not containing @a separator.
+uint
+bst_path_leaf_index (const String &path, char separator)
+{
+  const char *data = path.data();
+  const char *d = strrchr (data, separator);
+  return d && d >= data && d < data + path.size() ? d - data + 1 : 0;
+}
+
 namespace Bse {
 
 const char*
diff --git a/beast-gtk/bstbseutils.hh b/beast-gtk/bstbseutils.hh
index c1a9b0d..96a2f41 100644
--- a/beast-gtk/bstbseutils.hh
+++ b/beast-gtk/bstbseutils.hh
@@ -39,6 +39,8 @@ Bse::ErrorType    bst_project_restore_from_file   (Bse::ProjectH   project,
 Bse::ErrorType    bst_project_import_midi_file    (Bse::ProjectH   project,
                                                  const gchar    *file_name);
 const gchar*    bst_procedure_get_title         (const gchar    *procedure);
+uint            bst_path_leaf_index             (const String &path, char separator = '/');
+
 
 G_END_DECLS
 
diff --git a/beast-gtk/bstusermessage.cc b/beast-gtk/bstusermessage.cc
index b9dead8..2fb546c 100644
--- a/beast-gtk/bstusermessage.cc
+++ b/beast-gtk/bstusermessage.cc
@@ -483,7 +483,7 @@ message_fill_from_script (BstMessage    *msg,
     {
       BseCategorySeq *cseq = bse_categories_match_typed ("*", proc_name);
       if (cseq->n_cats)
-        proc_title = cseq->cats[0]->category + cseq->cats[0]->lindex + 1;
+        proc_title = cseq->cats[0]->category + bst_path_leaf_index (cseq->cats[0]->category);
     }
   msg->title = g_strdup (proc_title);
   msg->primary = g_strdup (primary ? primary : proc_title);


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