What encode() is actually?

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
User avatar
celestian
Dragon
Posts: 276
Joined: Mon May 17, 2010 3:29 pm

What encode() is actually?

Post by celestian »

So, I'm trying to write a little tool to convert character sheets/monsters from Maptools to a tool I wrote (external) and then import. Basically a character editor for the players they can do offline... however I'm running into an issue trying to figure out something.

I use "encode()" in a maptools macro on a few things that are written to the contents.xml file. The raw text looks like this.

Code: Select all


TSR+2140+-+Monstrous+Manual+%28Second+Edition%29%3A+2e

and another like this:

Code: Select all


weaponID%3D1+%26semi%3B+weaponSource%3Dnone+%26semi%3B+name%3Dattack+%231+%26semi%3B+speed%3D5+%26semi%3B+toHit%3D0+%26semi%3B+toDamage%3D0+%26semi%3B+damageSmall%3D2d4+%26semi%3B+damageMedium%3D2d4+%26semi%3B+damageLarge%3D2d4+%26semi%3B+weaponProf%3Dnone+%26semi%3B+strHit%3D0+%26semi%3B+strDamage%3D0+%26semi%3B+dexHit%3D0+%26semi%3B+racialBonus%3D0+%26semi%3B+otherBonus%3D0+%26semi%3B

I've tried a few perl modules to "decode" that. XML/HTML::Entities but neither seem to return it to a normal "string" of clean text. Any theories on how I can get around this? I really need this to be something I can do on the export/import side (not inside maptools).

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: What encode() is actually?

Post by aliasmask »

Encode will change non alphanumeric characters in to %[hex value in ascii] except for the space which is a + symbol and the semi-colon is %26semi%3B or ;.

Below is the original, encoded and decoded versions.

Code: Select all

This tab	is in the way;
This+tab%09is+in+the+way%26semi%3B
This tab	is in the way;
I recall that this is a change from earlier MT versions where %20 was used for space and something else was used for the ; which had an intentional duplication when encoding, or maybe that was with form submissions which also does encoding to pass data in a URL compatible format.

User avatar
celestian
Dragon
Posts: 276
Joined: Mon May 17, 2010 3:29 pm

Re: What encode() is actually?

Post by celestian »

aliasmask wrote:Encode will change non alphanumeric characters in to %[hex value in ascii] except for the space which is a + symbol and the semi-colon is %26semi%3B or ;.

Below is the original, encoded and decoded versions.

Code: Select all

This tab	is in the way;
This+tab%09is+in+the+way%26semi%3B
This tab	is in the way;
I recall that this is a change from earlier MT versions where %20 was used for space and something else was used for the ; which had an intentional duplication when encoding, or maybe that was with form submissions which also does encoding to pass data in a URL compatible format.
Ah, ok so here is what I ended up with.

Code: Select all

Source :weaponID%3D1+%26semi%3B+weaponSource%3Dnone+%26semi%3B+name%3Dattack+%231+%26semi%3B+speed%3D5+%26semi%3B+toHit%3D0+%26semi%3B+toDamage%3D0+%26semi%3B+damageSmall%3D2d4+%26semi%3B+damageMedium%3D2d4+%26semi%3B+damageLarge%3D2d4+%26semi%3B+weaponProf%3Dnone+%26semi%3B+strHit%3D0+%26semi%3B+strDamage%3D0+%26semi%3B+dexHit%3D0+%26semi%3B+racialBonus%3D0+%26semi%3B+otherBonus%3D0+%26semi%3B

-Source w/+ replacement for spaces: weaponID%3D1 %26semi%3B weaponSource%3Dnone %26semi%3B name%3Dattack %231 %26semi%3B speed%3D5 %26semi%3B toHit%3D0 %26semi%3B toDamage%3D0 %26semi%3B damageSmall%3D2d4 %26semi%3B damageMedium%3D2d4 %26semi%3B damageLarge%3D2d4 %26semi%3B weaponProf%3Dnone %26semi%3B strHit%3D0 %26semi%3B strDamage%3D0 %26semi%3B dexHit%3D0 %26semi%3B racialBonus%3D0 %26semi%3B otherBonus%3D0 %26semi%3B

--Source uri unescape: weaponID=1 ; weaponSource=none ; name=attack #1 ; speed=5 ; toHit=0 ; toDamage=0 ; damageSmall=2d4 ; damageMedium=2d4 ; damageLarge=2d4 ; weaponProf=none ; strHit=0 ; strDamage=0 ; dexHit=0 ; racialBonus=0 ; otherBonus=0 ;

--Source XML decode: weaponID=1 ; weaponSource=none ; name=attack #1 ; speed=5 ; toHit=0 ; toDamage=0 ; damageSmall=2d4 ; damageMedium=2d4 ; damageLarge=2d4 ; weaponProf=none ; strHit=0 ; strDamage=0 ; dexHit=0 ; racialBonus=0 ; otherBonus=0 ;

I did a string replace of + with space, then uri unescape, then a xml decode and it gets the text back in the right format.

Thanks!

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: What encode() is actually?

Post by JamzTheMan »

FYI: IF you want to live on the bleeding edge, my fork does have a sendURL(url, key, value) macro in it (as well as a requestURL(url)). It does a POST with the key/value pair, useful to package up json data and send it.

I only suggest it, as it seems you are developing something a little advance and may not care about staying with the normal builds. :D
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

Post Reply

Return to “MapTool”