Commit 4e9c1363 authored by Christian Hergert's avatar Christian Hergert
Browse files

util: use string utils from libdazzle

We don't need to maintain these in multiple places anymore.
parent a19e7d46
......@@ -184,7 +184,7 @@ ide_application_plugins_enabled_changed (IdeApplication *self,
gboolean enabled;
g_assert (IDE_IS_APPLICATION (self));
g_assert (ide_str_equal0 (key, "enabled"));
g_assert (dzl_str_equal0 (key, "enabled"));
g_assert (G_IS_SETTINGS (settings));
enabled = g_settings_get_boolean (settings, key);
......
......@@ -845,7 +845,7 @@ ide_application_show_projects_window (IdeApplication *self)
name = ide_workbench_get_visible_perspective_name (IDE_WORKBENCH (window));
if (ide_str_equal0 ("greeter", name))
if (dzl_str_equal0 ("greeter", name))
{
gtk_window_present (windows->data);
return;
......
......@@ -694,7 +694,7 @@ ide_buffer_do_modeline (IdeBuffer *self)
if (old_lang != NULL)
old_id = gtk_source_language_get_id (old_lang);
if (old_id == NULL || !ide_str_equal0 (old_id, new_id))
if (old_id == NULL || !dzl_str_equal0 (old_id, new_id))
_ide_file_set_content_type (ifile, content_type);
}
......
......@@ -375,7 +375,7 @@ ide_unsaved_files_restore_worker (GTask *task,
line[line_len] = '\0';
if (ide_str_empty0 (line))
if (dzl_str_empty0 (line))
continue;
file = g_file_new_for_uri (line);
......
......@@ -200,7 +200,7 @@ ide_buildconfig_configuration_provider_save_async (IdeConfigurationProvider *pro
key = ide_environment_variable_get_key (var);
value = ide_environment_variable_get_value (var);
if (!ide_str_empty0 (key))
if (!dzl_str_empty0 (key))
g_key_file_set_string (self->key_file, group_environ, key, value ?: "");
}
}
......
......@@ -545,7 +545,7 @@ ide_build_pipeline_log_observer (IdeBuildLogStream stream,
{
gssize len;
enterdir += IDE_LITERAL_LENGTH (ENTERING_DIRECTORY_BEGIN);
enterdir += DZL_LITERAL_LENGTH (ENTERING_DIRECTORY_BEGIN);
/* Translate to relative paths for out-of-tree builds */
if (g_str_has_prefix (enterdir, self->builddir))
......@@ -555,7 +555,7 @@ ide_build_pipeline_log_observer (IdeBuildLogStream stream,
enterdir++;
}
len = strlen (enterdir) - IDE_LITERAL_LENGTH (ENTERING_DIRECTORY_END);
len = strlen (enterdir) - DZL_LITERAL_LENGTH (ENTERING_DIRECTORY_END);
if (len > 0)
{
......@@ -2524,7 +2524,7 @@ ide_build_pipeline_get_message (IdeBuildPipeline *self)
{
const gchar *name = ide_build_stage_get_name (self->current_stage);
if (!ide_str_empty0 (name))
if (!dzl_str_empty0 (name))
return g_strdup (name);
}
......@@ -3037,7 +3037,7 @@ _ide_build_pipeline_set_message (IdeBuildPipeline *self,
message += strlen ("jhbuild:");
}
if (!ide_str_equal0 (message, self->message))
if (!dzl_str_equal0 (message, self->message))
{
g_free (self->message);
self->message = g_strdup (message);
......
......@@ -57,7 +57,7 @@ find_color_code (const gchar *txt,
{
const gchar *cursor = txt;
g_assert (!ide_str_empty0 (txt));
g_assert (!dzl_str_empty0 (txt));
g_assert (start_offset != NULL);
g_assert (end_offset != NULL);
......
......@@ -18,6 +18,7 @@
#define G_LOG_DOMAIN "ide-compile-commands"
#include <dazzle.h>
#include <json-glib/json-glib.h>
#include <string.h>
......@@ -506,12 +507,12 @@ ide_compile_commands_filter_c (IdeCompileCommands *self,
default:
if (g_str_has_prefix (param, "-std=") ||
ide_str_equal0 (param, "-pthread") ||
dzl_str_equal0 (param, "-pthread") ||
g_str_has_prefix (param, "-isystem"))
{
g_ptr_array_add (ar, g_strdup (param));
}
else if (next != NULL && ide_str_equal0 (param, "-include"))
else if (next != NULL && dzl_str_equal0 (param, "-include"))
{
g_ptr_array_add (ar, g_strdup (param));
g_ptr_array_add (ar, ide_compile_commands_resolve (self, info, next));
......@@ -652,7 +653,7 @@ ide_compile_commands_lookup (IdeCompileCommands *self,
* document we stored information about each of the Vala files in a special
* list for exactly this purpose.
*/
if (ide_str_equal0 (dot, ".vala") && self->vala_info != NULL)
if (dzl_str_equal0 (dot, ".vala") && self->vala_info != NULL)
{
for (guint i = 0; i < self->vala_info->len; i++)
{
......
......@@ -94,7 +94,7 @@ goto_line_activate (IdeEditorLayoutStackControls *self,
if (self->view == NULL)
return;
if (!ide_str_empty0 (text))
if (!dzl_str_empty0 (text))
{
value = g_ascii_strtoll (text, NULL, 10);
......@@ -153,7 +153,7 @@ goto_line_changed (IdeEditorLayoutStackControls *self,
gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (self->view->buffer), &begin, &end);
if (!ide_str_empty0 (text))
if (!dzl_str_empty0 (text))
{
gint64 value;
......
......@@ -267,7 +267,7 @@ ide_editor_properties_entry_changed (IdeEditorProperties *self,
text = gtk_entry_get_text (GTK_ENTRY (entry));
/* Clear any previous filter */
if (ide_str_empty0 (text))
if (dzl_str_empty0 (text))
{
gtk_tree_view_set_model (self->tree_view, GTK_TREE_MODEL (self->languages));
return;
......
......@@ -166,7 +166,7 @@ ide_greeter_project_row_add_tags (IdeGreeterProjectRow *self,
}
build_system_name = ide_project_info_get_build_system_name (project_info);
if (!ide_str_empty0 (build_system_name))
if (!dzl_str_empty0 (build_system_name))
{
GtkWidget *pill;
......
......@@ -842,7 +842,7 @@ ide_context_load_doap_worker (GTask *task,
filename = g_file_info_get_name (file_info);
if (!ide_str_empty0 (filename) && g_str_has_suffix (filename, ".doap"))
if (!dzl_str_empty0 (filename) && g_str_has_suffix (filename, ".doap"))
{
g_autoptr(GFile) file = NULL;
g_autoptr(IdeDoap) doap = NULL;
......
......@@ -23,26 +23,10 @@
G_BEGIN_DECLS
/* strlen() generally gets hoisted out automatically */
#define IDE_LITERAL_LENGTH(s) (strlen(s))
#if __GNUC__ >= 7
# define IDE_FALLTHROUGH __attribute__((fallthrough))
#else
# define IDE_FALLTHROUGH
#endif
static inline gboolean
ide_str_empty0 (const gchar *str)
{
return (str == NULL) || (str[0] == '\0');
}
static inline gboolean
ide_str_equal0 (gconstpointer a,
gconstpointer b)
{
return (g_strcmp0 ((const gchar *)a, (const gchar *)b) == 0);
}
G_END_DECLS
......@@ -18,6 +18,7 @@
#define G_LOG_DOMAIN "ide-keybindings"
#include <dazzle.h>
#include <glib/gi18n.h>
#include <libpeas/peas.h>
......@@ -202,7 +203,7 @@ ide_keybindings_set_mode (IdeKeybindings *self,
{
g_return_if_fail (IDE_IS_KEYBINDINGS (self));
if (!ide_str_equal0 (self->mode, mode))
if (!dzl_str_equal0 (self->mode, mode))
{
g_free (self->mode);
self->mode = g_strdup (mode);
......
......@@ -143,7 +143,7 @@ ide_layout_stack_actions_open_in_new_frame (GSimpleAction *action,
g_assert (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING));
filepath = g_variant_get_string (variant, NULL);
if (!ide_str_empty0 (filepath))
if (!dzl_str_empty0 (filepath))
{
IdeContext *context;
IdeBufferManager *buffer_manager;
......@@ -235,7 +235,7 @@ ide_layout_stack_actions_split_view (GSimpleAction *action,
}
filepath = g_variant_get_string (variant, NULL);
if (!ide_str_empty0 (filepath))
if (!dzl_str_empty0 (filepath))
{
IdeContext *context;
IdeBufferManager *buffer_manager;
......
......@@ -294,7 +294,7 @@ ide_extension_adapter__changed_disabled (IdeExtensionAdapter *self,
g_assert (IDE_IS_EXTENSION_ADAPTER (self));
g_assert (G_IS_SETTINGS (settings));
if (ide_str_equal0 (changed_key, "disabled"))
if (dzl_str_equal0 (changed_key, "disabled"))
ide_extension_adapter_queue_reload (self);
}
......@@ -463,7 +463,7 @@ ide_extension_adapter_set_key (IdeExtensionAdapter *self,
{
g_return_if_fail (IDE_IS_EXTENSION_ADAPTER (self));
if (!ide_str_equal0 (self->key, key))
if (!dzl_str_equal0 (self->key, key))
{
g_free (self->key);
self->key = g_strdup (key);
......@@ -486,7 +486,7 @@ ide_extension_adapter_set_value (IdeExtensionAdapter *self,
{
g_return_if_fail (IDE_IS_EXTENSION_ADAPTER (self));
if (!ide_str_equal0 (self->value, value))
if (!dzl_str_equal0 (self->value, value))
{
g_free (self->value);
self->value = g_strdup (value);
......
......@@ -18,6 +18,7 @@
#define G_LOG_DOMAIN "ide-extension-set-adapter"
#include <dazzle.h>
#include <glib/gi18n.h>
#include "ide-context.h"
......@@ -499,7 +500,7 @@ ide_extension_set_adapter_set_key (IdeExtensionSetAdapter *self,
{
g_return_if_fail (IDE_IS_EXTENSION_SET_ADAPTER (self));
if (!ide_str_equal0 (self->key, key))
if (!dzl_str_equal0 (self->key, key))
{
g_free (self->key);
self->key = g_strdup (key);
......@@ -522,7 +523,7 @@ ide_extension_set_adapter_set_value (IdeExtensionSetAdapter *self,
{
g_return_if_fail (IDE_IS_EXTENSION_SET_ADAPTER (self));
if (!ide_str_equal0 (self->value, value))
if (!dzl_str_equal0 (self->value, value))
{
g_free (self->value);
self->value = g_strdup (value);
......
......@@ -226,7 +226,7 @@ language_search_changed (GtkSearchEntry *search,
text = gtk_entry_get_text (GTK_ENTRY (search));
if (!ide_str_empty0 (text))
if (!dzl_str_empty0 (text))
{
g_autofree gchar *folded = g_utf8_casefold (text, -1);
......@@ -282,7 +282,7 @@ ide_preferences_builtin_register_languages (DzlPreferences *preferences)
const gchar *name;
const gchar *section;
if (ide_str_equal0 (language_ids [i], "def"))
if (dzl_str_equal0 (language_ids [i], "def"))
continue;
language = gtk_source_language_manager_get_language (manager, language_ids [i]);
......@@ -484,7 +484,7 @@ vcs_configs_foreach_cb (PeasExtensionSet *set,
g_value_unset (&value);
fullname = g_object_new (DZL_TYPE_PREFERENCES_ENTRY,
"text", ide_str_empty0 (author_name) ? "" : author_name,
"text", dzl_str_empty0 (author_name) ? "" : author_name,
"title", "Author",
"visible", TRUE,
NULL);
......@@ -496,7 +496,7 @@ vcs_configs_foreach_cb (PeasExtensionSet *set,
0);
email = g_object_new (DZL_TYPE_PREFERENCES_ENTRY,
"text", ide_str_empty0 (author_email) ? "" : author_email,
"text", dzl_str_empty0 (author_email) ? "" : author_email,
"title", "Email",
"visible", TRUE,
NULL);
......
......@@ -22,6 +22,7 @@
#define G_LOG_DOMAIN "ide-project-info"
#include <dazzle.h>
#include <glib/gi18n.h>
#include <string.h>
......@@ -208,7 +209,7 @@ ide_project_info_set_build_system_name (IdeProjectInfo *self,
{
g_return_if_fail (IDE_IS_PROJECT_INFO (self));
if (!ide_str_equal0 (self->build_system_name, build_system_name))
if (!dzl_str_equal0 (self->build_system_name, build_system_name))
{
g_free (self->build_system_name);
self->build_system_name = g_strdup (build_system_name);
......@@ -230,7 +231,7 @@ ide_project_info_set_description (IdeProjectInfo *self,
{
g_return_if_fail (IDE_IS_PROJECT_INFO (self));
if (!ide_str_equal0 (self->description, description))
if (!dzl_str_equal0 (self->description, description))
{
g_free (self->description);
self->description = g_strdup (description);
......@@ -252,7 +253,7 @@ ide_project_info_set_name (IdeProjectInfo *self,
{
g_return_if_fail (IDE_IS_PROJECT_INFO (self));
if (!ide_str_equal0 (self->name, name))
if (!dzl_str_equal0 (self->name, name))
{
g_free (self->name);
self->name = g_strdup (name);
......
......@@ -18,6 +18,7 @@
#define G_LOG_DOMAIN "ide-runner"
#include <dazzle.h>
#include <errno.h>
#include <glib/gi18n.h>
#include <libpeas/peas.h>
......@@ -1365,7 +1366,7 @@ ide_runner_set_cwd (IdeRunner *self,
g_return_if_fail (IDE_IS_RUNNER (self));
if (!ide_str_equal0 (priv->cwd, cwd))
if (!dzl_str_equal0 (priv->cwd, cwd))
{
g_free (priv->cwd);
priv->cwd = g_strdup (cwd);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment