For Programmers: Free Programming Magazines  


Home > Archive > Tcl > May 2006 > Regex question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Regex question
Robert Hicks

2006-05-24, 10:04 pm

I am woking on adding ::html::doctype to the html tcllib package. I
have a working snippet (not complete):

proc ::html::doctype {arg} {
switch -- $arg {
html401 { append html \
{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">}
}
html401t { append html \
{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">}
}
}
return $html
}

I like the switch because it makes it easier to add more doctypes as
they come along. What I want to do it make it *not* case sensitive. So
the arg can be HTML401T or html401t or any combo as long as they are
the correct letter/number combos.

I am sure I have to pass that through a regex or something to achieve
that.

Robert

Bruce Hartweg

2006-05-24, 10:04 pm

Robert Hicks wrote:
> I am woking on adding ::html::doctype to the html tcllib package. I
> have a working snippet (not complete):
>
> proc ::html::doctype {arg} {
> switch -- $arg {
> html401 { append html \
> {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
> "http://www.w3.org/TR/html4/strict.dtd">}
> }
> html401t { append html \
> {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
> Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">}
> }
> }
> return $html
> }
>
> I like the switch because it makes it easier to add more doctypes as
> they come along. What I want to do it make it *not* case sensitive. So
> the arg can be HTML401T or html401t or any combo as long as they are
> the correct letter/number combos.
>
> I am sure I have to pass that through a regex or something to achieve
> that.


don;t need a regexp - just do :

switch -- [string tolower $arg] {
...
}

Bruce
Robert Hicks

2006-05-24, 10:04 pm

Ah! I always forget about that!

Robert

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com