blob: 5dff39648ad871b67d1ee61a844d561914ee48fa [file] [log] [blame]
Howard Hinnant70505302010-06-17 00:34:591//===-------------------------- regex.cpp ---------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "regex"
11#include "algorithm"
12#include "iterator"
13
14
15_LIBCPP_BEGIN_NAMESPACE_STD
16
17static
18const char*
19make_error_type_string(regex_constants::error_type ecode)
20{
21 switch (ecode)
22 {
23 case regex_constants::error_collate:
24 return "error_collate";
25 case regex_constants::error_ctype:
26 return "error_ctype";
27 case regex_constants::error_escape:
28 return "error_escape";
29 case regex_constants::error_backref:
30 return "error_backref";
31 case regex_constants::error_brack:
32 return "error_brack";
33 case regex_constants::error_paren:
34 return "error_paren";
35 case regex_constants::error_brace:
36 return "error_brace";
37 case regex_constants::error_badbrace:
38 return "error_badbrace";
39 case regex_constants::error_range:
40 return "error_range";
41 case regex_constants::error_space:
42 return "error_space";
43 case regex_constants::error_badrepeat:
44 return "error_badrepeat";
45 case regex_constants::error_complexity:
46 return "error_complexity";
47 case regex_constants::error_stack:
48 return "error_stack";
49 }
50 return "unknown error_type";
51}
52
53regex_error::regex_error(regex_constants::error_type ecode)
54 : runtime_error(make_error_type_string(ecode)),
55 __code_(ecode)
56{}
57
58regex_error::~regex_error() throw() {}
59
60namespace {
61
62struct collationnames
63{
64 const char* elem_;
65 char char_;
66};
67
68const collationnames collatenames[] =
69{
70 {"A", 0x41},
71 {"B", 0x42},
72 {"C", 0x43},
73 {"D", 0x44},
74 {"E", 0x45},
75 {"F", 0x46},
76 {"G", 0x47},
77 {"H", 0x48},
78 {"I", 0x49},
79 {"J", 0x4a},
80 {"K", 0x4b},
81 {"L", 0x4c},
82 {"M", 0x4d},
83 {"N", 0x4e},
84 {"NUL", 0x00},
85 {"O", 0x4f},
86 {"P", 0x50},
87 {"Q", 0x51},
88 {"R", 0x52},
89 {"S", 0x53},
90 {"T", 0x54},
91 {"U", 0x55},
92 {"V", 0x56},
93 {"W", 0x57},
94 {"X", 0x58},
95 {"Y", 0x59},
96 {"Z", 0x5a},
97 {"a", 0x61},
98 {"alert", 0x07},
99 {"ampersand", 0x26},
100 {"apostrophe", 0x27},
101 {"asterisk", 0x2a},
102 {"b", 0x62},
103 {"backslash", 0x5c},
104 {"backspace", 0x08},
105 {"c", 0x63},
106 {"carriage-return", 0x0d},
107 {"circumflex", 0x5e},
108 {"circumflex-accent", 0x5e},
109 {"colon", 0x3a},
110 {"comma", 0x2c},
111 {"commercial-at", 0x40},
112 {"d", 0x64},
113 {"dollar-sign", 0x24},
114 {"e", 0x65},
115 {"eight", 0x38},
116 {"equals-sign", 0x3d},
117 {"exclamation-mark", 0x21},
118 {"f", 0x66},
119 {"five", 0x35},
120 {"form-feed", 0x0c},
121 {"four", 0x34},
122 {"full-stop", 0x2e},
123 {"g", 0x67},
124 {"grave-accent", 0x60},
125 {"greater-than-sign", 0x3e},
126 {"h", 0x68},
127 {"hyphen", 0x2d},
128 {"hyphen-minus", 0x2d},
129 {"i", 0x69},
130 {"j", 0x6a},
131 {"k", 0x6b},
132 {"l", 0x6c},
133 {"left-brace", 0x7b},
134 {"left-curly-bracket", 0x7b},
135 {"left-parenthesis", 0x28},
136 {"left-square-bracket", 0x5b},
137 {"less-than-sign", 0x3c},
138 {"low-line", 0x5f},
139 {"m", 0x6d},
140 {"n", 0x6e},
141 {"newline", 0x0a},
142 {"nine", 0x39},
143 {"number-sign", 0x23},
144 {"o", 0x6f},
145 {"one", 0x31},
146 {"p", 0x70},
147 {"percent-sign", 0x25},
148 {"period", 0x2e},
149 {"plus-sign", 0x2b},
150 {"q", 0x71},
151 {"question-mark", 0x3f},
152 {"quotation-mark", 0x22},
153 {"r", 0x72},
154 {"reverse-solidus", 0x5c},
155 {"right-brace", 0x7d},
156 {"right-curly-bracket", 0x7d},
157 {"right-parenthesis", 0x29},
158 {"right-square-bracket", 0x5d},
159 {"s", 0x73},
160 {"semicolon", 0x3b},
161 {"seven", 0x37},
162 {"six", 0x36},
163 {"slash", 0x2f},
164 {"solidus", 0x2f},
165 {"space", 0x20},
166 {"t", 0x74},
167 {"tab", 0x09},
168 {"three", 0x33},
169 {"tilde", 0x7e},
170 {"two", 0x32},
171 {"u", 0x75},
172 {"underscore", 0x5f},
173 {"v", 0x76},
174 {"vertical-line", 0x7c},
175 {"vertical-tab", 0x0b},
176 {"w", 0x77},
177 {"x", 0x78},
178 {"y", 0x79},
179 {"z", 0x7a},
180 {"zero", 0x30}
181};
182
183struct use_strcmp
184{
185 bool operator()(const collationnames& x, const char* y)
186 {return strcmp(x.elem_, y) < 0;}
187};
188
189}
190
191string
192__get_collation_name(const char* s)
193{
194 typedef std::pair<collationnames*, collationnames*> P;
195 const collationnames* i =
196 lower_bound(begin(collatenames), end(collatenames), s, use_strcmp());
197 string r;
198 if (i != end(collatenames) && strcmp(s, i->elem_) == 0)
199 r = char(i->char_);
200 return r;
201}
202
203_LIBCPP_END_NAMESPACE_STD