MCPcopy Index your code
hub / github.com/RustPython/RustPython / charset

Function charset

crates/sre_engine/src/engine.rs:1246–1337  ·  view source on GitHub ↗
(set: &[u32], ch: u32)

Source from the content-addressed store, hash-verified

1244}
1245
1246fn charset(set: &[u32], ch: u32) -> bool {
1247 /* check if character is a member of the given set */
1248 let mut ok = true;
1249 let mut i = 0;
1250 while i < set.len() {
1251 let opcode = match SreOpcode::try_from(set[i]) {
1252 Ok(code) => code,
1253 Err(_) => {
1254 break;
1255 }
1256 };
1257 match opcode {
1258 SreOpcode::FAILURE => {
1259 return !ok;
1260 }
1261 SreOpcode::CATEGORY => {
1262 /* <CATEGORY> <code> */
1263 let cat_code = match SreCatCode::try_from(set[i + 1]) {
1264 Ok(code) => code,
1265 Err(_) => {
1266 break;
1267 }
1268 };
1269 if category(cat_code, ch) {
1270 return ok;
1271 }
1272 i += 2;
1273 }
1274 SreOpcode::CHARSET => {
1275 /* <CHARSET> <bitmap> */
1276 let set = &set[i + 1..];
1277 if ch < 256 && ((set[(ch >> 5) as usize] & (1u32 << (ch & 31))) != 0) {
1278 return ok;
1279 }
1280 i += 1 + 8;
1281 }
1282 SreOpcode::BIGCHARSET => {
1283 /* <BIGCHARSET> <block_count> <256 block_indices> <blocks> */
1284 let count = set[i + 1] as usize;
1285 if ch < 0x10000 {
1286 let set = &set[i + 2..];
1287 let block_index = ch >> 8;
1288 let (_, block_indices, _) = unsafe { set.align_to::<u8>() };
1289 let blocks = &set[64..];
1290 let block = block_indices[block_index as usize];
1291 if blocks[((block as u32 * 256 + (ch & 255)) / 32) as usize]
1292 & (1u32 << (ch & 31))
1293 != 0
1294 {
1295 return ok;
1296 }
1297 }
1298 i += 2 + 64 + count * 8;
1299 }
1300 SreOpcode::LITERAL => {
1301 /* <LITERAL> <code> */
1302 if ch == set[i + 1] {
1303 return ok;

Callers 3

search_info_charsetFunction · 0.85
charset_loc_ignoreFunction · 0.85
_countFunction · 0.85

Calls 3

categoryFunction · 0.85
upper_unicodeFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected