diff options
author | jilles <jilles@FreeBSD.org> | 2011-05-08 17:40:10 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2011-05-08 17:40:10 +0000 |
commit | c9be2081e05e10ddab3dcb7fe31efcc981524e18 (patch) | |
tree | e90b9f059591317bfa02d51bd83a0cf89ad9f520 /bin/sh/parser.c | |
parent | bf0e27838c7f0e2558fb05339e6f8b74848281c9 (diff) | |
download | FreeBSD-src-c9be2081e05e10ddab3dcb7fe31efcc981524e18.zip FreeBSD-src-c9be2081e05e10ddab3dcb7fe31efcc981524e18.tar.gz |
sh: Add \u/\U support (in $'...') for UTF-8.
Because we have no iconv in base, support for other charsets is not
possible.
Note that \u/\U are processed using the locale that was active when the
shell started. This is necessary to avoid behaviour that depends on the
parse/execute split (for example when placing braces around an entire
script). Therefore, UTF-8 encoding is implemented manually.
Diffstat (limited to 'bin/sh/parser.c')
-rw-r--r-- | bin/sh/parser.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 5133d67..cc1860d 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -1219,6 +1219,29 @@ readcstyleesc(char *out) if (v == 0 || (v >= 0xd800 && v <= 0xdfff)) synerror("Bad escape sequence"); /* We really need iconv here. */ + if (initial_localeisutf8 && v > 127) { + CHECKSTRSPACE(4, out); + /* + * We cannot use wctomb() as the locale may have + * changed. + */ + if (v <= 0x7ff) { + USTPUTC(0xc0 | v >> 6, out); + USTPUTC(0x80 | (v & 0x3f), out); + return out; + } else if (v <= 0xffff) { + USTPUTC(0xe0 | v >> 12, out); + USTPUTC(0x80 | ((v >> 6) & 0x3f), out); + USTPUTC(0x80 | (v & 0x3f), out); + return out; + } else if (v <= 0x10ffff) { + USTPUTC(0xf0 | v >> 18, out); + USTPUTC(0x80 | ((v >> 12) & 0x3f), out); + USTPUTC(0x80 | ((v >> 6) & 0x3f), out); + USTPUTC(0x80 | (v & 0x3f), out); + return out; + } + } if (v > 127) v = '?'; break; |