summaryrefslogtreecommitdiff
path: root/amiga/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'amiga/misc.c')
-rwxr-xr-xamiga/misc.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/amiga/misc.c b/amiga/misc.c
index cedff5d77..cee6aa688 100755
--- a/amiga/misc.c
+++ b/amiga/misc.c
@@ -82,3 +82,40 @@ char *path_to_url(const char *path)
return r;
}
+
+/**
+ * returns a string without escape chars or |M chars.
+ * (based on remove_underscores from utils.c)
+ * \param translate true to insert a linebreak where there was |M,
+ * and capitalise initial characters after escape chars.
+ */
+
+char *remove_escape_chars(const char *s, bool translate)
+{
+ size_t i, ii, len;
+ char *ret;
+ bool nextcharupper = false;
+ len = strlen(s);
+ ret = malloc(len + 1);
+ if (ret == NULL)
+ return NULL;
+ for (i = 0, ii = 0; i < len; i++) {
+ if ((s[i] != '\\') && (s[i] != '|')) {
+ if(nextcharupper) {
+ ret[ii++] = toupper(s[i]);
+ nextcharupper = false;
+ }
+ else ret[ii++] = s[i];
+ }
+ else if ((translate) && (s[i] == '|') && (s[i+1] == 'M')) {
+ ret[ii++] = '\n';
+ i++;
+ }
+ else {
+ if(translate) nextcharupper = true;
+ i++;
+ }
+ }
+ ret[ii] = '\0';
+ return ret;
+}