summaryrefslogtreecommitdiff
path: root/ccode
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2010-01-23 00:03:06 +0100
committerJürg Billeter <j@bitron.ch>2010-03-14 20:25:35 +0100
commit20666769c446ece07ef1063188d3ac5879c9f84c (patch)
tree2d54f6908b43395f8122992868dd1c2069eae2c6 /ccode
parent20db7f59c9ae1d9ea157adacb91e73666e53f69b (diff)
downloadvala-20666769c446ece07ef1063188d3ac5879c9f84c.tar.gz
Split large string literals into multiple lines
Based on patch by Marc-André Lureau, fixes bug 606838.
Diffstat (limited to 'ccode')
-rw-r--r--ccode/valaccodeconstant.vala63
1 files changed, 60 insertions, 3 deletions
diff --git a/ccode/valaccodeconstant.vala b/ccode/valaccodeconstant.vala
index ebf36e9c6..0ac49ec3d 100644
--- a/ccode/valaccodeconstant.vala
+++ b/ccode/valaccodeconstant.vala
@@ -1,6 +1,6 @@
/* valaccodeconstant.vala
*
- * Copyright (C) 2006 Jürg Billeter
+ * Copyright (C) 2006-2010 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -30,11 +30,68 @@ public class Vala.CCodeConstant : CCodeExpression {
* The name of this constant.
*/
public string name { get; set; }
-
+
public CCodeConstant (string _name) {
name = _name;
}
-
+
+ const int LINE_LENGTH = 70;
+
+ public CCodeConstant.string (string _name) {
+ assert (_name[0] == '\"');
+
+ if (_name.length <= LINE_LENGTH) {
+ name = _name;
+ return;
+ }
+
+ var builder = new StringBuilder ("\"");
+
+ char* p = _name;
+ char* end = p + _name.size ();
+
+ // remove quotes
+ p++;
+ end--;
+
+ int col = 0;
+ while (p < end) {
+ if (col >= LINE_LENGTH) {
+ builder.append ("\" \\\n\"");
+ col = 0;
+ }
+ if (*p == '\\') {
+ char* begin_of_char = p;
+
+ builder.append_c (p[0]);
+ builder.append_c (p[1]);
+ p += 2;
+ switch (p[-1]) {
+ case 'x':
+ // hexadecimal character
+ while (p < end && p->isxdigit ()) {
+ builder.append_c (*p);
+ p++;
+ }
+ break;
+ case 'n':
+ // break line at \n
+ col = LINE_LENGTH;
+ break;
+ }
+ col += (int) (p - begin_of_char);
+ } else {
+ builder.append_unichar (((string) p).get_char ());
+ p += ((char*) ((string) p).next_char () - p);
+ col++;
+ }
+ }
+
+ builder.append_c ('"');
+
+ this.name = builder.str;
+ }
+
public override void write (CCodeWriter writer) {
writer.write_string (name);
}