MCPcopy Index your code
hub / github.com/bazelbuild/bazel / split

Method split

src/main/java/net/starlark/java/eval/StringModule.java:386–423  ·  view source on GitHub ↗
(
      String self, String sep, Object maxSplitO, StarlarkThread thread)

Source from the content-addressed store, hash-verified

384 }
385
386 @StarlarkMethod(
387 name = "split",
388 doc =
389 "Returns a list of all the words in the string, using <code>sep</code> as the "
390 + "separator, optionally limiting the number of splits to <code>maxsplit</code>.",
391 parameters = {
392 @Param(name = "self", doc = "This string."),
393 @Param(name = "sep", doc = "The string to split on.", named = true),
394 @Param(
395 name = "maxsplit",
396 allowedTypes = {@ParamType(type = StarlarkInt.class)},
397 defaultValue = "unbound",
398 doc = "The maximum number of splits.",
399 named = true)
400 },
401 useStarlarkThread = true)
402 public StarlarkList<String> split(
403 String self, String sep, Object maxSplitO, StarlarkThread thread) throws EvalException {
404 if (sep.isEmpty()) {
405 throw Starlark.errorf("Empty separator");
406 }
407 int maxSplit = Integer.MAX_VALUE;
408 if (maxSplitO != Starlark.UNBOUND) {
409 maxSplit = Starlark.toInt(maxSplitO, "maxsplit");
410 }
411 StarlarkList<String> res = StarlarkList.newList(thread.mutability());
412 int start = 0;
413 while (true) {
414 int end = self.indexOf(sep, start);
415 if (end < 0 || maxSplit-- == 0) {
416 res.addElement(self.substring(start));
417 break;
418 }
419 res.addElement(self.substring(start, end));
420 start = end + sep.length();
421 }
422 return res;
423 }
424
425 @StarlarkMethod(
426 name = "rsplit",

Callers 15

MockPythonLinesClass · 0.80
_print_diffFunction · 0.80
mainFunction · 0.80
testPrintTwoFilesMethod · 0.80
testPrintOneFileMethod · 0.80
testPrintBrdaLinesMethod · 0.80
testPrintBaLinesMethod · 0.80
parseFNLineMethod · 0.80
parseFNDALineMethod · 0.80
parseBALineMethod · 0.80
parseBRDALineMethod · 0.80
parseDALineMethod · 0.80

Calls 8

errorfMethod · 0.95
toIntMethod · 0.95
newListMethod · 0.95
indexOfMethod · 0.80
mutabilityMethod · 0.65
isEmptyMethod · 0.45
addElementMethod · 0.45
lengthMethod · 0.45

Tested by 15

testPrintTwoFilesMethod · 0.64
testPrintOneFileMethod · 0.64
testPrintBrdaLinesMethod · 0.64
testPrintBaLinesMethod · 0.64
parseFNLineMethod · 0.64
parseFNDALineMethod · 0.64
parseBALineMethod · 0.64
parseBRDALineMethod · 0.64
parseDALineMethod · 0.64
getMapFromFileMethod · 0.64
parseFunctionMethod · 0.64
parseLCountMethod · 0.64