MCPcopy Index your code
hub / github.com/python/cpython / _get_literal_prefix

Function _get_literal_prefix

Lib/re/_compiler.py:450–479  ·  view source on GitHub ↗
(pattern, flags)

Source from the content-addressed store, hash-verified

448 return _sre.ascii_iscased
449
450def _get_literal_prefix(pattern, flags):
451 # look for literal prefix
452 prefix = []
453 prefixappend = prefix.append
454 prefix_skip = None
455 iscased = _get_iscased(flags)
456 for op, av in pattern.data:
457 if op is LITERAL:
458 if iscased and iscased(av):
459 break
460 prefixappend(av)
461 elif op is SUBPATTERN:
462 group, add_flags, del_flags, p = av
463 flags1 = _combine_flags(flags, add_flags, del_flags)
464 if flags1 & SRE_FLAG_IGNORECASE and flags1 & SRE_FLAG_LOCALE:
465 break
466 prefix1, prefix_skip1, got_all = _get_literal_prefix(p, flags1)
467 if prefix_skip is None:
468 if group is not None:
469 prefix_skip = len(prefix)
470 elif prefix_skip1 is not None:
471 prefix_skip = len(prefix) + prefix_skip1
472 prefix.extend(prefix1)
473 if not got_all:
474 break
475 else:
476 break
477 else:
478 return prefix, prefix_skip, True
479 return prefix, prefix_skip, False
480
481def _get_charset_prefix(pattern, flags):
482 while True:

Callers 1

_compile_infoFunction · 0.85

Calls 3

_get_iscasedFunction · 0.85
_combine_flagsFunction · 0.85
extendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…