Skip to content

Commit

Permalink
Updated the function so that they would work better
Browse files Browse the repository at this point in the history
The function now work properly if a directory or file has the ' character in their name so that they don't get removed or get counted as having quoutes
  • Loading branch information
Black-Speedy committed Jan 5, 2024
1 parent 14346e0 commit 10866b0
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions WebShare-Connect/removeQuotes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}

0 comments on commit 10866b0

Please sign in to comment.