From 3dcc36c1c3be4bc3e86fcd3d04feb92730bd41da Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 25 Sep 2021 13:50:16 +0200 Subject: [PATCH] =?UTF-8?q?ngspice=20input=20deck=20may=20contain=20specia?= =?UTF-8?q?l=20characters=20like=20=C2=B5=20(mu).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Detect mu for ANSI and UTF-8 and translate it to u. --- src/frontend/inpcom.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 42e688f58..f178d09b1 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -9851,7 +9851,8 @@ void inp_rem_unused_models(struct nscope *root, struct card *deck) * or overlong UTF-8 sequence found, or NULL if the string contains * only correct UTF-8. It also spots UTF-8 sequences that could cause * trouble if converted to UTF-16, namely surrogate characters - * (U+D800..U+DFFF) and non-Unicode positions (U+FFFE..U+FFFF).*/ + * (U+D800..U+DFFF) and non-Unicode positions (U+FFFE..U+FFFF). + * In addition we check for some ngspice-specific characters like µ etc.*/ #ifndef EXT_ASC static unsigned char* utf8_check(unsigned char *s) @@ -9860,6 +9861,23 @@ utf8_check(unsigned char *s) if (*s < 0x80) /* 0xxxxxxx */ s++; + else if (*s == 0xb5) { + /* translate ansi micro µ to u */ + *s = 'u'; + s++; + } + else if (s[0] == 0xc2 && s[1] == 0xb5) { + /* translate utf-8 micro µ to u */ + s[0] = 'u'; + s[1] = ' '; + /* remove second byte */ + unsigned char *y = s + 1; + unsigned char *z = s + 2; + while (*z) { + *y++ = *z++; + } + s++; + } else if ((s[0] & 0xe0) == 0xc0) { /* 110XXXXx 10xxxxxx */ if ((s[1] & 0xc0) != 0x80 ||