function HTMLdecode() in script

If you need help on how to use the program
Post Reply
J
Posts: 224
Joined: 2008-02-17 17:09:26

function HTMLdecode() in script

Post by J »

hi,

the variable "Value" contains some text including different HTML entities.

When i´m using HTMLDecode(Value) and Value includes
then the rest of he text vanishes.

Is this an error of the function or am I doing anything wrong?
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

There seems to be a bug indeed...
but I do not know why it occurs in AMC since the function HTMLDecode used outside AMC works fine (at least the version of that function that was in previous AMC versions, but it does not seem to have changed).
So soulsnake will have to check that himself in AMC's code (I do not have AMC's code ready to compile on my PC).
J
Posts: 224
Joined: 2008-02-17 17:09:26

Post by J »

Alright, I´ll use a StringReplace for now.

thanks.
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

Hi,

This charactere "en dash" doesn't exist in table ascii iso 8859-1 that why it is replaced by empty.
Actually, all special characteres which don't exist in table ascii iso 8859-1 are replaced by empty.
But maybe we could subtitute "en dash" by 2 short dash and "em dash" by 3 short dash by default ?

Soulsnake.
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Well the bug is that all what follows the dash is deleted.
Replacing it by an empty string wouldn't be so much a problem if the rest of the variable wasn't lost.
If the function is improved, it could replace all the dash types simply by a "-".
Raoul_Volfoni
Posts: 863
Joined: 2006-08-31 23:58:18

Post by Raoul_Volfoni »

And replace by &#150 ; (–) and &#151 ; (—) ?

Code: Select all

program N_dash_M_dash;
var
value: string;
begin
value := '–'+#13#10+'N dash'+#13#10#13#10+'—'+#13#10+'M dash';
value := StringReplace(value, '–', '&#150 ;');
value := StringReplace(value, '—', '&#151 ;');
HTMLDecode(Value);
Showmessage(Value);
end.
Don't forget to remove space between &#150 and ; and between &#151 and ;
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Well in such case they could directly be included in the function.
These character do not exist in iso-8859-1, they are part of windows-1252. Maybe HTMLDecode should be extended to handle all the extra characters of that charset, as anyway the program itself uses windows-1252 on all western-european character set Windows.
J
Posts: 224
Joined: 2008-02-17 17:09:26

Post by J »

hi,

replacing one or two characters before using HTMLDecode() is not the problem, but referring to
http://en.wikipedia.org/wiki/List_of_XM ... references
there are dozens of special HTML character entities (The HTML 4 DTDs define 252 named entities).

As Antoine said, replacing the entities by an empty string wouldn't be so much a problem if the rest of the variable wasn't lost.

When parsing the HTML I have no clue what character set is used and this problem might occur with other special characters again. I expected the function working on all HTML character entities no matter which charset is used.

So at least a better "handling" (working replacement with space without cutting) or an expansion of htmDecode() for all the characters (even UTF-8 in my case) or maybe a second function doing this would be really nice to have.

thanks
J.
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Available entities do not depend on the character set used, as far as I know.
Except the few existing in windows-1252 charset that could be added, most of the missing ones can't be properly translated anyway, so either removing them or replacing them by "?" might be the best solution.
As AMC isn't unicode, handling all the unicode-ones will not be very useful, even if they could be stored in UTF-8 (for use in something else when exported by AMC then?)
J
Posts: 224
Joined: 2008-02-17 17:09:26

Post by J »

You´re right,

as far as I understood they are defined in HTML-DTD and the chars itself are partially used in the character sets.

Doing it as you suggested, including the win-1252 ones, should work then as expected for AMC. First I was confused by the "cutting off" error, which is still not the normal result, isn´t it?

If you don´t want to change the existing HTMLDecode function, I´ll then write a little script function which first does the remaining entities and then calls HTMLDecode, but that´s second best solution.
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

J wrote:First I was confused by the "cutting off" error, which is still not the normal result, isn´t it?
Indeed, it is not normal.
Extending it to windows-1252 is easy, as I think that all the missing characters used spaces that are currently empty in the iso-8859-1 set anyway.
It will give weird results on systems using a different character set (Cyrillic, etc.) but that was already the case with the symbols already handled anyway.
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

Hi,

I will extend HTMLDecode function to windows-1252 charset in next update of AMC 4.2 beta.

Soulsnake.
J
Posts: 224
Joined: 2008-02-17 17:09:26

Post by J »

very good, thanks.

just for the records:
will cause the script to an endless loop or to disappear into nirvana :hihi:
Post Reply