Repository: apple/pkl
File: pkl-core/src/main/java/org/pkl/core/stdlib/base/StringNodes.java (Java)

Code before:
    @TruffleBoundary
    @Specialization
    protected VmList eval(String self, String separator) {
      var parts = self.split(Pattern.quote(separator));
      return VmList.create(parts);
    }

    @TruffleBoundary
    @Specialization
    protected VmList eval(String self, VmRegex separator) {
      return VmList.create(separator.getPattern().split(self));
    }
  }

  public abstract static class capitalize extends ExternalMethod0Node {
    @TruffleBoundary
    @Specialization
    protected String eval(String self) {
      if (self.isEmpty()) return "";

      var firstChar = self.codePointAt(0);
      return Character.toString(Character.toTitleCase(firstChar))
          + self.substring(Character.isBmpCodePoint(firstChar) ? 1 : 2);
    }
  }

  public abstract static class decapitalize extends ExternalMethod0Node {
    @TruffleBoundary
    @Specialization
    protected String eval(String self) {
      if (self.isEmpty()) return "";

      var firstChar = self.codePointAt(0);
      return Character.toString(firstChar).toLowerCase(Locale.ROOT)
          + self.substring(Character.isBmpCodePoint(firstChar) ? 1 : 2);
    }
  }

  public abstract static class toInt extends ExternalMethod0Node {
    @TruffleBoundary
    @Specialization
    protected long eval(String self) {
      try {
        return Long.parseLong(removeUnderlinesFromNumber(self));
      } catch (NumberFormatException e) {
        throw exceptionBuilder()
            .evalError("cannotParseStringAs", "Int")
            .withProgramValue("String", self)
            .build();
      }
    }

Review comment (refactor):
It took me far too long to find this, but considering my comment on your snippet test expectation, I _believe_ this should be...
```suggestion
      return VmList.create(separator.getPattern().split(self, (int) limit));
```
I don't mind either way, but the difference would have been easier to spot if this was written in the same form as `eval(String,String,long)`;
```
var parts = separator.getPattern().split(self, (int) limit);
return VmList.create(parts);
```

Code after:
    @TruffleBoundary
    @Specialization
    protected VmList eval(String self, String separator) {
      var parts = self.split(Pattern.quote(separator));
      return VmList.create(parts);
    }

    @TruffleBoundary
    @Specialization
    protected VmList eval(String self, VmRegex separator) {
      return VmList.create(separator.getPattern().split(self));
    }
  }

  public abstract static class splitLimit extends ExternalMethod2Node {
    @TruffleBoundary
    @Specialization
    protected VmList eval(String self, String separator, long limit) {
      var parts = self.split(Pattern.quote(separator), (int) limit);
      return VmList.create(parts);
    }

    @TruffleBoundary
    @Specialization
    protected VmList eval(String self, VmRegex separator, long limit) {
      var parts = separator.getPattern().split(self, (int) limit);
      return VmList.create(parts);
    }
  }

  public abstract static class capitalize extends ExternalMethod0Node {
    @TruffleBoundary
    @Specialization
    protected String eval(String self) {
      if (self.isEmpty()) return "";

      var firstChar = self.codePointAt(0);
      return Character.toString(Character.toTitleCase(firstChar))
          + self.substring(Character.isBmpCodePoint(firstChar) ? 1 : 2);
    }
  }

  public abstract static class decapitalize extends ExternalMethod0Node {
    @TruffleBoundary
    @Specialization
    protected String eval(String self) {
      if (self.isEmpty()) return "";

      var firstChar = self.codePointAt(0);
      return Character.toString(firstChar).toLowerCase(Locale.ROOT)
          + self.substring(Character.isBmpCodePoint(firstChar) ? 1 : 2);