HTML issue
Eric Chatonet
eric.chatonet at sosmartsoftware.com
Thu Nov 17 16:55:24 EST 2005
Hi Alex,
Very interesting thoughts :-)
Above all about search and replace strings with the same length (I
remember a thread about that lately).
But there is still a problem of security:
It's the user who specifies the string and he can specify fa (then he
will be a musician :-) or nt (then will be an old Win man :-)
Another trick should be to allow only patterns with 3 chars or
more... to ensure your solution ;-)
Best Regards from Paris,
Eric Chatonet.
Le 17 nov. 05 à 22:19, Alex Tweedly a écrit :
> Eric Chatonet wrote:
>
>> Hi all,
>>
>> I want to change the colour of a string in some styled text.
>> As the string may be any string like "font", "size", etc. that
>> appear in html tags,
>> I use the following code that works but I'm not satisfied with it...
>> Any more elegant solution?
>> Thanks.
>>
> Some thoughts - to use on their own, or in combination - or not at
> all, since they are far short of "elegance"
> In fact, you might feel these sacrifice elegance for speed - that's
> a habit of mine :-)
>
> Basically what you are doing is
> a set of "replace"s to hide html tags
> the real replace
> a set of "replace"s to restore the html tags.
>
> Thought 1. Simplify the 3rd set of replaces, by doing
>
> put numToChar(3) into c3
> replace "<font" with "<fo" & c3 & "nt" in tText
> replace "face=" with "fa"&c3&"ce=" in tText
> etc. -- i.e. put a single c3 character into the middle of each
> html tag
> then do the real replace, and then
> replace c3 with empty in tText
>
> Thought 2. There is a speed optimization to replace a sub-string
> by another sub-string *of the same length*.
> AND note that the tags to be replaced all contain either "e" or
> "o", so
>
> put numToChar(3) into c3 -- to replace o
> put numToChar(8) into c8 -- to replace e
> replace "<font" with "<f" & c3 & "nt" in tText
> replace "face=" with "fac" & c8 & "=" in tText
> replace "size=" with "siz" & c8 & "=" in tText
> etc.
> then do the real replace, and then
> replace c3 with "o" in tText
> replace c8 with "e" in tText
>
>
> Thought 3. Use a list of replacements, in a script local variable.
>
> local lReplacements = \
> "<font" & comma & "<f" & c3 & "nt" & cr \
> "face=" & comma & "fac" & c8 & "=" & cr \
> "size=" & comma &"siz" & c8 & "=" & cr \
> "color=" with "c" & c3 & "lor=" & cr \
> "</font>" with "</f" & c3 & "nt>"
>
> Then do
> repeat for each line L in lReplacements
> replace item 1 of L with item 2 of L in tText
> end repeat
> do the real replace
> replace c3 with "o" in tText
> replace c8 with "e" in tText
>
>
> --
> Alex Tweedly http://www.tweedly.net
----------------------------------------------------------------
So Smart Software
Free plugins and tutorials on my website
----------------------------------------------------------------
Web site http://www.sosmartsoftware.com/
Email eric.chatonet at sosmartsoftware.com/
----------------------------------------------------------------
More information about the use-livecode
mailing list