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 `]{2,}`)
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 for _, set := range []string{bigboldshitz, biggothshitz, bigitalshitz, bigbangshitz} {
49 i := 0
50 for _, rr := range set {
51 if rr == c {
52 x[xi] = byte('A' + i)
53 continue loop1
54 }
55 i++
56 }
57 }
58 for _, set := range []string{lilboldshitz, lilgothshitz, lilitalshitz, lilbangshitz} {
59 i := 0
60 for _, rr := range set {
61 if rr == c {
62 x[xi] = byte('a' + i)
63 continue loop1
64 }
65 i++
66 }
67 }
68 x[xi] = '.'
69 }
70 return string(x)
71 }
72 s = re_alltheshitz.ReplaceAllStringFunc(s, fixer)
73
74 zw := false
75 for _, c := range s {
76 if runewidth.RuneWidth(c) == 0 {
77 zw = true
78 break
79 }
80 }
81 if zw {
82 x := make([]byte, 0, len(s))
83 zw = false
84 for _, c := range s {
85 if runewidth.RuneWidth(c) == 0 {
86 if zw {
87 continue
88 }
89 zw = true
90 } else {
91 zw = false
92 }
93 q := string(c)
94 x = append(x, []byte(q)...)
95 }
96 return string(x)
97 }
98 return s
99}