Coder Social home page Coder Social logo

Comments (5)

netvl avatar netvl commented on June 14, 2024 2

This, as you correctly identified in the comment to another issue, is likely a BOM mark which terminates the processing (BTW, there is no such encoding as DOS-UTF8, there is only just UTF-8).

Unfortunately, I don't think I want to add special handling for it in rust-xml. Ideally this should be handled on the low level by I/O streams library, and rust-xml should use properly decoded streams of characters. There is an encoding library, rust-encoding, which probably can be a basis for this, but I'm not sure if it provides proper streams and not only buffered decoding.

Another reason I don't want to add BOM handling directly into the library is that BOM mark should not be used in UTF-8 encoded files - it is not even recommended by W3C.

For now, your best bet will be dropping first character from the buffer if it is a BOM mark. However, as far as I'm aware, Rust Buffer does not provide an ability to "unread" characters (though it would be quite natural), so you will have to either to read your document into memory entirely and just slice it from the second byte onward, or you can write your own Buffer or even Reader implementation which filters out the first several bytes if they are UTF-8 BOM mark.

from xml-rs.

Pytheas01 avatar Pytheas01 commented on June 14, 2024

Hi,

have you mentioned this to the Rust developers?

Philippe

----- Mail original -----
De: "Vladimir Matveev" [email protected]
À: "netvl/rust-xml" [email protected]
Cc: "Phiroc" [email protected]
Envoyé: Mardi 2 Septembre 2014 10:25:30
Objet: Re: [rust-xml] Issue with UTF8 files (#10)

This, as you correctly identified in the comment to another issue, is likely a BOM mark which terminates the processing (BTW, there is no such encoding as DOS-UTF8, there is only just UTF-8).

Unfortunately, I don't think I want to add special handling for it in rust-xml . Ideally this should be handled on the low level by I/O streams library, and rust-xml should use properly decoded streams of characters. There is an encoding library, rust-encode , which probably can be a basis for this, but I'm not sure if it provides proper streams and not only buffered decoding.

Another reason I don't want to add BOM handling directly into the library is that BOM mark should not be used in UTF-8 encoded files - it is not even recommended by W3C.

For now, your best bet will be dropping first character from the buffer if it is a BOM mark. However, as far as I'm aware, Rust Buffer does not provide an ability to "unread" characters (though it would be quite natural), so you will have to either to read your document into memory entirely and just slice it from the second byte onward, or you can write your own Buffer or even Reader implementation which filters out the first several bytes if they are UTF-8 BOM mark.


Reply to this email directly or view it on GitHub .

from xml-rs.

netvl avatar netvl commented on June 14, 2024

@Phiroc, there was an RFC on something like that, but it was postponed. I now looked more closely into rust-encoding and it seems to me that it has facilities which would allow implementing streaming decoding, but I'm not sure if I'm able to implement such thing, at least not right now.

from xml-rs.

netvl avatar netvl commented on June 14, 2024

There is a new library, encoding_rs, which explicitly supports streaming encoding/decoding. I guess it is possible to use it for streaming encoding/decoding.

from xml-rs.

kornelski avatar kornelski commented on June 14, 2024

latin1, ASCII, and UTF-16 are now supported.

I'm not sure if there's demand for other encodings like legacy codepages or non-Unicode CJK encodings. Please open new issue if you need other encodings.

from xml-rs.

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.