Re: Detect wrong characters
by Corion (Patriarch) on Dec 02, 2024 at 14:26 UTC
|
According to this random character table, ISO-8859 defines a character for every byte value. So there are no characters not defined in this charset.
Maybe you can show us a more concrete example of what you have, what you expect and the code you wrote already. Please also tell us how your code fails to produce the result you expect.
| [reply] |
|
|
If there are strings from a foreign language in my text, they could conflict with my encoding "ISO-8859-1". Let me give you 2 examples:
- You have got a sentence which contains the Greek equivalent of the German term "Steuerbescheid": εκκαθαριστικό φορολογίας
- Your text might contain a letter that looks like a small "o", but the author used the small Greek omicron "ο" which looks the same, but is technically different.
Unfortunately, I haven't yet any code to show to you, as I don't know how to do this.
| [reply] |
|
|
Probably someone entered text encoded in utf8 or another foreign encoding in the fields. If you can read them, it means your editor is configured to do so. Set it to Latin 1 to spot the difference.
You have to identify which encoding was used and hope to code a heuristic to correct those. Like the special start bytes of Utf8 wide characters.
You will end up needing to check and trust the heuristic, or manually correct everything.
As far as I see does ISO Latin 1 not include Greek letters. Hence you have to translate them to HTML entities.
(I suppose that's allowed in the document's definition)
| [reply] |
Re: Detect wrong characters
by ikegami (Patriarch) on Dec 02, 2024 at 15:19 UTC
|
When the encoding is set to iso-8859-1, the file can't possibly contain characters that aren't part of the iso-8859-1 character set (unless they are encoded using entities such as ਩).
Are you asking if it's possible to detect if the wrong encoding is specified? There's no way to detect whether it's invalid or not without using heuristics. For example, if byte sequence in the XML would form a word in iso-8859-7 but not in iso-8859-1, it could suggest that the wrong encoding was specified.
| [reply] [d/l] |
|
|
But if you write characters that violate the encoding, they might look rather weird if your application is tuned to that encoding, but nevertheless be saved. Or am I wrong?
And an XML file with encoding='ISO-8859-1" should not contains characters in another encoding. The ideal solution to use UTF-8 unfortunately doesn't work in my environment - in the midst of a chain of production ;)
| [reply] |
|
|
if you write characters that violate the encoding
You can't write character that violate the encoding. It's simply not possible. But you could encode characters using the wrong encoding, and incorrectly write that to the XML document. This would produce a document that contains different characters than the intended characters. Detecting this would require heuristics, as per my original post.
And an XML file with encoding='ISO-8859-1" should not contains characters in another encoding.
No. An XML file with encoding='ISO-8859-1" can not contain characters in another encoding (unless encoded using entities such as ਩). It's simply not possible.
| [reply] [d/l] |
Re: Detect wrong characters
by bliako (Abbot) on Dec 02, 2024 at 15:16 UTC
|
I had similar woes. The way to identify encodings is not guaranteed unless a (knowledgable) human is employed. Corion proved that above. But check the comment there how firefox and chrome tackle this issue.
| [reply] |