From 738f4daed7f0555f7ac11dc2f527bc53dddd4e5b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 1 Feb 2019 22:12:52 +0000 Subject: viewvcs: cleanup utf8 handling Favor in-place utf8::decode since it's a bit faster without method dispatch overhead; and don't care about validity just yet. HlMod->do_hl itself should return "utf8" strings, since other parts of our code can use it, so it's not the job of ViewVCS to post-process HlMod output. --- lib/PublicInbox/HlMod.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/PublicInbox/HlMod.pm') diff --git a/lib/PublicInbox/HlMod.pm b/lib/PublicInbox/HlMod.pm index 237ffaca..decfd714 100644 --- a/lib/PublicInbox/HlMod.pm +++ b/lib/PublicInbox/HlMod.pm @@ -107,7 +107,12 @@ sub do_hl { $g->setEncoding('utf-8'); $g; }; - \($gen->generateString($$str)) + + # we assume $$str is valid UTF-8, but the SWIG binding doesn't + # know that, so ensure it's marked as UTF-8 even if it isnt... + my $out = $gen->generateString($$str); + utf8::decode($out); + \$out; } # SWIG instances aren't reference-counted, but $self is; -- cgit v1.2.3-24-ge0c7