(&self, scope: Scope<'_>)
| 179 | } |
| 180 | |
| 181 | fn exec(&self, scope: Scope<'_>) -> CallResult<()> { |
| 182 | debug_assert_eq!(1, scope.nargs()); |
| 183 | let s = scope.get_string(0); |
| 184 | |
| 185 | let mut chars = s.chars(); |
| 186 | let ch = match chars.next() { |
| 187 | Some(ch) => ch, |
| 188 | None => { |
| 189 | return Err(CallError::Syntax( |
| 190 | scope.get_pos(0), |
| 191 | format!("Input string \"{}\" must be 1-character long", s), |
| 192 | )); |
| 193 | } |
| 194 | }; |
| 195 | if chars.next().is_some() { |
| 196 | return Err(CallError::Syntax( |
| 197 | scope.get_pos(0), |
| 198 | format!("Input string \"{}\" must be 1-character long", s), |
| 199 | )); |
| 200 | } |
| 201 | let ch = if cfg!(debug_assertions) { |
| 202 | i32::try_from(ch as u32).expect("Unicode code points end at U+10FFFF") |
| 203 | } else { |
| 204 | ch as i32 |
| 205 | }; |
| 206 | |
| 207 | scope.return_integer(ch) |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | /// The `CHR` function. |
nothing calls this directly
no test coverage detected