summaryrefslogtreecommitdiff
path: root/src/c/urweb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/c/urweb.c')
-rw-r--r--src/c/urweb.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index b820354f..af929269 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -21,6 +21,7 @@
#include <pthread.h>
#include <unicode/utf8.h>
+#include <unicode/ustring.h>
#include <unicode/uchar.h>
#include "types.h"
@@ -2344,10 +2345,23 @@ char *uw_Basis_htmlifySpecialChar(uw_context ctx, uw_Basis_char ch) {
uw_unit uw_Basis_htmlifySpecialChar_w(uw_context ctx, uw_Basis_char ch) {
unsigned int n = ch;
- int len;
+ int len = 0;
uw_check(ctx, INTS_MAX+3);
- len = sprintf(ctx->page.front, "&#%u;", n);
+
+ if(uw_Basis_isprint(ctx, ch)) {
+
+ int32_t len_written = 0;
+ UErrorCode err = U_ZERO_ERROR;
+
+ u_strToUTF8(ctx->page.front, 5, &len_written, (const UChar*)&ch, 1, &err);
+ len = len_written;
+ }
+
+ // either it's a non-printable character, or we failed to convert to UTF-8
+ if(len == 0) {
+ len = sprintf(ctx->page.front, "&#%u;", n);
+ }
ctx->page.front += len;
return uw_unit_v;
@@ -2459,7 +2473,7 @@ uw_unit uw_Basis_htmlifyString_w(uw_context ctx, uw_Basis_string s) {
else {
uw_Basis_htmlifySpecialChar_w(ctx, c1);
}
- }
+ }
return uw_unit_v;
}