|
76 | 76 | #[allow(clippy::match_same_arms)]
|
77 | 77 | #[allow(clippy::too_many_lines)]
|
78 | 78 | pub fn lookup(c: char, mode: Mode) -> Mapping {
|
79 |
| - let char_bytes = u32::from(c).to_be_bytes(); |
| 79 | + let codepoint = c as u32; |
| 80 | + let char_bytes = codepoint.to_be_bytes(); |
80 | 81 | let mid_byte = char_bytes[2];
|
81 | 82 | let high_bytes = u16::from_be_bytes([char_bytes[0], char_bytes[1]]);
|
82 | 83 | match (high_bytes, mid_byte) {
|
83 | 84 | (0x0000, 0x00) => match c {
|
84 | 85 | // Turkic mapping in ASCII range
|
85 | 86 | // 0049; T; 0131; # LATIN CAPITAL LETTER I
|
86 |
| - '\\u{0049}' if mode == Mode::Turkic => Mapping::Single(0x0131), |
87 |
| - c if c.is_ascii() => Mapping::Single(c.to_ascii_lowercase().into()), |
| 87 | + '\\u{0049}' if matches!(mode, Mode::Turkic) => Mapping::Single(0x0131), |
| 88 | + c if c.is_ascii() => Mapping::Single(c.to_ascii_lowercase() as u32), |
88 | 89 | AUTOGEN
|
89 | 90 |
|
90 | 91 | last_high_bytes = 0x00
|
|
102 | 103 | high_bytes = ((start >> 16) & 0xFFFF)
|
103 | 104 |
|
104 | 105 | if high_bytes != last_high_bytes || mid_byte != last_mid_byte
|
105 |
| - rs.puts ' _ => Mapping::Single(c.into()),' |
| 106 | + rs.puts ' _ => Mapping::Single(codepoint),' |
106 | 107 | rs.puts ' },'
|
107 | 108 | rs.puts " (0x#{high_bytes.to_s(16).upcase.rjust(4, '0')}, 0x#{mid_byte.to_s(16).upcase.rjust(2, '0')}) => match c {"
|
108 | 109 | last_high_bytes = high_bytes
|
|
116 | 117 | full = mapping[:full].map { |ch| ch.to_s(16).upcase.rjust(4, '0') }
|
117 | 118 | case full.length
|
118 | 119 | when 1
|
119 |
| - rs.puts " '\\u{#{char}}' if mode == Mode::Full => Mapping::Single(0x#{full[0]})," |
| 120 | + rs.puts " '\\u{#{char}}' if matches!(mode, Mode::Full) => Mapping::Single(0x#{full[0]})," |
120 | 121 | when 2
|
121 |
| - rs.puts " '\\u{#{char}}' if mode == Mode::Full => Mapping::Double(0x#{full[0]}, 0x#{full[1]})," |
| 122 | + rs.puts " '\\u{#{char}}' if matches!(mode, Mode::Full) => Mapping::Double(0x#{full[0]}, 0x#{full[1]})," |
122 | 123 | when 3
|
123 |
| - rs.puts " '\\u{#{char}}' if mode == Mode::Full => Mapping::Triple(0x#{full[0]}, 0x#{full[1]}}, 0x#{full[2]})," |
| 124 | + rs.puts " '\\u{#{char}}' if matches!(mode, Mode::Full) => Mapping::Triple(0x#{full[0]}, 0x#{full[1]}}, 0x#{full[2]})," |
124 | 125 | else
|
125 | 126 | raise "Unsupported mapping length: #{map.inspect} for code #{code}"
|
126 | 127 | end
|
127 | 128 | turkic = mapping[:turkic].map { |ch| ch.to_s(16).upcase.rjust(4, '0') }
|
128 | 129 | case turkic.length
|
129 | 130 | when 1
|
130 |
| - rs.puts " '\\u{#{char}}' if mode == Mode::Turkic => Mapping::Single(0x#{turkic[0]})," |
| 131 | + rs.puts " '\\u{#{char}}' if matches!(mode, Mode::Turkic) => Mapping::Single(0x#{turkic[0]})," |
131 | 132 | when 2
|
132 |
| - rs.puts " '\\u{#{char}}' if mode == Mode::Turkic => Mapping::Double(0x#{turkic[0]}, 0x#{turkic[1]})," |
| 133 | + rs.puts " '\\u{#{char}}' if matches!(mode, Mode::Turkic) => Mapping::Double(0x#{turkic[0]}, 0x#{turkic[1]})," |
133 | 134 | when 3
|
134 |
| - rs.puts " '\\u{#{char}}' if mode == Mode::Turkic => Mapping::Triple(0x#{turkic[0]}, 0x#{turkic[1]}, 0x#{turkic[2]})," |
| 135 | + rs.puts " '\\u{#{char}}' if matches!(mode, Mode::Turkic) => Mapping::Triple(0x#{turkic[0]}, 0x#{turkic[1]}, 0x#{turkic[2]})," |
135 | 136 | else
|
136 | 137 | raise "Unsupported mapping length: #{map.inspect} for code #{code}"
|
137 | 138 | end
|
|
150 | 151 | rs.puts " '\\u{#{base}}' => Mapping::Single(0x#{full[0]}),"
|
151 | 152 | elsif full.length == 1
|
152 | 153 | finish = last.to_s(16).upcase.rjust(4, '0')
|
153 |
| - rs.puts " '\\u{#{base}}'..='\\u{#{finish}}' => Mapping::Single(u32::from(c).wrapping_#{op}(0x#{op_offset}))," |
| 154 | + rs.puts " '\\u{#{base}}'..='\\u{#{finish}}' => Mapping::Single(codepoint.wrapping_#{op}(0x#{op_offset}))," |
154 | 155 | elsif (last - start).zero? && full.length == 2
|
155 | 156 | rs.puts " '\\u{#{base}}' => Mapping::Double(0x#{full[0]}, 0x#{full[1]}),"
|
156 | 157 | elsif full.length == 2
|
157 | 158 | finish = last.to_s(16).upcase.rjust(4, '0')
|
158 |
| - rs.puts " '\\u{#{base}}'..='\\u{#{finish}}' => Mapping::Double(u32::from(c).wrapping_#{op}(0x#{op_offset}), 0x#{full[1]})," |
| 159 | + rs.puts " '\\u{#{base}}'..='\\u{#{finish}}' => Mapping::Double(codepoint.wrapping_#{op}(0x#{op_offset}), 0x#{full[1]})," |
159 | 160 | elsif (last - start).zero? && full.length == 3
|
160 | 161 | rs.puts " '\\u{#{base}}' => Mapping::Triple(0x#{full[0]}, 0x#{full[1]}, 0x#{full[2]}),"
|
161 | 162 | elsif full.length == 3
|
162 | 163 | finish = last.to_s(16).upcase.rjust(4, '0')
|
163 |
| - rs.puts " '\\u{#{base}}'..='\\u{#{finish}}' => Mapping::Triple(u32::from(c).wrapping_#{op}(0x#{op_offset}), 0x#{full[1]}, 0x#{full[2]})," |
| 164 | + rs.puts " '\\u{#{base}}'..='\\u{#{finish}}' => Mapping::Triple(codepoint.wrapping_#{op}(0x#{op_offset}), 0x#{full[1]}, 0x#{full[2]})," |
164 | 165 | end
|
165 | 166 | elsif mapping.key?(:full)
|
166 | 167 | char = start.to_s(16).upcase.rjust(4, '0')
|
|
180 | 181 | end
|
181 | 182 | end
|
182 | 183 |
|
183 |
| -rs.puts ' _ => Mapping::Single(c.into()),' |
| 184 | +rs.puts ' _ => Mapping::Single(codepoint),' |
184 | 185 | rs.puts ' },'
|
185 |
| -rs.puts ' _ => Mapping::Single(c.into()),' |
| 186 | +rs.puts ' _ => Mapping::Single(codepoint),' |
186 | 187 |
|
187 | 188 | rs.puts ' }'
|
188 | 189 | rs.puts '}'
|
|
0 commit comments