-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_punctuation.go
68 lines (61 loc) · 1.5 KB
/
convert_punctuation.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
package kanatrans
import (
"strings"
)
// Function to convert normal punctuations to their Japanese equivalents
func ConvertToJapanesePunctuation(str string) string {
punctuationMap := map[rune]string{
',': "、",
'.': "。",
'!': "!",
'?': "?",
';': ";",
':': ":",
'-': "ー",
'~': "〜",
'\'': "’",
' ': " ",
}
// Iterate over each character in the string
var result strings.Builder
for _, char := range str {
// Check if the character is in the punctuation map
if repl, ok := punctuationMap[char]; ok {
// If yes, append its Japanese equivalent to the result
result.WriteString(repl)
} else {
// If not, append the original character to the result
result.WriteRune(char)
}
}
return result.String()
}
// Function to convert normal punctuations to their Japanese equivalents
func ConvertToJapanesePunctuationRestricted(str string) string {
punctuationMap := map[rune]string{
',': "、",
'.': "。",
'!': "、",
'?': "、",
';': "、",
':': "、",
'-': "、",
'~': "、",
'\'': "、",
' ': "",
' ': "",
}
// Iterate over each character in the string
var result strings.Builder
for _, char := range str {
// Check if the character is in the punctuation map
if repl, ok := punctuationMap[char]; ok {
// If yes, append its Japanese equivalent to the result
result.WriteString(repl)
} else {
// If not, append the original character to the result
result.WriteRune(char)
}
}
return strings.TrimSpace(result.String())
}