-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
classlib: implement CharSequence chars and codePoints
- Loading branch information
1 parent
e48dfb2
commit 0dd1089
Showing
8 changed files
with
219 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...b/src/main/java/org/teavm/classlib/java/util/stream/intimpl/TCharSequenceCharsStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2023 JFronny. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.teavm.classlib.java.util.stream.intimpl; | ||
|
||
import java.util.function.IntPredicate; | ||
import org.teavm.classlib.java.lang.TCharSequence; | ||
|
||
public class TCharSequenceCharsStream extends TSimpleIntStreamImpl { | ||
private final TCharSequence csq; | ||
private int index; | ||
|
||
public TCharSequenceCharsStream(TCharSequence csq) { | ||
this.csq = csq; | ||
} | ||
|
||
@Override | ||
public boolean next(IntPredicate consumer) { | ||
while (index < csq.length()) { | ||
if (!consumer.test(csq.charAt(index++))) { | ||
break; | ||
} | ||
} | ||
return index < csq.length(); | ||
} | ||
|
||
@Override | ||
protected int estimateSize() { | ||
return csq.length(); | ||
} | ||
|
||
@Override | ||
public long count() { | ||
return csq.length(); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
.../main/java/org/teavm/classlib/java/util/stream/intimpl/TCharSequenceCodePointsStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2024 Alexey Andreev. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.teavm.classlib.java.util.stream.intimpl; | ||
|
||
import java.util.function.IntPredicate; | ||
import org.teavm.classlib.java.lang.TCharSequence; | ||
import org.teavm.classlib.java.lang.TCharacter; | ||
|
||
public class TCharSequenceCodePointsStream extends TSimpleIntStreamImpl { | ||
private final TCharSequence csq; | ||
private int index; | ||
|
||
public TCharSequenceCodePointsStream(TCharSequence csq) { | ||
this.csq = csq; | ||
} | ||
|
||
@Override | ||
public boolean next(IntPredicate consumer) { | ||
while (index < csq.length()) { | ||
var hi = csq.charAt(index++); | ||
if (TCharacter.isHighSurrogate(hi) && index < csq.length()) { | ||
var lo = csq.charAt(index); | ||
if (TCharacter.isLowSurrogate(lo)) { | ||
++index; | ||
if (!consumer.test(TCharacter.toCodePoint(hi, lo))) { | ||
break; | ||
} | ||
continue; | ||
} | ||
} | ||
if (!consumer.test(hi)) { | ||
break; | ||
} | ||
} | ||
return index < csq.length(); | ||
} | ||
|
||
@Override | ||
protected int estimateSize() { | ||
return csq.length(); | ||
} | ||
|
||
@Override | ||
public long count() { | ||
return csq.length(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...ib/src/main/java/org/teavm/classlib/java/util/stream/intimpl/TStringCodePointsStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2024 Alexey Andreev. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.teavm.classlib.java.util.stream.intimpl; | ||
|
||
import java.util.function.IntPredicate; | ||
import org.teavm.classlib.java.lang.TCharacter; | ||
import org.teavm.classlib.java.lang.TString; | ||
|
||
public class TStringCodePointsStream extends TSimpleIntStreamImpl { | ||
private final TString string; | ||
private int index; | ||
|
||
public TStringCodePointsStream(TString string) { | ||
this.string = string; | ||
} | ||
|
||
@Override | ||
public boolean next(IntPredicate consumer) { | ||
while (index < string.length()) { | ||
var hi = string.charAt(index++); | ||
if (TCharacter.isHighSurrogate(hi) && index < string.length()) { | ||
var lo = string.charAt(index); | ||
if (TCharacter.isLowSurrogate(lo)) { | ||
++index; | ||
if (!consumer.test(TCharacter.toCodePoint(hi, lo))) { | ||
break; | ||
} | ||
continue; | ||
} | ||
} | ||
if (!consumer.test(hi)) { | ||
break; | ||
} | ||
} | ||
return index < string.length(); | ||
} | ||
|
||
@Override | ||
protected int estimateSize() { | ||
return string.length(); | ||
} | ||
|
||
@Override | ||
public long count() { | ||
return string.length(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters