Skip to content

Commit 84a12db

Browse files
committed
Provide char-based Stepper for String as the default Stepper
Both `charStepper` and `codepointStepper` are available through separate methods. The default `stepper` methods from `MakesIntStepper` is equivalent to `charStepper`.
1 parent 3cbecca commit 84a12db

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/scala/scala/compat/java8/converterImpl/StepsString.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import Stepper._
1111
// Stepper implementation //
1212
////////////////////////////
1313

14+
private[java8] class StepperStringChar(underlying: String, _i0: Int, _iN: Int)
15+
extends StepsIntLikeIndexed[StepperStringChar](_i0, _iN) {
16+
def nextInt() = if (hasNext()) { val j = i0; i0 += 1; underlying.charAt(j) } else throwNSEE
17+
def semiclone(half: Int) = new StepperStringChar(underlying, i0, half)
18+
}
19+
1420
private[java8] class StepperStringCodePoint(underlying: String, var i0: Int, var iN: Int) extends IntStepper with EfficientSubstep {
1521
def characteristics() = NonNull
1622
def estimateSize = iN - i0
@@ -40,5 +46,7 @@ private[java8] class StepperStringCodePoint(underlying: String, var i0: Int, var
4046
/////////////////////////
4147

4248
final class RichStringCanStep(private val underlying: String) extends AnyVal with MakesIntStepper {
43-
@inline def stepper: IntStepper with EfficientSubstep = new StepperStringCodePoint(underlying, 0, underlying.length)
44-
}
49+
@inline def stepper: IntStepper with EfficientSubstep = charStepper
50+
@inline def charStepper: IntStepper with EfficientSubstep = new StepperStringChar(underlying, 0, underlying.length)
51+
@inline def codepointStepper: IntStepper with EfficientSubstep = new StepperStringCodePoint(underlying, 0, underlying.length)
52+
}

0 commit comments

Comments
 (0)