MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / _consume_until_literal

Method _consume_until_literal

examples/server/server.py:4741–4760  ·  view source on GitHub ↗
(
        cls,
        text: str,
        literal: str,
    )

Source from the content-addressed store, hash-verified

4739
4740 @classmethod
4741 def _consume_until_literal(
4742 cls,
4743 text: str,
4744 literal: str,
4745 ) -> Tuple[str, bool, str, str]:
4746 if not literal:
4747 return text, True, "", ""
4748 literal_length = len(literal)
4749 search_from = 0
4750 first_char = literal[0]
4751 while True:
4752 marker_index = text.find(first_char, search_from)
4753 if marker_index < 0:
4754 return text, False, "", ""
4755 if text.startswith(literal, marker_index):
4756 return text[:marker_index], True, text[marker_index + literal_length :], ""
4757 suffix = text[marker_index:]
4758 if literal.startswith(suffix):
4759 return text[:marker_index], False, "", suffix
4760 search_from = marker_index + 1
4761
4762 @staticmethod
4763 def _compile_iterator_pattern(pattern: str) -> Optional[Tuple[str, str]]:

Calls

no outgoing calls

Tested by

no test coverage detected