Scala StringView-like class

Viewed 71

I want to see a class that represents a part of the existing string. Something that I can use in the following manner:

val theBigString: String = ???;
val pattern: Regex = ???;

val mySubstring = SmthLikeStringView(theBigString, /*start*/ 1000, /*end*/ 1500);
if (pattern.matches(mySubstring)) {???;} else {???;}

Of course I know about the following stuff, but it seems not to fit:

  1. val mySubstring = theBigString.substring(/*start*/ 1000, /*end*/ 1500). The resulting object has nice interface, which I like. But AFAIK, the operation implies literally copying character, which I want to avoid, I'd like to create a "lightweight" object.
  2. val mySubstring = scala.collection.StringView(theBigString).slice(/*start*/ 1000, /*end*/ 1500). This is really a View (hopefully, lightweight enough), but it has inappropriate interface. Not only it has unexpected method names (e.g. slice instead of substring), but it also doesn't implement CharSequence, so I can't operate on it via Regex and other standard ways.

Is there something that (on the one hand) is lightweight, view-like and (on the other hand) can be used together with Regex?

(AFAIK, no. But then the questions are: (1) WHY??? (2) Are there any bug reports / feature requests for that?)

0 Answers
Related