all repos — honk @ 9ecbd57f09a044972ef5ee5772d5df1808343171

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 moegothshitz = "๐”„๐”…๐•ฎ๐”‡๐”ˆ๐”‰๐”Š๐•ณโ„‘๐”๐”Ž๐”๐”๐”‘๐”’๐”“๐””โ„œ๐”–๐”—๐”˜๐”™๐”š๐”›๐”œ๐–…"
 29var morgothshitz = "๐”ž๐”Ÿ๐” ๐”ก๐”ข๐”ฃ๐”ค๐”ฅ๐”ฆ๐”ง๐”จ๐”ฉ๐”ช๐”ซ๐”ฌ๐”ญ๐”ฎ๐”ฏ๐”ฐ๐”ฑ๐”ฒ๐”ณ๐”ด๐”ต๐”ถ๐”ท"
 30var bigitalshitz = "๐‘จ๐‘ฉ๐‘ช๐‘ซ๐‘ฌ๐‘ญ๐‘ฎ๐‘ฏ๐‘ฐ๐‘ฑ๐‘ฒ๐‘ณ๐‘ด๐‘ต๐‘ถ๐‘ท๐‘ธ๐‘น๐‘บ๐‘ป๐‘ผ๐‘ฝ๐‘พ๐‘ฟ๐’€๐’"
 31var lilitalshitz = "๐’‚๐’ƒ๐’„๐’…๐’†๐’‡๐’ˆ๐’‰๐’Š๐’‹๐’Œ๐’๐’Ž๐’๐’๐’‘๐’’๐’“๐’”๐’•๐’–๐’—๐’˜๐’™๐’š๐’›"
 32var bigbangshitz = "๐”ธ๐”นโ„‚๐”ป๐”ผ๐”ฝ๐”พโ„๐•€๐•๐•‚๐•ƒ๐•„โ„•๐•†โ„™โ„šโ„๐•Š๐•‹๐•Œ๐•๐•Ž๐•๐•โ„ค"
 33var lilbangshitz = "๐•’๐•“๐•”๐••๐•–๐•—๐•˜๐•™๐•š๐•›๐•œ๐•๐•ž๐•Ÿ๐• ๐•ก๐•ข๐•ฃ๐•ค๐•ฅ๐•ฆ๐•ง๐•จ๐•ฉ๐•ช๐•ซ"
 34var bigblokshitz = "๐Ÿ…ฐ๐Ÿ…ฑ๐Ÿ…ฒ๐Ÿ…ณ๐Ÿ…ด๐Ÿ…ต๐Ÿ…ถ๐Ÿ…ท๐Ÿ…ธ๐Ÿ…น๐Ÿ…บ๐Ÿ…ป๐Ÿ…ผ๐Ÿ…ฝ๐Ÿ…พ๐Ÿ…ฟ๐Ÿ†€๐Ÿ†๐Ÿ†‚๐Ÿ†ƒ๐Ÿ†„๐Ÿ†…๐Ÿ††๐Ÿ†‡๐Ÿ†ˆ๐Ÿ†‰"
 35
 36var re_alltheshitz = regexp.MustCompile(`([` +
 37	bigboldshitz + lilboldshitz +
 38	biggothshitz + lilgothshitz +
 39	moegothshitz + morgothshitz +
 40	bigitalshitz + lilitalshitz +
 41	bigbangshitz + lilbangshitz +
 42	bigblokshitz +
 43	"][ '\ufe0f]?){3,}")
 44
 45var re_moredumb = regexp.MustCompile(`[๐Ÿ‘]`)
 46
 47// this may not be especially fast
 48func unpucker(s string) string {
 49	fixer := func(r string) string {
 50		x := make([]byte, len(r))
 51		xi := 0
 52	loop1:
 53		for _, c := range r {
 54			xi++
 55			if c == ' ' || c == '\'' {
 56				x[xi] = byte(c)
 57				continue
 58			}
 59			for _, set := range []string{bigboldshitz, biggothshitz, moegothshitz, bigitalshitz, bigbangshitz, bigblokshitz} {
 60				i := 0
 61				for _, rr := range set {
 62					if rr == c {
 63						x[xi] = byte('A' + i)
 64						continue loop1
 65					}
 66					i++
 67				}
 68			}
 69			for _, set := range []string{lilboldshitz, lilgothshitz, morgothshitz, lilitalshitz, lilbangshitz} {
 70				i := 0
 71				for _, rr := range set {
 72					if rr == c {
 73						x[xi] = byte('a' + i)
 74						continue loop1
 75					}
 76					i++
 77				}
 78			}
 79			x[xi] = '.'
 80		}
 81		return string(x)
 82	}
 83	s = re_alltheshitz.ReplaceAllStringFunc(s, fixer)
 84
 85	s = re_moredumb.ReplaceAllString(s, ".")
 86
 87	zw := false
 88	for _, c := range s {
 89		if runewidth.RuneWidth(c) == 0 {
 90			zw = true
 91			break
 92		}
 93	}
 94	if zw {
 95		x := make([]byte, 0, len(s))
 96		zw = false
 97		for _, c := range s {
 98			if runewidth.RuneWidth(c) == 0 {
 99				if zw {
100					continue
101				}
102				zw = true
103			} else {
104				zw = false
105			}
106			q := string(c)
107			x = append(x, []byte(q)...)
108		}
109		return string(x)
110	}
111	return s
112}