Comments (4)
@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.
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.
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::name
s, 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.
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)
- `encoding::Encoding` cannot be shared between threads safely HOT 1
- warning: private trait in public interface (error E0445) HOT 1
- Charset request: ArmSCII-8 HOT 4
- How to Reset a RawDecoder HOT 1
- Implement common traits for Encoding HOT 1
- include LICENSE text to subcrates HOT 3
- C1 are part of ISO-8859-1 (as far as the IANA is concerned)
- Use Cow?
- cp437 HOT 1
- Add Support For CP850
- Warnings emited when building
- Performance: Consider replacing lookup tables with match statements or binary search in single byte index
- request for no_std support
- Abandoned? HOT 2
- to GBK and to UTF8 is not right work
- Community activeness
- Use FM-index & json for DBCS decoding. HOT 3
- Need the performance data for rust-encoding. HOT 1
- Issue with multi-codepoint graphemes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-encoding.