Hello [EMAIL PROTECTED]!

On 04-Feb-00, you wrote:

 b> So I need a mapper function. Maybe two (or three). One to
 b> convert an arbitrary string of characters to a legal (and
 b> recognizable if only alpahnumerics and _ are used) filename.

Not that difficult to do.

>> string: "A *string* with /special/ characters?"
== "A *string* with /special/ characters?"
>> allowed: [#"A" - #"Z" #"a" - #"z" #"0" - #"9"] ; whatever you like
== [#"A" - #"Z" #"a" - #"z" #"0" - #"9"]
>> escape: #"-" ; the char used for escaping
== #"-"
>> allowed-chars: charset allowed
== make bitset! #{
000000000000FF03FEFFFF07FEFFFF0700000000000000000000000000000000
}
>> result: make string! 100
== ""
>> parse/all string [                                                       
[    some [                                                                   
[        copy chars some allowed-chars (insert tail result chars) |               
[        copy chars skip (insert tail result reduce [escape enbase/base chars 16])
[        ]                                                                        
[    ]
== true
>> result
== {A-20-2Astring-2A-20with-20-2Fspecial-2F-20characters-3F}

 b> The second function is to go back the other way - derive the
 b> original string from the encoding.

>> string: result
== {A-20-2Astring-2A-20with-20-2Fspecial-2F-20characters-3F}
>> result: make string! 100
== ""
>> parse/all string [                                             
[    some [                                                                   
[        copy chars some allowed-chars (insert tail result chars) |     
[        "-" copy chars 2 skip (insert tail result debase/base chars 16)
[        ]
[    ]
== true
>> result
== "A *string* with /special/ characters?"


The rest is left for exercise. ;^)

Regards,
    Gabriele.
-- 
o--------------------) .-^-. (----------------------------------o
| Gabriele Santilli / /_/_\_\ \ Amiga Group Italia --- L'Aquila |
| GIESSE on IRC     \ \-\_/-/ /  http://www.amyresource.it/AGI/ |
o--------------------) `-v-' (----------------------------------o

Reply via email to