Improve id3tag parsing for duplicated code(skip new line) 97/214997/1
authorjiyong.min <jiyong.min@samsung.com>
Tue, 24 Sep 2019 03:21:38 +0000 (12:21 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Thu, 26 Sep 2019 00:15:56 +0000 (09:15 +0900)
Change-Id: I4914f579dadb63713efc8c37cce61a73db5b3c32

utils/mm_file_util_tag.c

index 025704f..da4175b 100644 (file)
@@ -2558,6 +2558,15 @@ static void _mm_file_id3tag_add_bracket_at_genre(char **genre, int genre_len)
        }
 }
 
+static void __id3tag_skip_newline(unsigned char *pTagVal, int *nTagLen, int *offset)
+{
+       /* skip newline in text encoding of ID3 tag frame */
+       while ((NEWLINE_OF_UTF16(pTagVal + *offset) || NEWLINE_OF_UTF16_R(pTagVal + *offset)) && *nTagLen > 4) {
+               *nTagLen -= 4;
+               *offset += 4;
+       }
+}
+
 static bool __id3tag_parse_PIC_format(AvFileContentInfo *pInfo, unsigned char *pTagVal, int *offset)
 {
        unsigned int idx = 0;
@@ -3225,10 +3234,7 @@ bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                                /*pExtContent[tmp+1] value should't have encoding value */
                                                                if (pExtContent[tmp] == 0x00 || pExtContent[tmp] == 0xFF || pExtContent[tmp] == 0xFE) {
                                                                        if ((IS_ENCODEDBY_UTF16(pExtContent + tmp) || IS_ENCODEDBY_UTF16_R(pExtContent + tmp)) && realCpyFrameNum > 2) {
-                                                                               while ((NEWLINE_OF_UTF16(pExtContent + tmp) || NEWLINE_OF_UTF16_R(pExtContent + tmp)) && realCpyFrameNum > 4) {
-                                                                                       realCpyFrameNum -= 4;
-                                                                                       tmp += 4;
-                                                                               }
+                                                                               __id3tag_skip_newline(pExtContent, &realCpyFrameNum, &tmp);
 
                                                                                if (IS_ENCODEDBY_UTF16(pExtContent + tmp) && (realCpyFrameNum > 2)) {
                                                                                        realCpyFrameNum -= 2;
@@ -3285,10 +3291,7 @@ bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                                /*pExtContent[tmp+1] value should't have encoding value */
                                                                if (pExtContent[tmp] == 0x00 || pExtContent[tmp] == 0xFF || pExtContent[tmp] == 0xFE) {
                                                                        if ((IS_ENCODEDBY_UTF16(pExtContent + tmp) || IS_ENCODEDBY_UTF16_R(pExtContent + tmp)) && realCpyFrameNum > 2) {
-                                                                               while ((NEWLINE_OF_UTF16(pExtContent + tmp) || NEWLINE_OF_UTF16_R(pExtContent + tmp)) && realCpyFrameNum > 4) {
-                                                                                       realCpyFrameNum -= 4;
-                                                                                       tmp += 4;
-                                                                               }
+                                                                               __id3tag_skip_newline(pExtContent, &realCpyFrameNum, &tmp);
 
                                                                                if (IS_ENCODEDBY_UTF16(pExtContent + tmp) && (realCpyFrameNum > 2)) {
                                                                                        realCpyFrameNum -= 2;
@@ -3397,10 +3400,7 @@ bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer)
 
                                                                if (pExtContent[tmp] == 0x00 || pExtContent[tmp] == 0xFF || pExtContent[tmp] == 0xFE) {
                                                                        if ((IS_ENCODEDBY_UTF16(pExtContent + tmp) || IS_ENCODEDBY_UTF16_R(pExtContent + tmp)) && realCpyFrameNum > 2) {
-                                                                               while ((NEWLINE_OF_UTF16(pExtContent + tmp) || NEWLINE_OF_UTF16_R(pExtContent + tmp)) && realCpyFrameNum > 4) {
-                                                                                       realCpyFrameNum -= 4;
-                                                                                       tmp += 4;
-                                                                               }
+                                                                               __id3tag_skip_newline(pExtContent, &realCpyFrameNum, &tmp);
 
                                                                                if (IS_ENCODEDBY_UTF16(pExtContent + tmp) && (realCpyFrameNum > 2)) {
                                                                                        realCpyFrameNum -= 2;
@@ -3707,10 +3707,7 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                                tmp = 3;
 
                                                                if (textEncodingType == AV_ID3V2_UTF16 || textEncodingType == AV_ID3V2_UTF16_BE) {
-                                                                       while ((NEWLINE_OF_UTF16(pExtContent + tmp) || NEWLINE_OF_UTF16_R(pExtContent + tmp)) && realCpyFrameNum > 4) {
-                                                                               realCpyFrameNum -= 4;
-                                                                               tmp += 4;
-                                                                       }
+                                                                       __id3tag_skip_newline(pExtContent, &realCpyFrameNum, &tmp);
 
                                                                        if ((IS_ENCODEDBY_UTF16(pExtContent + tmp) || IS_ENCODEDBY_UTF16_R(pExtContent + tmp)) && realCpyFrameNum > 2) {
                                                                                realCpyFrameNum -= 2;
@@ -3756,10 +3753,7 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                                tmp = 5;
 
                                                                if (textEncodingType == AV_ID3V2_UTF16 || textEncodingType == AV_ID3V2_UTF16_BE) {
-                                                                       while ((NEWLINE_OF_UTF16(pExtContent + tmp) || NEWLINE_OF_UTF16_R(pExtContent + tmp)) && realCpyFrameNum > 4) {
-                                                                               realCpyFrameNum -= 4;
-                                                                               tmp += 4;
-                                                                       }
+                                                                       __id3tag_skip_newline(pExtContent, &realCpyFrameNum, &tmp);
 
                                                                        if ((IS_ENCODEDBY_UTF16(pExtContent + tmp) || IS_ENCODEDBY_UTF16_R(pExtContent + tmp)) && realCpyFrameNum > 2) {
                                                                                realCpyFrameNum -= 2;
@@ -3834,10 +3828,7 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                                tmp = 3;
 
                                                                if (textEncodingType == AV_ID3V2_UTF16 || textEncodingType == AV_ID3V2_UTF16_BE) {
-                                                                       while ((NEWLINE_OF_UTF16(pExtContent + tmp) || NEWLINE_OF_UTF16_R(pExtContent + tmp)) && realCpyFrameNum > 4) {
-                                                                               realCpyFrameNum -= 4;
-                                                                               tmp += 4;
-                                                                       }
+                                                                       __id3tag_skip_newline(pExtContent, &realCpyFrameNum, &tmp);
 
                                                                        if ((IS_ENCODEDBY_UTF16(pExtContent + tmp) || IS_ENCODEDBY_UTF16_R(pExtContent + tmp)) && realCpyFrameNum > 2) {
                                                                                realCpyFrameNum -= 2;