MCPcopy Index your code
hub / github.com/FloatTech/ZeroBot-Plugin / chineseNum2Int

Function chineseNum2Int

plugin/manager/timer/parse.go:125–152  ·  view source on GitHub ↗

chineseNum2Int 汉字数字转int,仅支持-10~99,最多两位数,其中"每"解释为-1,"每二"为-2,以此类推

(rs []rune)

Source from the content-addressed store, hash-verified

123
124// chineseNum2Int 汉字数字转int,仅支持-10~99,最多两位数,其中"每"解释为-1,"每二"为-2,以此类推
125func chineseNum2Int(rs []rune) int {
126 r := -1
127 l := len(rs)
128 mai := rune('每')
129 if unicode.IsDigit(rs[0]) { // 默认可能存在的第二位也为int
130 r, _ = strconv.Atoi(string(rs))
131 } else {
132 switch {
133 case rs[0] == mai:
134 if l == 2 {
135 r = -chineseChar2Int(rs[1])
136 }
137 case l == 1:
138 r = chineseChar2Int(rs[0])
139 default:
140 ten := chineseChar2Int(rs[0])
141 if ten != 10 {
142 ten *= 10
143 }
144 ge := chineseChar2Int(rs[1])
145 if ge == 10 {
146 ge = 0
147 }
148 r = ten + ge
149 }
150 }
151 return r
152}
153
154// chineseChar2Int 处理单个字符的映射0~10
155func chineseChar2Int(c rune) int {

Callers 1

GetFilledTimerFunction · 0.85

Calls 1

chineseChar2IntFunction · 0.85

Tested by

no test coverage detected