[easytag] Use et_str_empty() in several more places



commit 40abf34fa235dcb5527f326bdf772b87b9773bc8
Author: David King <amigadave amigadave com>
Date:   Sat Feb 21 23:12:05 2015 +0000

    Use et_str_empty() in several more places
    
    There are many instances of strlen() being used to check for an empty
    string, which can be replaced with et_str_empty().

 src/browser.c         |   12 +++++++-----
 src/cddb_dialog.c     |    3 +--
 src/playlist_dialog.c |    3 ++-
 src/scan_dialog.c     |   19 +++++++++++--------
 src/tag_area.c        |    6 +++---
 5 files changed, 24 insertions(+), 19 deletions(-)
---
diff --git a/src/browser.c b/src/browser.c
index b3d5f1c..fa0809a 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -1058,7 +1058,7 @@ et_browser_select_dir (EtBrowser *self, const gchar *current_path)
 
     while (parts[index]) // it is NULL-terminated
     {
-        if (strlen(parts[index]) == 0)
+        if (parts[index] == '\0')
         {
             index++;
             continue;
@@ -4170,7 +4170,7 @@ et_browser_show_rename_directory_dialog (EtBrowser *self)
     directory_name = g_strdup(address+1);
     *(address+1) = 0;
 
-    if (!directory_name || strlen(directory_name)==0)
+    if (et_str_empty (directory_name))
     {
         g_free(directory_name);
         g_free(directory_parent);
@@ -4592,10 +4592,12 @@ et_browser_show_open_directory_with_dialog (EtBrowser *self)
     }
 
     /* Current directory. */
-    current_directory = g_strdup (priv->current_path);
-
-    if (!current_directory || strlen(current_directory)==0)
+    if (et_str_empty (priv->current_path))
+    {
         return;
+    }
+
+    current_directory = g_strdup (priv->current_path);
 
     builder = gtk_builder_new ();
     gtk_builder_add_from_resource (builder,
diff --git a/src/cddb_dialog.c b/src/cddb_dialog.c
index 7c5a6f6..c71bfd3 100644
--- a/src/cddb_dialog.c
+++ b/src/cddb_dialog.c
@@ -3161,8 +3161,7 @@ Cddb_Read_Http_Header (FILE **file, gchar **cddb_out)
     {
         g_free (*cddb_out);
     }
-    while (Cddb_Read_Line (file, cddb_out) > 0
-           && *cddb_out && strlen (*cddb_out) > 0);
+    while (Cddb_Read_Line (file, cddb_out) > 0 && !et_str_empty (*cddb_out));
 
     //g_print("Http Header : %s\n",*cddb_out);
     return 1;
diff --git a/src/playlist_dialog.c b/src/playlist_dialog.c
index 1a2d6c8..7efadaa 100644
--- a/src/playlist_dialog.c
+++ b/src/playlist_dialog.c
@@ -604,7 +604,8 @@ entry_check_content_mask (GtkEntry *entry, gpointer user_data)
     g_return_if_fail (entry != NULL);
 
     mask = g_strdup (gtk_entry_get_text (entry));
-    if (!mask || strlen(mask)<1)
+
+    if (et_str_empty (mask))
         goto Bad_Mask;
 
     while (mask)
diff --git a/src/scan_dialog.c b/src/scan_dialog.c
index 9174779..e4e54fd 100644
--- a/src/scan_dialog.c
+++ b/src/scan_dialog.c
@@ -367,7 +367,7 @@ Scan_Tag_With_Mask (EtScanDialog *self, ET_File *ETFile)
     /* Set the default text to comment. */
     if (g_settings_get_boolean (MainSettings, "fill-set-default-comment")
         && (g_settings_get_boolean (MainSettings, "fill-overwrite-tag-fields")
-            || FileTag->comment == NULL || strlen (FileTag->comment) == 0))
+            || et_str_empty (FileTag->comment)))
     {
         gchar *default_comment = g_settings_get_string (MainSettings,
                                                         "fill-default-comment");
@@ -378,7 +378,7 @@ Scan_Tag_With_Mask (EtScanDialog *self, ET_File *ETFile)
     /* Set CRC-32 value as default comment (for files with ID3 tag only). */
     if (g_settings_get_boolean (MainSettings, "fill-crc32-comment")
         && (g_settings_get_boolean (MainSettings, "fill-overwrite-tag-fields")
-            || FileTag->comment == NULL || strlen (FileTag->comment) == 0))
+            || et_str_empty (FileTag->comment)))
     {
         GFile *file;
         GError *error = NULL;
@@ -517,7 +517,7 @@ Scan_Generate_New_Tag_From_Mask (ET_File *ETFile, gchar *mask)
         gchar *file_seq_utf8 = filename_to_display(file_seq);
 
         //g_print(">%d> seq '%s' '%s'\n",loop,mask_seq,file_seq);
-        while ( mask_seq && strlen(mask_seq)>0 )
+        while (!et_str_empty (mask_seq))
         {
 
             /*
@@ -564,7 +564,7 @@ Scan_Generate_New_Tag_From_Mask (ET_File *ETFile, gchar *mask)
             /*
              * Determine separator between two code or trailing text (after code)
              */
-            if ( mask_seq && strlen(mask_seq)>0 )
+            if (!et_str_empty (mask_seq))
             {
                 if ( (tmp=strchr(mask_seq,'%')) == NULL || strlen(tmp) < 2 )
                 {
@@ -915,7 +915,8 @@ et_scan_generate_new_filename_from_mask (const ET_File *ETFile,
         // Now, parses the code to get the corresponding string (from tag)
         source = Scan_Return_File_Tag_Field_From_Mask_Code((File_Tag *)ETFile->FileTag->data,tmp[1]);
         mask_item = g_slice_new0 (File_Mask_Item);
-        if (source && *source && strlen(*source)>0)
+
+        if (source && !et_str_empty (*source))
         {
             mask_item->type = FIELD;
             mask_item->string = g_strdup(*source);
@@ -961,7 +962,7 @@ et_scan_generate_new_filename_from_mask (const ET_File *ETFile,
     }
 
     // It may have some characters before the last remaining code ('__%a')
-    if (mask!=NULL && strlen(mask)>0)
+    if (!et_str_empty (mask))
     {
         mask_item = g_slice_new0 (File_Mask_Item);
         mask_item->type = LEADING_SEPARATOR;
@@ -2764,7 +2765,8 @@ entry_check_scan_tag_mask (GtkEntry *entry, gpointer user_data)
     g_return_if_fail (entry != NULL);
 
     mask = g_strdup (gtk_entry_get_text (entry));
-    if (!mask || strlen(mask)<1)
+
+    if (et_str_empty (mask))
         goto Bad_Mask;
 
     while (mask)
@@ -2840,7 +2842,8 @@ entry_check_rename_file_mask (GtkEntry *entry, gpointer user_data)
     g_return_if_fail (entry != NULL);
 
     mask = g_strdup (gtk_entry_get_text (entry));
-    if (!mask || strlen(mask)<1)
+
+    if (et_str_empty (mask))
         goto Bad_Mask;
 
     // Not a valid path....
diff --git a/src/tag_area.c b/src/tag_area.c
index 1ee216d..f205175 100644
--- a/src/tag_area.c
+++ b/src/tag_area.c
@@ -1876,8 +1876,8 @@ on_picture_save_button_clicked (GObject *object,
         if (init_dir)
             gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(FileSelectionWindow),init_dir);
 
-        // Suggest a filename to the user
-        if ( pic->description && strlen(pic->description) )
+        /* Suggest a filename to the user. */
+        if (!et_str_empty (pic->description))
         {
             gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(FileSelectionWindow), pic->description); 
//filename in UTF8
         }else
@@ -2012,7 +2012,7 @@ on_picture_view_drag_data (GtkWidget *widget, GdkDragContext *dc,
     uri = uri_list = g_strsplit ((const gchar *)gtk_selection_data_get_data (selection_data),
                                  "\r\n", 0);
 
-    while (*uri && strlen(*uri))
+    while (!et_str_empty (*uri))
     {
         GFile *file = g_file_new_for_uri (*uri);
 


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