[gnome-builder/gnome-builder-3-32] io: add ide-path helpers to check for C/C++ suffixes



commit 7e2079eb94ac85e2bd3cf05e1d4deb3d5c61eba8
Author: Christian Hergert <chergert redhat com>
Date:   Thu Apr 18 13:08:02 2019 -0700

    io: add ide-path helpers to check for C/C++ suffixes
    
    This can be used in various places to determine the file type based on
    the suffix alone. Generally, we want to use content-type, but you just
    can't do that in some places, due to empty files or other I/O sensitive
    code paths.

 src/libide/io/ide-path.c | 38 ++++++++++++++++++++++++++++++++++++++
 src/libide/io/ide-path.h |  8 ++++++--
 2 files changed, 44 insertions(+), 2 deletions(-)
---
diff --git a/src/libide/io/ide-path.c b/src/libide/io/ide-path.c
index 51bd84211..89377f383 100644
--- a/src/libide/io/ide-path.c
+++ b/src/libide/io/ide-path.c
@@ -95,3 +95,41 @@ ide_path_collapse (const gchar *path)
 
   return g_steal_pointer (&expanded);
 }
+
+gboolean
+ide_path_is_c_like (const gchar *path)
+{
+  const gchar *dot;
+
+  if (path == NULL)
+    return FALSE;
+
+  if ((dot = strrchr (path, '.')))
+    return ide_str_equal (dot, ".c") || ide_str_equal (dot, ".h");
+
+  return FALSE;
+}
+
+gboolean
+ide_path_is_cpp_like (const gchar *path)
+{
+  static const gchar *cpplike[] = {
+    ".cc", ".cpp", ".c++", ".cxx",
+    ".hh", ".hpp", ".h++", ".hxx",
+  };
+  const gchar *dot;
+
+  if (path == NULL)
+    return FALSE;
+
+  if ((dot = strrchr (path, '.')))
+    {
+      for (guint i = 0; i < G_N_ELEMENTS (cpplike); i++)
+        {
+          if (ide_str_equal (dot, cpplike[i]))
+            return TRUE;
+        }
+    }
+
+  return FALSE;
+}
diff --git a/src/libide/io/ide-path.h b/src/libide/io/ide-path.h
index 3144bc637..9d7bb9b73 100644
--- a/src/libide/io/ide-path.h
+++ b/src/libide/io/ide-path.h
@@ -29,8 +29,12 @@
 G_BEGIN_DECLS
 
 IDE_AVAILABLE_IN_3_32
-gchar *ide_path_collapse (const gchar *path);
+gchar    *ide_path_collapse    (const gchar *path);
 IDE_AVAILABLE_IN_3_32
-gchar *ide_path_expand   (const gchar *path);
+gchar    *ide_path_expand      (const gchar *path);
+
+/* Not available as public ABI Until 3.34 */
+gboolean  ide_path_is_c_like   (const gchar *path);
+gboolean  ide_path_is_cpp_like (const gchar *path);
 
 G_END_DECLS


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