Giter Club home page Giter Club logo

Comments (4)

lifthrasiir avatar lifthrasiir commented on September 25, 2024

@getreu I'm confused as to what do you mean by names "not working".

My best guess is that you are trying to get encodings by encoding::label::encoding_from_whatwg_label function, which is (as the name suggests) a lookup by the names from WHATWG Encoding standard, which may have a different name from Encoding::name (which is a descriptive, arbitrary name for the inspection only). I believe the function names are clear enough that this does not need any fix.

There is no guarantee that encoding::all::encodings() will return encodings in any particular order, and I cannot see any benefit in doing so (enumerating encodings is extremely rare). If you think that this should be communicated clearly, please file a pull request with documentation added.

from rust-encoding.

getreu avatar getreu commented on September 25, 2024

Maybe I am using your API not in the right way:

a) My tools prints a list with all encodings supported:

let list = all::encodings().iter().map(|&e|format!(" {}\n",e.name())).collect::<String>();

b) Then the user choses one entry from the list and enters a string enc_name with the encoding name:

encoding_from_whatwg_label(enc_name.as_str())

These encodings are listed in a) but are not understood in b)

error mac-roman mac-roman mac-cyrillic hz big5-2003 pua-mapped-binary encoder-only-utf-8
  • As I understood the list a) is generated from a constant string in all.rs. It would be nice if this list
    is ordered alphabetically. Then I do not need to do sort it before showing it to the user.

from rust-encoding.

lifthrasiir avatar lifthrasiir commented on September 25, 2024

First, the primary WHATWG name (which encoding_from_whatwg_label accepts) is available from Encoding::whatwg_name (which can be absent, by the way, if it's not in the standard).

I think you are doing this in the wrong way, however. You should have a separate mapping from the name (whatever it is) to the encoding object, like HashMap<&'static str, EncodingRef> (or BTreeMap if you want sorted ones). The Encoding standard often changes the entire set of aliases, primarily to reflect what the current web browsers should do. Also I haven't explicitly mentioned this but it's my intention for all Encoding-supported encodings to have unique, descriptive and semi-stable [1] Encoding::names, so if you need some human-readable names you can at least use it as a unique identifier.

[1] That is, while I will keep a unique name for each encoding (so that you can, say, map "big5-2003" to the actual encoding mostly described by Big5-2003 and also to more human-readable name like "Traditional Chinese (Big5-2003)"), if the encoding implementation has changed substantially I may change the name without any explicit support for the prior encoding (which is generally hard). Or you can commit to whatever web browsers do by using a stable WHATWG name instead, but I guess this is not your use case.

from rust-encoding.

getreu avatar getreu commented on September 25, 2024

Thanks a lot for your help! I modified my supported encodings list generation code as follows:

let list = all::encodings().iter().filter_map(|&e|e.whatwg_name()).sorted();

As you can see I sorted the list myself. I agree with you that this feature is not of interest for many people.

from rust-encoding.

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.