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}