You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Geir Magnusson Jr." <ge...@yahoo.com> on 2001/11/13 20:02:36 UTC

Escaped quotes in string literals

I have something working, but wanted to solicit some opinions.

Fundamentally, the escaping should keep the syntax from getting in the way,
so at the zeroth order fix, we need to escape ' and " such that

  #set($foo = 'I\'m tired.' )
  $foo

Renders as

  I'm tired.

And

  #set($bar = "foo=bar")
  #set($href = "<a href=\"foo.vm?$bar\">Hi</a>")
  $href

Renders as 
    
   <a href="foo.vm?foo=bar">Hi</a>

This works so far.

Now, I am worried about it being confusing for users - I think that \' and
\" should render as ' and " no matter if in single quotes or double quotes.

So

  #set($foo = "I\'m tired, $name.")
  #set($bar = "I'm tired, $name.")

Produce the same thing.

Now, this is weird in some sense as there are two string literals that don't
look the same but produce the same thing - however, the flip side is endless
confusion trying to explain the rule that active escape only applies to the
same character that is delineating the string...

Opinions?

(It works this way in my version...)

Next subject - I don't really believe that we need to do standard escaping
like \n, \t and \r - I think that is a perfectly adequate thing for a tool
to do, as it doesn't prevent you from cleanly expressing simple things like
the current problem with " and ' do...

You can always do something like

#set( $foo = "This is a $tool.char('\n')")

Or whatever...

Finally, there is the question of long strings - should we allow

#set( $foo = "I am a long \
String that goes across two lines \
Or more")


Now, this is compelling for its convenience for people that want to keep
long strings.  However, do we want to encourage that?  It can be achieved
via the app putting references in the context as well as

  #set($foo = "#include<'textresource.txt')")


Opinions?

geir

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Escaped quotes in string literals

Posted by LS <al...@yahoo.com>.
I vote for the first one as well. 

#set($simple = "good thing")


--- Terry Steichen <te...@net-frame.com> wrote:
> Geir,
> 
> On the first one - I agree.  I remember how confusing this was at first.
> The simpler the better.




__________________________________________________
Do You Yahoo!?
Find the one for you at Yahoo! Personals
http://personals.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Escaped quotes in string literals

Posted by Terry Steichen <te...@net-frame.com>.
Geir,

On the first one - I agree.  I remember how confusing this was at first.
The simpler the better.

On the second one - I agree - for the same reason as above.  Too much
convenience threatens simplicity. And simplicity will be the *key* to
broadscale adoption of Velocity (with the option to extend it with clever
tricks if you need to).

My $0.02.

Regards,

Terry

----- Original Message -----
From: "Geir Magnusson Jr." <ge...@yahoo.com>
To: <ve...@jakarta.apache.org>
Sent: Tuesday, November 13, 2001 2:02 PM
Subject: Escaped quotes in string literals


> I have something working, but wanted to solicit some opinions.
>
> Fundamentally, the escaping should keep the syntax from getting in the
way,
> so at the zeroth order fix, we need to escape ' and " such that
>
>   #set($foo = 'I\'m tired.' )
>   $foo
>
> Renders as
>
>   I'm tired.
>
> And
>
>   #set($bar = "foo=bar")
>   #set($href = "<a href=\"foo.vm?$bar\">Hi</a>")
>   $href
>
> Renders as
>
>    <a href="foo.vm?foo=bar">Hi</a>
>
> This works so far.
>
> Now, I am worried about it being confusing for users - I think that \' and
> \" should render as ' and " no matter if in single quotes or double
quotes.
>
> So
>
>   #set($foo = "I\'m tired, $name.")
>   #set($bar = "I'm tired, $name.")
>
> Produce the same thing.
>
> Now, this is weird in some sense as there are two string literals that
don't
> look the same but produce the same thing - however, the flip side is
endless
> confusion trying to explain the rule that active escape only applies to
the
> same character that is delineating the string...
>
> Opinions?
>
> (It works this way in my version...)
>
> Next subject - I don't really believe that we need to do standard escaping
> like \n, \t and \r - I think that is a perfectly adequate thing for a tool
> to do, as it doesn't prevent you from cleanly expressing simple things
like
> the current problem with " and ' do...
>
> You can always do something like
>
> #set( $foo = "This is a $tool.char('\n')")
>
> Or whatever...
>
> Finally, there is the question of long strings - should we allow
>
> #set( $foo = "I am a long \
> String that goes across two lines \
> Or more")
>
>
> Now, this is compelling for its convenience for people that want to keep
> long strings.  However, do we want to encourage that?  It can be achieved
> via the app putting references in the context as well as
>
>   #set($foo = "#include<'textresource.txt')")
>
>
> Opinions?
>
> geir
>
> --
> Geir Magnusson Jr.                                     geirm@optonline.net
> System and Software Consulting
> "They that can give up essential liberty to obtain a little temporary
safety
> deserve neither liberty nor safety." - Benjamin Franklin
>
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Escaped quotes in string literals

Posted by Christoph Reck <Ch...@dlr.de>.
"Geir Magnusson Jr." wrote:
> 
> I have something working, but wanted to solicit some opinions.
> 
> Fundamentally, the escaping should keep the syntax from getting in the way,
> so at the zeroth order fix, we need to escape ' and " such that
> 
>   #set($foo = 'I\'m tired.' )
>   $foo
>[snip]
>   #set($foo = "I\'m tired")
>   #set($bar = "I'm tired")
> 
> Produce the same thing.

+1

#set( $foo = 'Geir\' proposal' )
#set( $bar = "It\'s good" )
#set( $boo = "I say: \"Fine\"" )
#set( $goo = '\"Just great!\"' )

Will then render as one would expect with othogonal escaping rules on quotes!

>[snip]
> Next subject - I don't really believe that we need to do standard escaping
> like \n, \t and \r - I think that is a perfectly adequate thing for a tool
> to do, as it doesn't prevent you from cleanly expressing simple things like
> the current problem with " and ' do...
> 
> You can always do something like
> 
> #set( $foo = "This is a $tool.char('\n')")
> 
> Or whatever...

I use #set( $LF = $StringTool.URLDecode('%0A') ), which uses the standard 
HTML and URL functionality.

> 
> Finally, there is the question of long strings - should we allow
> 
> #set( $foo = "I am a long \
> String that goes across two lines \
> Or more")
> 
> Now, this is compelling for its convenience for people that want to keep
> long strings.  However, do we want to encourage that?  It can be achieved
> via the app putting references in the context as well as
> 
>   #set($foo = "#include<'textresource.txt')")
> 
> Opinions?

Maybe you are right not to encourage people with such a feature, I've
had some case where this would have been nice, but there are
feasible workarounds:

#set( $button = "http://www.eoweb.de:8888/eoweb/servlets/button" )
#set( $button = "$button?fontSize=20&fontStyle=bold&width=200" )
#set( $search = "$button&text=Data+Search" )

to obtain very long strings. Someone else suggested once to use 
macros and escape the line break using comments:

#macro( button $text )##
http://www.eoweb.de:8888/eoweb/servlets/button?fontSize=16##
&text=$StringTool.URLEncode($text)##
#end

and then:
#set( $search = "#button( 'Data Search' )" )

B.T.W. Anyone interested in this simple button servlet (the above URL works!), 
please contact me and we can put it on sourceforge.


My 2c disclaimer...

:) Christoph

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Escaped quotes in string literals

Posted by Steven Caswell <st...@yahoo.com>.
I'll weigh in on the first one (I'm just too ambivalent on the other two):
I think anything that keeps me from having to think about special cases is a
good thing.  There is a finite amount of memory in my brain, and the less
rules to remember, the better.  So I like what you are proposing.

-----Original Message-----
From: Geir Magnusson Jr. [mailto:geirmagnussonjr@yahoo.com]
Sent: Tuesday, November 13, 2001 2:03 PM
To: velocity-user@jakarta.apache.org
Subject: Escaped quotes in string literals


I have something working, but wanted to solicit some opinions.

Fundamentally, the escaping should keep the syntax from getting in the way,
so at the zeroth order fix, we need to escape ' and " such that

  #set($foo = 'I\'m tired.' )
  $foo

Renders as

  I'm tired.

And

  #set($bar = "foo=bar")
  #set($href = "<a href=\"foo.vm?$bar\">Hi</a>")
  $href

Renders as

   <a href="foo.vm?foo=bar">Hi</a>

This works so far.

Now, I am worried about it being confusing for users - I think that \' and
\" should render as ' and " no matter if in single quotes or double quotes.

So

  #set($foo = "I\'m tired, $name.")
  #set($bar = "I'm tired, $name.")

Produce the same thing.

Now, this is weird in some sense as there are two string literals that don't
look the same but produce the same thing - however, the flip side is endless
confusion trying to explain the rule that active escape only applies to the
same character that is delineating the string...

Opinions?

(It works this way in my version...)

Next subject - I don't really believe that we need to do standard escaping
like \n, \t and \r - I think that is a perfectly adequate thing for a tool
to do, as it doesn't prevent you from cleanly expressing simple things like
the current problem with " and ' do...

You can always do something like

#set( $foo = "This is a $tool.char('\n')")

Or whatever...

Finally, there is the question of long strings - should we allow

#set( $foo = "I am a long \
String that goes across two lines \
Or more")


Now, this is compelling for its convenience for people that want to keep
long strings.  However, do we want to encourage that?  It can be achieved
via the app putting references in the context as well as

  #set($foo = "#include<'textresource.txt')")


Opinions?

geir

--
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>