MCPcopy Create free account
hub / github.com/OpenSparseLLMs/MoM / escaped_split

Function escaped_split

lm-eval-harness/lm_eval/utils.py:33–53  ·  view source on GitHub ↗

Split text into a list on occurrences of the given separation character `sep_char`. The separation character may be escaped by a backslash to avoid splitting at that location. The separation character must be a string of size 1. If `maxsplit` is given, at most `maxsplit` splits are

(text, sep_char, maxsplit=-1)

Source from the content-addressed store, hash-verified

31
32
33def escaped_split(text, sep_char, maxsplit=-1):
34 """Split text into a list on occurrences of the given separation
35 character `sep_char`. The separation character may be escaped by a
36 backslash to avoid splitting at that location.
37
38 The separation character must be a string of size 1.
39
40 If `maxsplit` is given, at most `maxsplit` splits are done (thus,
41 the list will have at most `maxsplit + 1` elements). If `maxsplit`
42 is not specified or less than 0, then there is no limit on the
43 number of splits (all possible splits are made).
44 """
45 assert (
46 len(sep_char) == 1
47 ), "separation string must be a single character for escaped splitting"
48
49 if maxsplit == 0:
50 return text
51 maxsplit = max(0, maxsplit)
52
53 return re.split(r"(?<!\\)" + sep_char, text, maxsplit)
54
55
56def handle_arg_string(arg):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected