GNOME Bugzilla – Bug 606838
const triple quoted strings are too long
Last modified: 2010-10-14 08:28:40 UTC
When using """ strings, the generated code in C should be: var str = """ this is just a random text to test quoted strings """; const char *str = "\n" "this is just\n" "a random text\n" "to test quoted\n" "strings\n"; And the same for const strings (#define) The string in C should be parsed to ensure a decent column width: - split string at every \n - split string if text exceeds column N The problem is that Visual Studio does not supports long lines and fails to compile such C files. It also makes the C code hard to read.
Does the above example already fail with Visual Studio or does it only fail at longer lines? What's the limit?
It fails when lines are longer than 16Kb, according to: http://msdn.microsoft.com/en-us/library/dddywwsc(VS.80).aspx
Created attachment 152051 [details] [review] Split large string literal in multiple lines Fixes bug 606838.
This patch is ok for normal variables, but if you set the variable as const, vala generates a CPP macro which needs a '\' at the end of the line to not chop the macro at the first line. Here's a example: 264 #define FOO_preference_window_string "\n" 265 "<?xml version=\"1.0\"?>\n" 266 "<!--Generated with glade3 3.4.5 on Tue Dec 22 10:52:57 2009 -->\n" 267 "<interface>\n" .. must be: 264 #define FOO_preference_window_string "\n" \ 265 "<?xml version=\"1.0\"?>\n" \ 266 "<!--Generated with glade3 3.4.5 on Tue Dec 22 10:52:57 2009 -->\n" \ 267 "<interface>\n" \ .. Another enhacement would be to check if the string between '\n' is longer than X and then split it again without appending "\n" to ensure that no line is that long.
(In reply to comment #4) > must be: > > 264 #define FOO_preference_window_string "\n" \ > 265 "<?xml version=\"1.0\"?>\n" \ > 266 "<!--Generated with glade3 3.4.5 on Tue Dec 22 10:52:57 2009 -->\n" \ > 267 "<interface>\n" \ > .. Should we add \ in all cases, that would be a trivial change. > Another enhacement would be to check if the string between '\n' is longer than > X and then split it again without appending "\n" to ensure that no line is that > long. that I do already, or could you rephrase?
Yep, it's ok to append \ everywhere. Oh, sorry, you are right, your patch is checking for strings longer than 68 chars (maybe a longer size can be ok too) it depends on how many columns do vala standards recommend :)
(In reply to comment #6) > Yep, it's ok to append \ everywhere. > ok, I'll update the patch > Oh, sorry, you are right, your patch is checking for strings longer than 68 > chars (maybe a longer size can be ok too) it depends on how many columns do > vala standards recommend :) it's not really 68, it's more like 70, if character 68 is a backslash (which is not already escaped), it takes the following char, and then put a quote = 70 char ;) well, I don't know, I didn't though too much about it.
Created attachment 152253 [details] [review] Split large string literal in multiple lines Fixes bug 606838.
This breaks multi-character escape sequences such as in the following example: void main () { var s = "lorem ipsum dolor sit amet, consectetur, sadipisci velit lorem ipsu\x35 lorem ipsum"; message (s); }
Created attachment 155791 [details] [review] Split large string literal in multiple lines Fixes bug 606838.
Created attachment 156127 [details] [review] Split large string literal in multiple lines Fixes bug 606838.
I'm afraid my above testcase still fails with the latest patch. I'll try to come up with a fix.
commit 20666769c446ece07ef1063188d3ac5879c9f84c Author: Jürg Billeter <j@bitron.ch> Date: Sat Jan 23 00:03:06 2010 +0100 Split large string literals into multiple lines Based on patch by Marc-André Lureau, fixes bug 606838.
*** Bug 539894 has been marked as a duplicate of this bug. ***