-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
84 lines (76 loc) · 1.83 KB
/
helper.go
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
75
76
77
78
79
80
81
82
83
84
package main
import (
"path/filepath"
"strings"
)
const maxASCIIIndex = 127
// containsNonASCII returns true if a string contains non-ASCII characters.
func containsNonASCII(str string) bool {
for _, char := range str {
if char > maxASCIIIndex {
return true
}
}
return false
}
// removeNonASCII replaces non-ASCII characters in a string with an ASCII equivalent.
func removeNonASCII(str string) string {
// Create a hashmap to store non-ASCII characters as keys and ASCII characters as values
nonASCIItoASCII := map[rune]rune{
'á': 'a',
'é': 'e',
'è': 'e',
'ê': 'e',
'í': 'i',
'ó': 'o',
'ø': 'o',
'ú': 'u',
'ñ': 'n',
'Á': 'A',
'É': 'E',
'È': 'E',
'Ê': 'E',
'Í': 'I',
'Ó': 'O',
'Ø': 'O',
'Ú': 'U',
'Ñ': 'N',
// Add more mappings as needed
}
// Replace non-ASCII characters with their ASCII equivalents
var result strings.Builder
for _, char := range str {
asciiChar, isCharMappedToASCII := nonASCIItoASCII[char]
switch {
case isCharMappedToASCII:
result.WriteRune(asciiChar)
case char > maxASCIIIndex:
// Don't emit char
default:
result.WriteRune(char)
}
}
return result.String()
}
// isUntranscodedMusicFile checks if the path is a source music file of
// common types that need to be converted to MP3 (but are not themselves MP3),
// based on its extension.
func isUntranscodedMusicFile(path string) bool {
extensions := []string{".aif", ".wav", ".m4a"}
return stringInSlice(filepath.Ext(path), extensions)
}
// stringInSlice returns bool if a string is found in any of a list of other strings.
//
// Example usage:
//
// if stringInSlice("Stevia", []string{"Stevie Nicks", "Stevie Wonder", "Steve Nash", "Steve McQueen"}) {
//
// }
func stringInSlice(str string, list []string) bool {
for _, v := range list {
if v == str {
return true
}
}
return false
}