girwriter: Fix indices for delegate parameters
[vala-lang.git] / ccode / valaccodeconstant.vala
blob85e63c73e4c1ef8942a2754913164d7fc6275661
1 /* valaccodeconstant.vala
3 * Copyright (C) 2006-2010 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * A constant C expression.
28 public class Vala.CCodeConstant : CCodeExpression {
29 /**
30 * The name of this constant.
32 public string name { get; set; }
34 public CCodeConstant (string _name) {
35 name = _name;
38 const int LINE_LENGTH = 70;
40 public CCodeConstant.string (string _name) {
41 assert (_name[0] == '\"');
43 if (_name.length <= LINE_LENGTH) {
44 name = _name;
45 return;
48 var builder = new StringBuilder ("\"");
50 char* p = _name;
51 char* end = p + _name.length;
53 // remove quotes
54 p++;
55 end--;
57 int col = 0;
58 while (p < end) {
59 if (col >= LINE_LENGTH) {
60 builder.append ("\" \\\n\"");
61 col = 0;
63 if (*p == '\\') {
64 char* begin_of_char = p;
66 builder.append_c (p[0]);
67 builder.append_c (p[1]);
68 p += 2;
69 switch (p[-1]) {
70 case 'x':
71 // hexadecimal character
72 while (p < end && p->isxdigit ()) {
73 builder.append_c (*p);
74 p++;
76 break;
77 case 'n':
78 // break line at \n
79 col = LINE_LENGTH;
80 break;
82 col += (int) (p - begin_of_char);
83 } else {
84 builder.append_unichar (((string) p).get_char ());
85 p += ((char*) ((string) p).next_char () - p);
86 col++;
90 builder.append_c ('"');
92 this.name = builder.str;
95 public override void write (CCodeWriter writer) {
96 writer.write_string (name);