Re: name:variable

Sovande Ulv <[email protected]>
Newsgroups gmane.text.clearsilver.general
Message-ID <[email protected]>
On Nov 27, 2007, at 4:16 PM, Sovande Ulv wrote:

> Would it be possible for name:var to return a value so it can be used
> in statements such as this:
>
> <?cs if:var:key == name:header ?>
>

Ah hmm, the problem was not that name:header does not return a value.  
The problem is that I use variable names with '-' in them and that  
'var:key'  and 'name:header' evaluates to a minus expression when key  
or header contains a '-'.

So the expression, <?cs if:var:key == name:header ?>  becomes  <?cs if: 
0== 0 ?>. The problem lies in csparse.c:parse_tokens() which scan args  
and if it finds a '-' or '+' in the arg assume (wrongly in my case)  
that it deals with a numeric expression.

I understand that '-' and '+' may be tricky in variable names, but  
this could easily be handled by using the parse->hdf tree as a symbol  
table and look up a variable there first. At least, this will handle  
hdf variables. "In place" variable set with "set:variable.." is  
another case.

The reason I use variables with '-' in the name is that it is very  
convenient to define HTTP headers as they come in, directly in a hdf  
tree like so:

Request.Header.Host = localhost:8080
Request.Header.Connection = keep-alive
Request.Header.Accept-Encoding = gzip, deflate
Request.Header.Accept-Language = en-us
Request.Header.Accept = text/xml,application/xml,application/xhtml 
+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Request.Header.Cache-Control = max-age=0
Request.Header.User-Agent = Mozilla/5.0 (Macintosh; U; Intel Mac OS X;  
en-us) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/ 
523.10

Request headers can then be accessed and printed like so,

  <?cs each:header = Request.Header ?>
     <li> <?cs name:header ?> = <?cs var:header ?>
  <?cs /each ?>

Though direct access to e.g Request.Header.Accept-Encoding  using  <? 
cs var: Request.Header.Accept-Encoding ?> does not work since it  
evaluates to "Request.Header.Accept - Encoding" -> 0 Though <?cs evar:  
Request.Header.Accept-Encoding ?> prints correctly -> gzip, deflate,  
but unfortunately evar cannot be used in a each-loop.

I believe that the clearsilver CGI module also would benefit from this  
as well, i.e. allow to define variables with '-' in them.  This way  
the cgi module does not have to hardcode header names it will  
recognize but can define all headers as they come in, in a hdf tree.

Would you be interested in a patch for this Brandon, or maybe you  
already have thought about it and have a workaround?

Best regards
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.