~seirdy/moac

moac/charsets/defaults.go -rw-r--r-- 2.9 KiB
97035daeRohan Kumar Chore(deps): bump deps 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package charsets

// DefaultCharset is a pre-built charset, with a name and string/rune representations.
type DefaultCharset int

const (
	// Lowercase contains runes in the range [a-z].
	Lowercase DefaultCharset = iota
	// Uppercase contains runes in the range [A-Z].
	Uppercase
	// Numbers contains runes in the range [0-9].
	Numbers
	// Symbols contains all the ASCII symbols.
	Symbols
	// Latin1 contains all the glyphs in the Latin-1 Unicode block.
	Latin1
	// LatinExtendedA contains all the glyphs in the Latin Extended-A Unicode block.
	LatinExtendedA
	// LatinExtendedB contains all the glyphs in the Latin Extended-B Unicode block.
	LatinExtendedB
	// IPAExtensions contains all the glyphs in the IPA Extensions Unicode block.
	IPAExtensions
)

func (dc DefaultCharset) String() string {
	return [...]string{
		"abcdefghijklmnopqrstuvwxyz",
		"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
		"0123456789",
		"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
		"¡¢£¤¥¦§¨©ª«¬®¯°±²³´μ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ",
		"ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſ",
		"ƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴǵǶǷǸǹǺǻǼǽǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȜȝȞȟȠȡȢȣȤȥȦȧȨȩȪȫȬȭȮȯȰȱȲȳȴȵȶȷȸȹȺȻȼȽȾȿɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏ",
		"ɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯ",
	}[dc]
}

// Name outputs the human-readable name for a charset, useful for matching user input.
func (dc DefaultCharset) Name() string {
	return [...]string{
		"lowercase",
		"uppercase",
		"numbers",
		"symbols",
		"latin1",
		"latinExtendedA",
		"latinExtendedB",
		"ipaExtensions",
	}[dc]
}

// Runes outputs all the runes in a charset.
func (dc DefaultCharset) Runes() []rune {
	return []rune(dc.String())
}

// DefaultCharsets contains pre-built named charsets.
// This makes identifying a charset by name (e.g. as a CLI argument) much easier.
var DefaultCharsets = []DefaultCharset{
	Lowercase, Uppercase, Numbers, Symbols,
	Latin1, LatinExtendedA, LatinExtendedB, IPAExtensions,
}

// IsDefault returns true if the charset c is represented in DefaultCharsets.
// Deprecated; will be removed in v3.
func IsDefault(c Charset) bool {
	for _, dc := range DefaultCharsets {
		if c.String() == dc.String() {
			return true
		}
	}

	return false
}