]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Refactor unquoting strings
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Dec 2024 19:09:59 +0000 (19:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Dec 2024 19:09:59 +0000 (19:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser/scanner.l

index e6659cc41c12c10e12f190f4b14b19a034182c05..fa78fabff12e2d76b9ec6e501f2b714e9fd45f81 100644 (file)
 #include "grammar.h"
 
 static char* unquote(const char* input) {
-       size_t length = strlen(input);
+       char* output = NULL;
 
-       // Check whether the first character is "
-       if (*input != '"')
-               goto COPY;
-
-       // Check whether the last characters is "
-       if (input[length] != '"')
-               goto COPY;
+       // Do nothing if there is no input
+       if (!input)
+               return NULL;
 
-       char* output = malloc(length - 1);
+       // Copy the string
+       output = strdup(input);
        if (!output)
                return NULL;
 
-       // Copy everything except the first and last character
-       snprintf(output, length - 2, "%s", input + 1);
+       // Unquote the string
+       pakfire_string_unquote(output);
 
        return output;
-COPY:
-       return strdup(input);
 }
 
 // Forward declaration