From 49d1574575f4e351c481de6e9511631eb96d3bdb Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Thu, 25 Apr 2019 10:59:57 -0400 Subject: [PATCH] only need to dupe string for zalgo if zerowidth present --- skulduggery.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/skulduggery.go b/skulduggery.go index fded8c3..d39f74f 100644 --- a/skulduggery.go +++ b/skulduggery.go @@ -70,19 +70,30 @@ func unpucker(s string) string { return string(x) } s = re_alltheshitz.ReplaceAllStringFunc(s, fixer) - x := make([]byte, 0, len(s)) + zw := false for _, c := range s { if runewidth.RuneWidth(c) == 0 { - if zw { - continue - } zw = true - } else { - zw = false + break } - q := string(c) - x = append(x, []byte(q)...) } - return string(x) + if zw { + x := make([]byte, 0, len(s)) + zw = false + for _, c := range s { + if runewidth.RuneWidth(c) == 0 { + if zw { + continue + } + zw = true + } else { + zw = false + } + q := string(c) + x = append(x, []byte(q)...) + } + return string(x) + } + return s }