Code Monkey home page Code Monkey logo

Comments (5)

LillianZ avatar LillianZ commented on July 17, 2024 1

Yes, I was using an old version, thanks for helping me debug!

from jcodings.

headius avatar headius commented on July 17, 2024

Assuming the encoding of these characters is the same in Ruby, the GB18030 bytes appear to match:

[] ~/projects/jruby $ ruby -e 'p "Lašas".encode("gb18030").bytes'
[76, 97, 129, 48, 148, 56, 97, 115]

I do not have an explanation for why the Java GB18030 encoder produces different output.

from jcodings.

headius avatar headius commented on July 17, 2024

Based on this online converter, we also match:

$ ruby -e 'p "Lašas".encode("gb18030").bytes.map{|i| i.to_s(16)}'
["4c", "61", "81", "30", "94", "38", "61", "73"]

image

I would say the Java encoder is in error here.

from jcodings.

headius avatar headius commented on July 17, 2024

Actually now I see that the Java getBytes matches Ruby but the manually transcoded result is not correct in your example.

I made this into a test class and I believe the latest jcodings should match. Perhaps you are running against an old version?

$ java -cp ../jcodings/target/jcodings.jar:. Blah
[76, 97, -127, 48, -108, 56, 97, 115]
[76, 97, -127, 48, -108, 56, 97, 115]
import org.jcodings.*;
import org.jcodings.transcode.*;
import java.util.*;

public class Blah {
public static void main(String[] args) throws Throwable {
EConv econv = TranscoderDB.open("UTF-8", "gb18030", 0);

byte[] src = "Lašas".getBytes("UTF-8");
byte[] dest = new byte["Lašas".getBytes("gb18030").length];

econv.convert(src, new Ptr(0), 6, dest, new Ptr(0), dest.length, 0);
System.out.println(Arrays.toString(dest)); 
// [76, 97, -127, 48, 18, 56, 97, 115]
System.out.println(Arrays.toString("Lašas".getBytes("gb18030"))); 
// [76, 97, -127, 48, -108, 56, 97, 115]
}
}

from jcodings.

headius avatar headius commented on July 17, 2024

Possibly fixed by @k77ch7 in 408210c. In any case, it's no longer broken.

from jcodings.

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.