[easytag/wip/core-refactoring: 6/6] Replace g_utf8_str[r]chr() usage with str[r]chr()



commit 21c01d25d067afcc32876fb545ceea834ef912be
Author: David King <amigadave amigadave com>
Date:   Sat Jan 16 00:14:30 2016 +0000

    Replace g_utf8_str[r]chr() usage with str[r]chr()
    
    If looking for an ASCII character, it is simpler to use the string
    functions from the C library.

 src/cddb_dialog.c      |    4 ++--
 src/file_area.c        |    2 +-
 src/misc.c             |   44 +++++++++++++++++++++++++++-----------------
 src/scan.c             |    4 ++--
 src/tag_area.c         |    8 ++++----
 src/tags/ape_tag.c     |    5 ++---
 src/tags/flac_tag.c    |    4 ++--
 src/tags/id3v24_tag.c  |    4 ++--
 src/tags/ogg_tag.c     |    4 ++--
 src/tags/wavpack_tag.c |    4 ++--
 10 files changed, 46 insertions(+), 37 deletions(-)
---
diff --git a/src/cddb_dialog.c b/src/cddb_dialog.c
index ee02b7a..7ffa57c 100644
--- a/src/cddb_dialog.c
+++ b/src/cddb_dialog.c
@@ -1177,7 +1177,7 @@ Cddb_Get_Album_Tracks_List (EtCDDBDialog *self, GtkTreeSelection* selection)
             cddbtrackalbum->cddbalbum = cddbalbum; // To find the CddbAlbum father quickly
 
             // Here is a fix when TTITLExx doesn't contain an "=", we skip the line
-            if ( (copy = g_utf8_strchr(cddb_out,-1,'=')) != NULL )
+            if ((copy = strchr (cddb_out, '=')) != NULL)
             {
                 cddbtrackalbum->track_name = Try_To_Validate_Utf8_String(copy+1);
             }else
@@ -1186,7 +1186,7 @@ Cddb_Get_Album_Tracks_List (EtCDDBDialog *self, GtkTreeSelection* selection)
                 continue;
             }
 
-            *g_utf8_strchr(cddb_out,-1,'=') = 0;
+            *strchr (cddb_out, '=') = 0;
             cddbtrackalbum->track_number = atoi(cddb_out+6)+1;
 
             // Note : titles too long take severals lines. For example :
diff --git a/src/file_area.c b/src/file_area.c
index dce7418..a0cca16 100644
--- a/src/file_area.c
+++ b/src/file_area.c
@@ -308,7 +308,7 @@ et_file_area_set_file_fields (EtFileArea *self,
     g_object_unref (info);
 
     /* Remove the extension. */
-    if ((pos = g_utf8_strrchr (basename_utf8, -1, '.')) != NULL)
+    if ((pos = strrchr (basename_utf8, '.')) != NULL)
     {
         *pos = 0;
     }
diff --git a/src/misc.c b/src/misc.c
index 3c41d5c..f5e5f37 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -511,16 +511,17 @@ et_filename_prepare (gchar *filename_utf8,
     g_return_if_fail (filename_utf8 != NULL);
 
     // Convert automatically the directory separator ('/' on LINUX and '\' on WIN32) to '-'.
-    while ( (character=g_utf8_strchr(filename_utf8, -1, G_DIR_SEPARATOR))!=NULL )
+    while ((character = strchr (filename_utf8, G_DIR_SEPARATOR)) != NULL)
+    {
         *character = '-';
+    }
 
 #ifdef G_OS_WIN32
-    /* Convert character '\' on WIN32 to '-'. */
-    while ( (character=g_utf8_strchr(filename_utf8, -1, '\\'))!=NULL )
-        *character = '-';
     /* Convert character '/' on WIN32 to '-'. May be converted to '\' after. */
-    while ( (character=g_utf8_strchr(filename_utf8, -1, '/'))!=NULL )
+    while ((character = strchr (filename_utf8, '/')) != NULL)
+    {
         *character = '-';
+    }
 #endif /* G_OS_WIN32 */
 
     /* Convert other illegal characters on FAT32/16 filesystems and ISO9660 and
@@ -529,25 +530,34 @@ et_filename_prepare (gchar *filename_utf8,
     {
         size_t last;
 
-        // Commented as we display unicode values as "\351" for "é"
-        //while ( (character=g_utf8_strchr(filename_utf8, -1, '\\'))!=NULL )
-        //    *character = ',';
-        while ( (character=g_utf8_strchr(filename_utf8, -1, ':'))!=NULL )
+        while ((character = strchr (filename_utf8, ':')) != NULL)
+        {
             *character = '-';
-        //while ( (character=g_utf8_strchr(filename_utf8, -1, ';'))!=NULL )
-        //    *character = '-';
-        while ( (character=g_utf8_strchr(filename_utf8, -1, '*'))!=NULL )
+        }
+        while ((character = strchr (filename_utf8, '*')) != NULL)
+        {
             *character = '+';
-        while ( (character=g_utf8_strchr(filename_utf8, -1, '?'))!=NULL )
+        }
+        while ((character = strchr (filename_utf8, '?')) != NULL)
+        {
             *character = '_';
-        while ( (character=g_utf8_strchr(filename_utf8, -1, '\"'))!=NULL )
+        }
+        while ((character = strchr (filename_utf8, '\"')) != NULL)
+        {
             *character = '\'';
-        while ( (character=g_utf8_strchr(filename_utf8, -1, '<'))!=NULL )
+        }
+        while ((character = strchr (filename_utf8, '<')) != NULL)
+        {
             *character = '(';
-        while ( (character=g_utf8_strchr(filename_utf8, -1, '>'))!=NULL )
+        }
+        while ((character = strchr (filename_utf8, '>')) != NULL)
+        {
             *character = ')';
-        while ( (character=g_utf8_strchr(filename_utf8, -1, '|'))!=NULL )
+        }
+        while ((character = strchr (filename_utf8, '|')) != NULL)
+        {
             *character = '-';
+        }
 
         /* FAT has additional restrictions on the last character of a filename.
          * 
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#naming_conventions */
diff --git a/src/scan.c b/src/scan.c
index f9b2f38..38e5d46 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -394,8 +394,8 @@ Scan_Process_Fields_First_Letters_Uppercase (gchar **str,
     while ( temp )
     {
         word = temp; // Needed if there is only one word
-        word1 = g_utf8_strchr(temp,-1,' ');
-        word2 = g_utf8_strchr(temp,-1,'_');
+        word1 = strchr (temp, ' ');
+        word2 = strchr (temp, '_');
 
         // Take the first string found (near beginning of string)
         if (word1 && word2)
diff --git a/src/tag_area.c b/src/tag_area.c
index a3dd41a..9570844 100644
--- a/src/tag_area.c
+++ b/src/tag_area.c
@@ -265,9 +265,9 @@ on_apply_to_selection (GObject *object,
         gchar *disc_number = NULL;
 
         string_to_set = gtk_entry_get_text (GTK_ENTRY (priv->disc_number_entry));
-        /* g_utf8_strchr() does not allocate a new string, and should probably
-         * return a const gchar *. */
-        separator = g_utf8_strchr (string_to_set, -1, '/');
+        /* strchr() does not allocate a new string, and should probably return
+         * a const gchar *. */
+        separator = strchr (string_to_set, '/');
 
         if (separator)
         {
@@ -2745,7 +2745,7 @@ et_tag_area_create_file_tag (EtTagArea *self)
     {
         gchar *separator;
 
-        separator = g_utf8_strchr (buffer, -1, '/');
+        separator = strchr (buffer, '/');
 
         if (separator && *(separator + 1))
         {
diff --git a/src/tags/ape_tag.c b/src/tags/ape_tag.c
index b56ab9a..0a83acd 100644
--- a/src/tags/ape_tag.c
+++ b/src/tags/ape_tag.c
@@ -109,8 +109,7 @@ ape_tag_read_file_tag (GFile *file,
     {
         string = Try_To_Validate_Utf8_String (string);
 
-        /* strchr does not like NULL string. */
-        string1 = g_utf8_strchr (string, -1, '/');
+        string1 = strchr (string, '/');
 
         if (string1)
         {
@@ -142,7 +141,7 @@ ape_tag_read_file_tag (GFile *file,
     {
         string = Try_To_Validate_Utf8_String(string);
 
-        string1 = g_utf8_strchr(string, -1, '/');    // strchr don't like NULL string
+        string1 = strchr (string, '/');
 
         if (string1)
         {
diff --git a/src/tags/flac_tag.c b/src/tags/flac_tag.c
index 2cb855b..90b0cce 100644
--- a/src/tags/flac_tag.c
+++ b/src/tags/flac_tag.c
@@ -345,7 +345,7 @@ flac_tag_read_file_tag (GFile *file,
                             field_len = field->length - (field_value - (gchar*) field->entry);
                             field_value = validate_field_utf8 (field_value,
                                                                field_len);
-                            string = g_utf8_strchr (field_value, -1, '/');
+                            string = strchr (field_value, '/');
 
                             if (string && !FileTag->disc_total)
                             {
@@ -423,7 +423,7 @@ flac_tag_read_file_tag (GFile *file,
                             field_len = field->length - (field_value - (gchar*) field->entry);
                             field_value = validate_field_utf8 (field_value,
                                                                field_len);
-                            string = g_utf8_strchr(field_value, -1, '/');
+                            string = strchr (field_value, '/');
 
                             if (string && !FileTag->track_total)
                             {
diff --git a/src/tags/id3v24_tag.c b/src/tags/id3v24_tag.c
index dc5b5aa..acacb99 100644
--- a/src/tags/id3v24_tag.c
+++ b/src/tags/id3v24_tag.c
@@ -270,7 +270,7 @@ id3tag_read_file_tag (GFile *gfile,
 
         if (string1)
         {
-            string2 = g_utf8_strchr (string1, -1, '/');
+            string2 = strchr (string1, '/');
 
             if (string2)
             {
@@ -305,7 +305,7 @@ id3tag_read_file_tag (GFile *gfile,
         update |= libid3tag_Get_Frame_Str(frame, ~0, &string1);
         if ( string1 )
         {
-            string2 = g_utf8_strchr(string1,-1,'/');
+            string2 = strchr (string1, '/');
 
             if (string2)
             {
diff --git a/src/tags/ogg_tag.c b/src/tags/ogg_tag.c
index b93813b..9724e8d 100644
--- a/src/tags/ogg_tag.c
+++ b/src/tags/ogg_tag.c
@@ -264,7 +264,7 @@ et_add_file_tags_from_vorbis_comments (vorbis_comment *vc,
         {
             FileTag->disc_total = et_disc_number_to_string (atoi (string1));
         }
-        else if ((string1 = g_utf8_strchr (string, -1, '/')))
+        else if ((string1 = strchr (string, '/')))
         {
             FileTag->disc_total = et_disc_number_to_string (atoi (string1
                                                                   + 1));
@@ -297,7 +297,7 @@ et_add_file_tags_from_vorbis_comments (vorbis_comment *vc,
         {
             FileTag->track_total = et_track_number_to_string (atoi (string1));
         }
-        else if ((string1 = g_utf8_strchr (string, -1, '/')))
+        else if ((string1 = strchr (string, '/')))
         {
             FileTag->track_total = et_track_number_to_string (atoi (string1
                                                                     + 1));
diff --git a/src/tags/wavpack_tag.c b/src/tags/wavpack_tag.c
index 5a543cd..8634c50 100644
--- a/src/tags/wavpack_tag.c
+++ b/src/tags/wavpack_tag.c
@@ -157,7 +157,7 @@ wavpack_tag_read_file_tag (GFile *file,
      * Discnumber + Disctotal.
      */
     length = WavpackGetTagItem (wpc, "part", field, MAXLEN);
-    field2 = g_utf8_strchr (field, -1, '/');
+    field2 = strchr (field, '/');
 
     /* Need to cut off the total tracks if present */
     if (field2)
@@ -201,7 +201,7 @@ wavpack_tag_read_file_tag (GFile *file,
      * Tracknumber + tracktotal
      */
     length = WavpackGetTagItem(wpc, "track", field, MAXLEN);
-    field2 = g_utf8_strchr(field, -1, '/');
+    field2 = strchr (field, '/');
 
     /* Need to cut off the total tracks if present */
     if (field2) {


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