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
20 * Jürg Billeter <j@bitron.ch>
26 * A constant C expression.
28 public class Vala
.CCodeConstant
: CCodeExpression
{
30 * The name of this constant.
32 public string name
{ get; set; }
34 public CCodeConstant (string _name
) {
38 const int LINE_LENGTH
= 70;
40 public CCodeConstant
.string (string _name
) {
41 assert (_name
[0] == '\"');
43 if (_name
.length
<= LINE_LENGTH
) {
48 var builder
= new
StringBuilder ("\"");
51 char* end
= p
+ _name
.length
;
59 if (col
>= LINE_LENGTH
) {
60 builder
.append ("\" \\\n\"");
64 char* begin_of_char
= p
;
66 builder
.append_c (p
[0]);
67 builder
.append_c (p
[1]);
71 // hexadecimal character
72 while (p
< end
&& p
->isxdigit ()) {
73 builder
.append_c (*p
);
82 col
+= (int) (p
- begin_of_char
);
84 builder
.append_unichar (((string) p
).get_char ());
85 p
+= ((char*) ((string) p
).next_char () - p
);
90 builder
.append_c ('"');
92 this
.name
= builder
.str
;
95 public override void write (CCodeWriter writer
) {
96 writer
.write_string (name
);