// Strip any leading or trailing whitespace
pakfire_string_strip(buffer);
- // Pointer to the start of the string
- char* p = buffer;
-
- // Determine the length of the string
- const size_t l = strlen(s);
-
- char* linebreak = strstr(p, "\\\n");
- while (linebreak) {
- // Move p to the beginning of the linebreak
- p = linebreak;
-
- // Skip \\\n
- linebreak += strlen("\\\n");
-
- // Find any whitespace after the linebreak
- while (*linebreak && isspace(*linebreak))
- linebreak++;
-
- if (!linebreak)
- break;
-
- // Splice together
- memmove(p, linebreak, buffer + l - linebreak + 1);
-
- // Find another linebreak
- linebreak = strstr(p, "\\\n");
- }
+ // Remove any linebreaks
+ pakfire_string_remove_linebreaks(buffer);
return buffer;
}
return NULL;
}
+void pakfire_string_remove_linebreaks(char* src) {
+ char* dst = src;
+
+ while (*src) {
+ // Check for "\" at the end of a line
+ if (src[0] == '\\' && src[1] == '\n') {
+ // Skip the string
+ src += strlen("\\\n");
+
+ // Consume any following whitespace
+ while (*src && isspace(*src))
+ src++;
+
+ // Otherwise copy the entire string
+ } else {
+ *dst++ = *src++;
+ }
+ }
+
+ // Ensure the string is terminated
+ *dst = '\0';
+}
+
char* pakfire_string_join(const char** list, const char* delim) {
// Validate input
if (!list || !delim) {
int pakfire_string_partition(const char* s, const char* delim, char** s1, char** s2);
char* pakfire_string_replace(const char* s, const char* pattern, const char* repl);
+void pakfire_string_remove_linebreaks(char* src);
char* pakfire_string_join(const char** list, const char* delim);
inline int pakfire_string_equals(const char* s1, const char* s2) {