forked from uncrustify/uncrustify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd.tokenize.cpp
More file actions
122 lines (114 loc) · 2.76 KB
/
d.tokenize.cpp
File metadata and controls
122 lines (114 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* @file d.tokenize.cpp
* This file gets included into tokenize.cpp.
* This is specific to the D language.
*
* @author Ben Gardner
* @license GPL v2+
*/
/**
* Parses all legal D string constants.
*
* Quoted strings:
* r"Wysiwyg" # WYSIWYG string
* x"hexstring" # Hexadecimal array
* `Wysiwyg` # WYSIWYG string
* 'char' # single character
* "reg_string" # regular string
*
* Non-quoted strings:
* \x12 # 1-byte hex constant
* \u1234 # 2-byte hex constant
* \U12345678 # 4-byte hex constant
* \123 # octal constant
* \& # named entity
* \n # single character
*
* @param pc The structure to update, str is an input.
* @return Whether a string was parsed
*/
static bool d_parse_string(chunk_t *pc)
{
if (pc->str[0] == '"')
{
return(parse_string(pc, 0, true));
}
else if ((pc->str[0] == '\'') ||
(pc->str[0] == '`'))
{
return(parse_string(pc, 0, true));
}
else if (pc->str[0] == '\\')
{
pc->len = 0;
while (pc->str[pc->len] == '\\')
{
pc->len++;
/* Check for end of file */
switch (pc->str[pc->len])
{
case 'x':
/* \x HexDigit HexDigit */
pc->len += 3;
break;
case 'u':
/* \u HexDigit HexDigit HexDigit HexDigit */
pc->len += 5;
break;
case 'U':
/* \U HexDigit (x8) */
pc->len += 9;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
/* handle up to 3 octal digits */
pc->len++;
if ((pc->str[pc->len] >= '0') && (pc->str[pc->len] <= '7'))
{
pc->len++;
if ((pc->str[pc->len] >= '0') && (pc->str[pc->len] <= '7'))
{
pc->len++;
}
}
break;
case '&':
/* \& NamedCharacterEntity ; */
pc->len++;
while (isalpha(pc->str[pc->len]))
{
pc->len++;
}
if (pc->str[pc->len] == ';')
{
pc->len++;
}
break;
default:
/* Everything else is a single character */
pc->len++;
break;
}
}
if (pc->len > 1)
{
pc->type = CT_STRING;
cpd.column += pc->len;
return(true);
}
}
else if (pc->str[1] == '"')
{
if ((pc->str[0] == 'r') || (pc->str[0] == 'x'))
{
return(parse_string(pc, 1, false));
}
}
return(false);
}