From 0dd10899a06f5b19842de33c5059f6b943c66c07 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 29 Apr 2024 19:15:08 +0200 Subject: [PATCH] classlib: implement CharSequence chars and codePoints --- .../classlib/java/lang/TCharSequence.java | 12 ++++ .../org/teavm/classlib/java/lang/TString.java | 7 +++ .../intimpl/TCharSequenceCharsStream.java | 48 +++++++++++++++ .../TCharSequenceCodePointsStream.java | 60 +++++++++++++++++++ .../stream/intimpl/TStringCharsStream.java | 3 +- .../intimpl/TStringCodePointsStream.java | 60 +++++++++++++++++++ .../classlib/java/lang/StringBuilderTest.java | 19 ++++++ .../teavm/classlib/java/lang/StringTest.java | 12 ++++ 8 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 classlib/src/main/java/org/teavm/classlib/java/util/stream/intimpl/TCharSequenceCharsStream.java create mode 100644 classlib/src/main/java/org/teavm/classlib/java/util/stream/intimpl/TCharSequenceCodePointsStream.java create mode 100644 classlib/src/main/java/org/teavm/classlib/java/util/stream/intimpl/TStringCodePointsStream.java diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TCharSequence.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TCharSequence.java index 11f4c705f..2e24aee75 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TCharSequence.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TCharSequence.java @@ -15,6 +15,10 @@ */ package org.teavm.classlib.java.lang; +import org.teavm.classlib.java.util.stream.TIntStream; +import org.teavm.classlib.java.util.stream.intimpl.TCharSequenceCharsStream; +import org.teavm.classlib.java.util.stream.intimpl.TCharSequenceCodePointsStream; + public interface TCharSequence { int length(); @@ -24,6 +28,14 @@ public interface TCharSequence { TCharSequence subSequence(int start, int end); + default TIntStream chars() { + return new TCharSequenceCharsStream(this); + } + + default TIntStream codePoints() { + return new TCharSequenceCodePointsStream(this); + } + @Override String toString(); } diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TString.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TString.java index 7e368cb20..6488165fb 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TString.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TString.java @@ -33,6 +33,7 @@ import org.teavm.classlib.java.util.TLocale; import org.teavm.classlib.java.util.regex.TPattern; import org.teavm.classlib.java.util.stream.TIntStream; import org.teavm.classlib.java.util.stream.intimpl.TStringCharsStream; +import org.teavm.classlib.java.util.stream.intimpl.TStringCodePointsStream; import org.teavm.dependency.PluggableDependency; import org.teavm.interop.NoSideEffects; @@ -589,10 +590,16 @@ public class TString extends TObject implements TSerializable, TComparable