Find `PARTITIONED BY` keyword position, skipping string literals and comments.
(sql: &str)
| 1361 | |
| 1362 | /// Find `PARTITIONED BY` keyword position, skipping string literals and comments. |
| 1363 | fn find_partitioned_by(sql: &str) -> Option<(usize, usize)> { |
| 1364 | let bytes = sql.as_bytes(); |
| 1365 | let len = bytes.len(); |
| 1366 | let mut i = 0; |
| 1367 | while i < len { |
| 1368 | match bytes[i] { |
| 1369 | b'\'' => { |
| 1370 | i += 1; |
| 1371 | while i < len { |
| 1372 | if bytes[i] == b'\'' { |
| 1373 | i += 1; |
| 1374 | if i < len && bytes[i] == b'\'' { |
| 1375 | i += 1; |
| 1376 | } else { |
| 1377 | break; |
| 1378 | } |
| 1379 | } else { |
| 1380 | i += 1; |
| 1381 | } |
| 1382 | } |
| 1383 | } |
| 1384 | b'-' if i + 1 < len && bytes[i + 1] == b'-' => { |
| 1385 | i += 2; |
| 1386 | while i < len && bytes[i] != b'\n' { |
| 1387 | i += 1; |
| 1388 | } |
| 1389 | } |
| 1390 | b'/' if i + 1 < len && bytes[i + 1] == b'*' => { |
| 1391 | i += 2; |
| 1392 | while i + 1 < len { |
| 1393 | if bytes[i] == b'*' && bytes[i + 1] == b'/' { |
| 1394 | i += 2; |
| 1395 | break; |
| 1396 | } |
| 1397 | i += 1; |
| 1398 | } |
| 1399 | } |
| 1400 | b if b.is_ascii_alphabetic() && i + 11 <= len => { |
| 1401 | if bytes[i..i + 11].eq_ignore_ascii_case(b"PARTITIONED") { |
| 1402 | let rest = &bytes[i + 11..]; |
| 1403 | let ws = rest.iter().take_while(|b| b.is_ascii_whitespace()).count(); |
| 1404 | if ws > 0 |
| 1405 | && i + 11 + ws + 2 <= len |
| 1406 | && rest[ws..ws + 2].eq_ignore_ascii_case(b"BY") |
| 1407 | { |
| 1408 | let by_end = i + 11 + ws + 2; |
| 1409 | return Some((i, by_end)); |
| 1410 | } |
| 1411 | } |
| 1412 | i += 1; |
| 1413 | } |
| 1414 | _ => { |
| 1415 | i += 1; |
| 1416 | } |
| 1417 | } |
| 1418 | } |
| 1419 | None |
| 1420 | } |
no test coverage detected