From 253e72786b5d36cdea59afd7ab853ba5f7acce09 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Tue, 5 May 2020 14:04:23 -0400 Subject: [PATCH] Tweaks to utilsReplaceIllegalCharacters. We won't need to replace characters outside of the ASCII range for USB transfers. --- source/utils.c | 15 ++------------- source/utils.h | 2 +- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/source/utils.c b/source/utils.c index b3c96c7..6beae83 100644 --- a/source/utils.c +++ b/source/utils.c @@ -245,18 +245,7 @@ out: mutexUnlock(&g_logfileMutex); } -void removeIllegalCharacters(char *name) -{ - if (!name || !strlen(name)) return; - - u32 i, len = strlen(name); - for (i = 0; i < len; i++) - { - if (memchr("?[]/\\=+<>:;\",*|^", name[i], sizeof("?[]/\\=+<>:;\",*|^") - 1) || name[i] < 0x20 || name[i] > 0x7E) name[i] = '_'; - } -} - -void utilsReplaceIllegalCharacters(char *str) +void utilsReplaceIllegalCharacters(char *str, bool ascii_only) { size_t strsize = 0; @@ -264,7 +253,7 @@ void utilsReplaceIllegalCharacters(char *str) for(size_t i = 0; i < strsize; i++) { - if (memchr("?[]/\\=+<>:;\",*|^", str[i], sizeof("?[]/\\=+<>:;\",*|^") - 1) || str[i] < 0x20 || str[i] > 0x7E) str[i] = '_'; + if (memchr("?[]/\\=+<>:;\",*|^", str[i], sizeof("?[]/\\=+<>:;\",*|^") - 1) || str[i] < 0x20 || (!ascii_only && str[i] == 0x7F) || (ascii_only && str[i] >= 0x7F)) str[i] = '_'; } } diff --git a/source/utils.h b/source/utils.h index 152e962..abeb335 100644 --- a/source/utils.h +++ b/source/utils.h @@ -67,7 +67,7 @@ void utilsWaitForButtonPress(void); void utilsWriteLogMessage(const char *func_name, const char *fmt, ...); -void utilsReplaceIllegalCharacters(char *str); +void utilsReplaceIllegalCharacters(char *str, bool ascii_only); void utilsTrimString(char *str);