Do simple \ replacement in user strings

This commit is contained in:
Linus Dierheimer
2022-08-18 11:36:30 +02:00
parent 83016289e9
commit 6cdb694e33
3 changed files with 37 additions and 3 deletions
+34 -2
View File
@@ -30,7 +30,7 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
ffParseFormatString(&key, customKeyFormat, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex}
});
ffStrbufWriteTo(&key, stdout);
ffPrintUserString(key.chars);
ffStrbufDestroy(&key);
}
@@ -53,7 +53,8 @@ void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t m
if(buffer.length > 0)
{
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
ffStrbufPutTo(&buffer, stdout);
ffPrintUserString(buffer.chars);
putchar('\n');
}
ffStrbufDestroy(&buffer);
@@ -129,3 +130,34 @@ void ffPrintCharTimes(char c, uint32_t times)
for(uint32_t i = 0; i < times; i++)
putchar(c);
}
void ffPrintUserString(const char* value)
{
while(*value != '\0')
{
if(*value != '\\')
{
putchar(*value);
++value;
continue;
}
++value;
if(*value == 'n')
putchar('\n');
else if(*value == 't')
putchar('\t');
else if(*value == 'e')
putchar('\e');
else if(*value == '\\')
putchar('\\');
else
{
putchar('\\');
putchar(*value);
}
++value;
}
}
+1
View File
@@ -13,5 +13,6 @@ void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t mo
void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...);
void ffPrintColor(const FFstrbuf* colorValue);
void ffPrintCharTimes(char c, uint32_t times);
void ffPrintUserString(const char* str);
#endif
+2 -1
View File
@@ -4,5 +4,6 @@
void ffPrintCustom(FFinstance* instance, const char* key, const char* value)
{
ffPrintLogoAndKey(instance, key, 0, NULL);
puts(value);
ffPrintUserString(value);
putchar('\n');
}