Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: regexp2000/src/ast.cc

Issue 11407: * Changed meaning of "%k" format to always output fixed-width ASCII-only representations. (Closed)
Patch Set: Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | regexp2000/src/string-stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 void* RegExpUnparser::VisitAlternative(RegExpAlternative* that, void* data) { 247 void* RegExpUnparser::VisitAlternative(RegExpAlternative* that, void* data) {
248 stream()->Add("(:"); 248 stream()->Add("(:");
249 for (int i = 0; i < that->nodes()->length(); i++) { 249 for (int i = 0; i < that->nodes()->length(); i++) {
250 stream()->Add(" "); 250 stream()->Add(" ");
251 that->nodes()->at(i)->Accept(this, data); 251 that->nodes()->at(i)->Accept(this, data);
252 } 252 }
253 stream()->Add(")"); 253 stream()->Add(")");
254 return NULL; 254 return NULL;
255 } 255 }
256 256
257 static void AddChar(StringStream* stream, uc16 character) { 257
258 if (character < 32 || (character >= 128 && character < 256)) { 258 void RegExpUnparser::VisitCharacterRange(CharacterRange that) {
259 stream->Add("\\x%02x", character); 259 stream()->Add("%k", that.from());
260 } else if (character >= 256) { 260 if (!that.IsSingleton()) {
261 stream->Add("\\u%04x", character); 261 stream()->Add("-%k", that.to());
262 } else {
263 stream->Add("%c", character);
264 } 262 }
265 } 263 }
266 264
267 void RegExpUnparser::VisitCharacterRange(CharacterRange that) {
268 AddChar(stream(), that.from());
269 if (!that.IsSingleton()) {
270 stream()->Add("-");
271 AddChar(stream(), that.to());
272 }
273 }
274
275 265
276 266
277 void* RegExpUnparser::VisitCharacterClass(RegExpCharacterClass* that, 267 void* RegExpUnparser::VisitCharacterClass(RegExpCharacterClass* that,
278 void* data) { 268 void* data) {
279 if (that->is_negated()) 269 if (that->is_negated())
280 stream()->Add("^"); 270 stream()->Add("^");
281 stream()->Add("["); 271 stream()->Add("[");
282 for (int i = 0; i < that->ranges()->length(); i++) { 272 for (int i = 0; i < that->ranges()->length(); i++) {
283 if (i > 0) stream()->Add(" "); 273 if (i > 0) stream()->Add(" ");
284 VisitCharacterRange(that->ranges()->at(i)); 274 VisitCharacterRange(that->ranges()->at(i));
(...skipping 25 matching lines...) Expand all
310 break; 300 break;
311 } 301 }
312 return NULL; 302 return NULL;
313 } 303 }
314 304
315 305
316 void* RegExpUnparser::VisitAtom(RegExpAtom* that, void* data) { 306 void* RegExpUnparser::VisitAtom(RegExpAtom* that, void* data) {
317 stream()->Add("'"); 307 stream()->Add("'");
318 Vector<const uc16> chardata = that->data(); 308 Vector<const uc16> chardata = that->data();
319 for (int i = 0; i < chardata.length(); i++) { 309 for (int i = 0; i < chardata.length(); i++) {
320 AddChar(stream(), chardata[i]); 310 stream()->Add("%k", chardata[i]);
321 } 311 }
322 stream()->Add("'"); 312 stream()->Add("'");
323 return NULL; 313 return NULL;
324 } 314 }
325 315
326 316
327 void* RegExpUnparser::VisitText(RegExpText* that, void* data) { 317 void* RegExpUnparser::VisitText(RegExpText* that, void* data) {
328 if (that->elements()->length() == 1) { 318 if (that->elements()->length() == 1) {
329 that->elements()->at(0).data.u_atom->Accept(this, data); 319 that->elements()->at(0).data.u_atom->Accept(this, data);
330 } else { 320 } else {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 374
385 375
386 SmartPointer<const char> RegExpTree::ToString() { 376 SmartPointer<const char> RegExpTree::ToString() {
387 RegExpUnparser unparser; 377 RegExpUnparser unparser;
388 Accept(&unparser, NULL); 378 Accept(&unparser, NULL);
389 return unparser.ToString(); 379 return unparser.ToString();
390 } 380 }
391 381
392 382
393 } } // namespace v8::internal 383 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | regexp2000/src/string-stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698