[beast: 5/12] SFI: add g_sname_equals to compare strings while ignoring '-' vs '_' differences



commit 270ff8e432a6196f2a7eef1f8e6f2e47eaaaf920
Author: Tim Janik <timj gnu org>
Date:   Tue Sep 22 19:31:09 2015 +0200

    SFI: add g_sname_equals to compare strings while ignoring '-' vs '_' differences

 sfi/glib-extra.cc |   14 ++++++++++++++
 sfi/glib-extra.hh |    1 +
 2 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/sfi/glib-extra.cc b/sfi/glib-extra.cc
index 48d596e..bc252e8 100644
--- a/sfi/glib-extra.cc
+++ b/sfi/glib-extra.cc
@@ -767,6 +767,20 @@ g_type_name_to_type_macro (const gchar *type_name)
   return type_name_to_cname (type_name, "_TYPE", '_', TRUE);
 }
 
+/// Check if @a s1 is equal to @a s2, while ignoring separator differences like '-' vs '_'.
+bool
+g_sname_equals (const std::string &s1, const std::string &s2)
+{
+  if (s1.size() != s2.size())
+    return false;
+  for (size_t i = 0; i < s1.size(); i++)
+    if (s1.data()[i] != s2.data()[i] &&
+        (s1.data()[i] == '_' ? '-' : s1.data()[i]) !=
+        (s2.data()[i] == '_' ? '-' : s2.data()[i]))
+      return false;
+  return true;
+}
+
 
 /* --- simple main loop source --- */
 typedef struct {
diff --git a/sfi/glib-extra.hh b/sfi/glib-extra.hh
index d29b62b..0262795 100644
--- a/sfi/glib-extra.hh
+++ b/sfi/glib-extra.hh
@@ -129,6 +129,7 @@ gchar*  g_type_name_to_cname            (const gchar    *type_name);
 gchar*  g_type_name_to_sname            (const gchar    *type_name);
 gchar*  g_type_name_to_cupper           (const gchar    *type_name);
 gchar*  g_type_name_to_type_macro       (const gchar    *type_name);
+bool    g_sname_equals                  (const std::string &s1, const std::string &s2);
 
 
 /* --- simple main loop source --- */


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