Giter VIP home page Giter VIP logo

Comments (2)

tanishiking avatar tanishiking commented on May 28, 2024

Thank you for reporting! Right, we should count as 1 for the unpaired surrogate point.

Unpaired surrogates within the text range given by index and codePointOffset count as one code point each.
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html#offsetByCodePoints(int,int)

❯ cat test.scala
@main def main = {
    println("\uD800".offsetByCodePoints(0, 1))
}

❯ scala-cli test.scala
Compiling project (Scala 3.3.0, JVM)
Compiled project (Scala 3.3.0, JVM)
1

❯ scala-cli test.scala --native
Compiling project (Scala 3.3.0, Scala Native)
Compiled project (Scala 3.3.0, Scala Native)
[info] Linking (756 ms)
[info] Discovered 680 classes and 3771 methods
[info] Optimizing (debug mode) (889 ms)
[info] Generating intermediate code (856 ms)
[info] Produced 8 files
[info] Compiling to native code (1649 ms)
[info] Total (4257 ms)
java.lang.ArrayIndexOutOfBoundsException: 1
        at java.lang.StackTrace$.currentStackTrace$$anonfun$1(Unknown Source)
        at java.lang.StackTrace$$$Lambda$2.applyVoid(Unknown Source)
        at scala.runtime.function.JProcedure1.apply(Unknown Source)
        at scala.scalanative.unsafe.Zone$.apply(Unknown Source)
        at java.lang.StackTrace$.currentStackTrace(Unknown Source)
        at java.lang.Throwable.fillInStackTrace(Unknown Source)
        at scala.scalanative.runtime.package$.throwOutOfBounds(Unknown Source)
        at java.lang.Character$.offsetByCodePoints(Unknown Source)
        at java.lang.String.offsetByCodePoints(Unknown Source)
        at test$package$.main(Unknown Source)
        at main.main(Unknown Source)
        at <none>.main(Unknown Source)

from scala-native.

tanishiking avatar tanishiking commented on May 28, 2024

It seems like we have an error when the part of string ends with the unpaired surrogate

if (isHighSurrogate(seq(i))) {
val next = i + 1
if (next <= end && isLowSurrogate(seq(next))) {
i += 1
}

❯ cat test.scala
// no problem
@main def main = {
    println("\uD800a".offsetByCodePoints(0, 1))
}

❯ scala-cli test.scala --native
1

and low-surrogate doesn't have the problem

@main def main = {
    println("\uDC00".offsetByCodePoints(0, 1))
}

❯ scala-cli test.scala --native
1

from scala-native.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.