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
45// this may not be especially fast
46func unpucker(s string) string {
47 fixer := func(r string) string {
48 x := make([]byte, len(r))
49 xi := 0
50 loop1:
51 for _, c := range r {
52 xi++
53 if c == ' ' || c == '\'' {
54 x[xi] = byte(c)
55 continue
56 }
57 for _, set := range []string{bigboldshitz, biggothshitz, moegothshitz, bigitalshitz, bigbangshitz, bigblokshitz} {
58 i := 0
59 for _, rr := range set {
60 if rr == c {
61 x[xi] = byte('A' + i)
62 continue loop1
63 }
64 i++
65 }
66 }
67 for _, set := range []string{lilboldshitz, lilgothshitz, morgothshitz, lilitalshitz, lilbangshitz} {
68 i := 0
69 for _, rr := range set {
70 if rr == c {
71 x[xi] = byte('a' + i)
72 continue loop1
73 }
74 i++
75 }
76 }
77 x[xi] = '.'
78 }
79 return string(x)
80 }
81 s = re_alltheshitz.ReplaceAllStringFunc(s, fixer)
82
83 zw := false
84 for _, c := range s {
85 if runewidth.RuneWidth(c) == 0 {
86 zw = true
87 break
88 }
89 }
90 if zw {
91 x := make([]byte, 0, len(s))
92 zw = false
93 for _, c := range s {
94 if runewidth.RuneWidth(c) == 0 {
95 if zw {
96 continue
97 }
98 zw = true
99 } else {
100 zw = false
101 }
102 q := string(c)
103 x = append(x, []byte(q)...)
104 }
105 return string(x)
106 }
107 return s
108}