diff --git a/WebShare-Connect/removeQuotes.c b/WebShare-Connect/removeQuotes.c index 3b18dbc..fe021fe 100644 --- a/WebShare-Connect/removeQuotes.c +++ b/WebShare-Connect/removeQuotes.c @@ -4,13 +4,19 @@ int containsQuotes(const char* str) { + int singleQuoteAtBeginning = 0; + if (*str == '\'') { + singleQuoteAtBeginning = 1; + } + while (*str != '\0') { - if (*str == '"' || *str == '\'') { + if (*str == '"') { return 1; } str++; } - return 0; + + return singleQuoteAtBeginning; } char* removeQuotes(const char* str) { @@ -24,14 +30,33 @@ char* removeQuotes(const char* str) { const char* current = str; // Pointer for iteration char* newStrPtr = newStr; // Pointer to build the modified string - while (*current != '\0') { - if (*current != '"' && *current != '\'') { + int singleQuoteAtBeginning = 0; + if (*current == '\'') { + const char* end = str + len - 1; + if (*end == '\'') { + singleQuoteAtBeginning = 1; + current++; + len -= 2; // Reduce the length to exclude the single quotes at the beginning and the end + } + } + + while (*current != '\0' && len > 0) { + if (*current != '"') { *newStrPtr = *current; newStrPtr++; } current++; + len--; } *newStrPtr = '\0'; // Null-terminate the modified string + if (singleQuoteAtBeginning) { + // If single quote was at the beginning, remove it from the end as well + size_t newLen = strlen(newStr); + if (newLen > 0 && newStr[newLen - 1] == '\'') { + newStr[newLen - 1] = '\0'; + } + } + return newStr; -} \ No newline at end of file +}