Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/util/doxygen/src/cppvalue.cpp

Source at commit 1322 created 9 years 5 months ago.
By meklort, Add doxygen to utils folder
1/******************************************************************************
2 *
3 * $Id: cppvalue.cpp,v 1.6 2001/03/19 19:27:40 root Exp $
4 *
5 *
6 * Copyright (C) 1997-2011 by Dimitri van Heesch.
7 *
8 * Permission to use, copy, modify, and distribute this software and its
9 * documentation under the terms of the GNU General Public License is hereby
10 * granted. No representations are made about the suitability of this software
11 * for any purpose. It is provided "as is" without express or implied warranty.
12 * See the GNU General Public License for more details.
13 *
14 * Documents produced by Doxygen are derivative works derived from the
15 * input used in their production; they are not affected by this license.
16 *
17 */
18
19#include <stdlib.h>
20
21#include "cppvalue.h"
22#include "constexp.h"
23
24CPPValue parseOctal()
25{
26 long val = 0;
27 for (const char *p = g_strToken.data(); *p != 0; p++)
28 {
29 if (*p >= '0' && *p <= '7') val = val * 8 + *p - '0';
30 }
31 return CPPValue(val);
32}
33
34CPPValue parseDecimal()
35{
36 long val = 0;
37 for (const char *p = g_strToken.data(); *p != 0; p++)
38 {
39 if (*p >= '0' && *p <= '9') val = val * 10 + *p - '0';
40 }
41 return CPPValue(val);
42}
43
44CPPValue parseHexadecimal()
45{
46 long val = 0;
47 for (const char *p = g_strToken.data(); *p != 0; p++)
48 {
49 if (*p >= '0' && *p <= '9') val = val * 16 + *p - '0';
50 else if (*p >= 'a' && *p <= 'f') val = val * 16 + *p - 'a' + 10;
51 else if (*p >= 'A' && *p <= 'F') val = val * 16 + *p - 'A' + 10;
52 }
53 //printf("parseHexadecimal %s->%x\n",g_strToken.data(),val);
54 return CPPValue(val);
55}
56
57CPPValue parseCharacter() // does not work for '\n' and the alike
58{
59 if (g_strToken[1]=='\\')
60 {
61 switch(g_strToken[2])
62 {
63 case 'n': return CPPValue((long)'\n');
64 case 't': return CPPValue((long)'\t');
65 case 'v': return CPPValue((long)'\v');
66 case 'b': return CPPValue((long)'\b');
67 case 'r': return CPPValue((long)'\r');
68 case 'f': return CPPValue((long)'\f');
69 case 'a': return CPPValue((long)'\a');
70 case '\\': return CPPValue((long)'\\');
71 case '?': return CPPValue((long)'\?');
72 case '\'': return CPPValue((long)'\'');
73 case '"': return CPPValue((long)'"');
74 case '0': // fall through
75 case '1': // fall through
76 case '2': // fall through
77 case '3': // fall through
78 case '4': // fall through
79 case '5': // fall through
80 case '6': // fall through
81 case '7': // fall through
82 return parseOctal();
83 case 'x':
84 case 'X': return parseHexadecimal();
85 default: printf("Invalid escape sequence %s found!\n",g_strToken.data());
86 return CPPValue(0L);
87 }
88 }
89 return CPPValue((long)g_strToken[1]);
90}
91
92CPPValue parseFloat()
93{
94 return CPPValue(atof(g_strToken));
95}
96

Archive Download this file

Revision: 1322