[ 
https://issues.apache.org/jira/browse/THRIFT-153?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12637197#action_12637197
 ] 

Chad Walters commented on THRIFT-153:
-------------------------------------

Mark, I think that Dave points out a flaw that should be addressed, though. We 
do need some kind of escaping in Thrift IDL or we can't represent strings with 
both single quotes and double quotes in them. However, as you correctly point 
out, this escaping should be separate from the escaping needs of the target 
languages.

My recommendation:
1. Beef up the IDL parser to allow some form of slash escaping in the constant 
strings. This would not be fully backwards compatible since existing '\' in 
strings would need to be escaped. The parser would unescape these characters as 
they are read in.
2. Have the compiler perform the appropriate language-specific escaping as you 
suggest above.

> Invalid code generated for string constants containing single quotes (')
> ------------------------------------------------------------------------
>
>                 Key: THRIFT-153
>                 URL: https://issues.apache.org/jira/browse/THRIFT-153
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Python)
>            Reporter: Dave Engberg
>         Attachments: t_py_generator.cc.diff
>
>
> If I declare a constant in a Thrift iDL like this:
> const string HAMMER_TIME = "Can't touch this";
> The generated Python sources generate a constant like this:
> HAMMER_TIME = 'Can't touch this';
> This doesn't work because the apostrophe terminates the string constant.
> Since Python supports string constants using either ' or ", an easy fix is 
> just to use " around Python constants instead:
> Index: compiler/cpp/src/generate/t_py_generator.cc
> ===================================================================
> --- compiler/cpp/src/generate/t_py_generator.cc       (revision 701711)
> +++ compiler/cpp/src/generate/t_py_generator.cc       (working copy)
> @@ -363,7 +363,7 @@
>      t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
>      switch (tbase) {
>      case t_base_type::TYPE_STRING:
> -      out << "'" << value->get_string() << "'";
> +      out << '"' << value->get_string() << '"';
>        break;
>      case t_base_type::TYPE_BOOL:
>        out << (value->get_integer() > 0 ? "True" : "False");

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to