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