[vlc-commits] str_format_meta: clean up

Rémi Denis-Courmont git at videolan.org
Wed Jan 1 19:55:58 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jan  1 20:17:32 2014 +0200| [098f3844b086a18c332f663a13c586bf1881b297] | committer: Rémi Denis-Courmont

str_format_meta: clean up

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=098f3844b086a18c332f663a13c586bf1881b297
---

 src/text/strings.c |   92 +++++++++++++---------------------------------------
 1 file changed, 23 insertions(+), 69 deletions(-)

diff --git a/src/text/strings.c b/src/text/strings.c
index 7d5651e..712116d 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -46,7 +46,6 @@
 
 #include <vlc_strings.h>
 #include <vlc_charset.h>
-#include <vlc_fs.h>
 #include <libvlc.h>
 #include <errno.h>
 
@@ -512,7 +511,7 @@ static void format_duration (char *buf, size_t len, int64_t duration)
 #define INSERT_STRING( string )                                     \
                     if( string != NULL )                            \
                     {                                               \
-                        int len = strlen( string );                 \
+                        size_t len = strlen( string );              \
                         dst = xrealloc( dst, i_size = i_size + len );\
                         memcpy( (dst+d), string, len );             \
                         d += len;                                   \
@@ -522,28 +521,25 @@ static void format_duration (char *buf, size_t len, int64_t duration)
 /* same than INSERT_STRING, except that string won't be freed */
 #define INSERT_STRING_NO_FREE( string )                             \
                     {                                               \
-                        int len = strlen( string );                 \
+                        size_t len = strlen( string );              \
                         dst = xrealloc( dst, i_size = i_size + len );\
                         memcpy( dst+d, string, len );               \
                         d += len;                                   \
                     }
-char *str_format_meta( playlist_t *p_object, const char *string )
+char *str_format_meta( playlist_t *p_playlist, const char *s )
 {
-    const char *s = string;
+    char *dst = strdup( s );
+    if( unlikely(dst == NULL) )
+        return NULL;
+
+    input_thread_t *p_input = playlist_CurrentInput( p_playlist );
+    input_item_t *p_item = p_input ? input_GetItem(p_input) : NULL;
+    size_t i_size = strlen( s ) + 1; /* +1 to store '\0' */
+    size_t d = 0;
+
     bool b_is_format = false;
     bool b_empty_if_na = false;
     char buf[10];
-    int i_size = strlen( string ) + 1; /* +1 to store '\0' */
-    char *dst = strdup( string );
-    if( !dst ) return NULL;
-    int d = 0;
-
-    input_thread_t *p_input = playlist_CurrentInput( p_object );
-    input_item_t *p_item = NULL;
-    if( p_input )
-    {
-        p_item = input_GetItem(p_input);
-    }
 
     while( *s )
     {
@@ -553,33 +549,23 @@ char *str_format_meta( playlist_t *p_object, const char *string )
             {
                 case 'a':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetArtist( p_item ) );
-                    }
                     break;
                 case 'b':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetAlbum( p_item ) );
-                    }
                     break;
                 case 'c':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetCopyright( p_item ) );
-                    }
                     break;
                 case 'd':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetDescription( p_item ) );
-                    }
                     break;
                 case 'e':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetEncodedBy( p_item ) );
-                    }
                     break;
                 case 'f':
                     if( p_item && p_item->p_stats )
@@ -595,33 +581,23 @@ char *str_format_meta( playlist_t *p_object, const char *string )
                     break;
                 case 'g':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetGenre( p_item ) );
-                    }
                     break;
                 case 'l':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetLanguage( p_item ) );
-                    }
                     break;
                 case 'n':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetTrackNum( p_item ) );
-                    }
                     break;
                 case 'p':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetNowPlaying( p_item ) );
-                    }
                     break;
                 case 'r':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetRating( p_item ) );
-                    }
                     break;
                 case 's':
                     {
@@ -635,38 +611,28 @@ char *str_format_meta( playlist_t *p_object, const char *string )
                     }
                 case 't':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetTitle( p_item ) );
-                    }
                     break;
                 case 'u':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetURL( p_item ) );
-                    }
                     break;
                 case 'A':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetDate( p_item ) );
-                    }
                     break;
                 case 'B':
                     if( p_input )
-                    {
                         snprintf( buf, 10, "%"PRId64,
                                   var_GetInteger( p_input, "bit-rate" )/1000 );
-                    }
                     else
                         strcpy( buf, b_empty_if_na ? "" : "-" );
                     INSERT_STRING_NO_FREE( buf );
                     break;
                 case 'C':
                     if( p_input )
-                    {
                         snprintf( buf, 10, "%"PRId64,
                                   var_GetInteger( p_input, "chapter" ) );
-                    }
                     else
                         strcpy( buf, b_empty_if_na ? "" : "-" );
                     INSERT_STRING_NO_FREE( buf );
@@ -683,16 +649,12 @@ char *str_format_meta( playlist_t *p_object, const char *string )
                     break;
                 case 'F':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetURI( p_item ) );
-                    }
                     break;
                 case 'I':
                     if( p_input )
-                    {
                         snprintf( buf, 10, "%"PRId64,
                                   var_GetInteger( p_input, "title" ) );
-                    }
                     else
                         strcpy( buf, b_empty_if_na ? "" : "-" );
                     INSERT_STRING_NO_FREE( buf );
@@ -711,31 +673,25 @@ char *str_format_meta( playlist_t *p_object, const char *string )
                     break;
                 case 'N':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetName( p_item ) );
-                    }
                     break;
                 case 'O':
-                    {
-                        char *lang = NULL;
-                        if( p_input )
-                            lang = var_GetNonEmptyString( p_input,
-                                                          "audio-language" );
-                        if( lang == NULL )
-                            lang = strdup( b_empty_if_na ? "" : "-" );
-                        INSERT_STRING( lang );
-                        break;
-                    }
+                {
+                    char *lang = NULL;
+                    if( p_input )
+                        lang = var_GetNonEmptyString( p_input,
+                                                      "audio-language" );
+                    if( lang == NULL )
+                        lang = strdup( b_empty_if_na ? "" : "-" );
+                    INSERT_STRING( lang );
+                    break;
+                }
                 case 'P':
                     if( p_input )
-                    {
                         snprintf( buf, 10, "%2.1lf",
                                   var_GetFloat( p_input, "position" ) * 100. );
-                    }
                     else
-                    {
                         snprintf( buf, 10, b_empty_if_na ? "" : "--.-%%" );
-                    }
                     INSERT_STRING_NO_FREE( buf );
                     break;
                 case 'R':
@@ -770,14 +726,12 @@ char *str_format_meta( playlist_t *p_object, const char *string )
                     break;
                 case 'U':
                     if( p_item )
-                    {
                         INSERT_STRING( input_item_GetPublisher( p_item ) );
-                    }
                     break;
                 case 'V':
                 {
                     float vol = playlist_VolumeGet( p_object );
-                    if( vol >= 0. )
+                    if( vol >= 0.f )
                     {
                         snprintf( buf, 10, "%ld",
                                   lroundf(vol * AOUT_VOLUME_DEFAULT ) );



More information about the vlc-commits mailing list