all repos — honk @ bb4b1055ed9d30bfcab8b4314e4bb186ee67d600

my fork of honk

skulduggery.go (view raw)

  1//
  2// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
  3//
  4// Permission to use, copy, modify, and distribute this software for any
  5// purpose with or without fee is hereby granted, provided that the above
  6// copyright notice and this permission notice appear in all copies.
  7//
  8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 11// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 12// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 15
 16package main
 17
 18import (
 19	"regexp"
 20
 21	"github.com/mattn/go-runewidth"
 22)
 23
 24var bigboldshitz = "๐€๐๐‚๐ƒ๐„๐…๐†๐‡๐ˆ๐‰๐Š๐‹๐Œ๐๐Ž๐๐๐‘๐’๐“๐”๐•๐–๐—๐˜๐™"
 25var lilboldshitz = "๐š๐›๐œ๐๐ž๐Ÿ๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ"
 26var biggothshitz = "๐•ฌ๐•ญ๐•ฎ๐•ฏ๐•ฐ๐•ฑ๐•ฒ๐•ณ๐•ด๐•ต๐•ถ๐•ท๐•ธ๐•น๐•บ๐•ป๐•ผ๐•ฝ๐•พ๐•ฟ๐–€๐–๐–‚๐–ƒ๐–„๐–…"
 27var lilgothshitz = "๐–†๐–‡๐–ˆ๐–‰๐–Š๐–‹๐–Œ๐–๐–Ž๐–๐–๐–‘๐–’๐–“๐–”๐–•๐––๐–—๐–˜๐–™๐–š๐–›๐–œ๐–๐–ž๐–Ÿ"
 28var bigitalshitz = "๐‘จ๐‘ฉ๐‘ช๐‘ซ๐‘ฌ๐‘ญ๐‘ฎ๐‘ฏ๐‘ฐ๐‘ฑ๐‘ฒ๐‘ณ๐‘ด๐‘ต๐‘ถ๐‘ท๐‘ธ๐‘น๐‘บ๐‘ป๐‘ผ๐‘ฝ๐‘พ๐‘ฟ๐’€๐’"
 29var lilitalshitz = "๐’‚๐’ƒ๐’„๐’…๐’†๐’‡๐’ˆ๐’‰๐’Š๐’‹๐’Œ๐’๐’Ž๐’๐’๐’‘๐’’๐’“๐’”๐’•๐’–๐’—๐’˜๐’™๐’š๐’›"
 30var bigbangshitz = "๐”ธ๐”นโ„‚๐”ป๐”ผ๐”ฝ๐”พโ„๐•€๐•๐•‚๐•ƒ๐•„โ„•๐•†โ„™โ„šโ„๐•Š๐•‹๐•Œ๐•๐•Ž๐•๐•โ„ค"
 31var lilbangshitz = "๐•’๐•“๐•”๐••๐•–๐•—๐•˜๐•™๐•š๐•›๐•œ๐•๐•ž๐•Ÿ๐• ๐•ก๐•ข๐•ฃ๐•ค๐•ฅ๐•ฆ๐•ง๐•จ๐•ฉ๐•ช๐•ซ"
 32
 33var re_alltheshitz = regexp.MustCompile(`([` +
 34	bigboldshitz + lilboldshitz +
 35	biggothshitz + lilgothshitz +
 36	bigitalshitz + lilitalshitz +
 37	bigbangshitz + lilbangshitz +
 38	`] ?){3,}`)
 39
 40// this may not be especially fast
 41func unpucker(s string) string {
 42	fixer := func(r string) string {
 43		x := make([]byte, len(r))
 44		xi := 0
 45	loop1:
 46		for _, c := range r {
 47			xi++
 48			if c == ' ' {
 49				x[xi] =  ' '
 50				continue
 51			}
 52			for _, set := range []string{bigboldshitz, biggothshitz, bigitalshitz, bigbangshitz} {
 53				i := 0
 54				for _, rr := range set {
 55					if rr == c {
 56						x[xi] = byte('A' + i)
 57						continue loop1
 58					}
 59					i++
 60				}
 61			}
 62			for _, set := range []string{lilboldshitz, lilgothshitz, lilitalshitz, lilbangshitz} {
 63				i := 0
 64				for _, rr := range set {
 65					if rr == c {
 66						x[xi] = byte('a' + i)
 67						continue loop1
 68					}
 69					i++
 70				}
 71			}
 72			x[xi] = '.'
 73		}
 74		return string(x)
 75	}
 76	s = re_alltheshitz.ReplaceAllStringFunc(s, fixer)
 77
 78	zw := false
 79	for _, c := range s {
 80		if runewidth.RuneWidth(c) == 0 {
 81			zw = true
 82			break
 83		}
 84	}
 85	if zw {
 86		x := make([]byte, 0, len(s))
 87		zw = false
 88		for _, c := range s {
 89			if runewidth.RuneWidth(c) == 0 {
 90				if zw {
 91					continue
 92				}
 93				zw = true
 94			} else {
 95				zw = false
 96			}
 97			q := string(c)
 98			x = append(x, []byte(q)...)
 99		}
100		return string(x)
101	}
102	return s
103}