chineseNum2Int 汉字数字转int,仅支持-10~99,最多两位数,其中"每"解释为-1,"每二"为-2,以此类推
(rs []rune)
| 123 | |
| 124 | // chineseNum2Int 汉字数字转int,仅支持-10~99,最多两位数,其中"每"解释为-1,"每二"为-2,以此类推 |
| 125 | func 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 |
| 155 | func chineseChar2Int(c rune) int { |
no test coverage detected