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

Side by Side Diff: src/ostreams.cc

Issue 1618753002: Revert of [regexp] implement character classes for unicode regexps. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 months 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 | « src/ostreams.h ('k') | src/regexp/jsregexp.h » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/ostreams.h" 5 #include "src/ostreams.h"
6 #include "src/objects.h"
7 6
8 #if V8_OS_WIN 7 #if V8_OS_WIN
9 #if _MSC_VER < 1900 8 #if _MSC_VER < 1900
10 #define snprintf sprintf_s 9 #define snprintf sprintf_s
11 #endif 10 #endif
12 #endif 11 #endif
13 12
14 namespace v8 { 13 namespace v8 {
15 namespace internal { 14 namespace internal {
16 15
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 bool IsOK(uint16_t c) { return (IsPrint(c) || IsSpace(c)) && c != '\\'; } 53 bool IsOK(uint16_t c) { return (IsPrint(c) || IsSpace(c)) && c != '\\'; }
55 54
56 55
57 std::ostream& PrintUC16(std::ostream& os, uint16_t c, bool (*pred)(uint16_t)) { 56 std::ostream& PrintUC16(std::ostream& os, uint16_t c, bool (*pred)(uint16_t)) {
58 char buf[10]; 57 char buf[10];
59 const char* format = pred(c) ? "%c" : (c <= 0xff) ? "\\x%02x" : "\\u%04x"; 58 const char* format = pred(c) ? "%c" : (c <= 0xff) ? "\\x%02x" : "\\u%04x";
60 snprintf(buf, sizeof(buf), format, c); 59 snprintf(buf, sizeof(buf), format, c);
61 return os << buf; 60 return os << buf;
62 } 61 }
63 62
64
65 std::ostream& PrintUC32(std::ostream& os, int32_t c, bool (*pred)(uint16_t)) {
66 if (c <= String::kMaxUtf16CodeUnit) {
67 return PrintUC16(os, static_cast<uint16_t>(c), pred);
68 }
69 char buf[13];
70 snprintf(buf, sizeof(buf), "\\u{%06x}", c);
71 return os << buf;
72 }
73
74 } // namespace 63 } // namespace
75 64
76 65
77 std::ostream& operator<<(std::ostream& os, const AsReversiblyEscapedUC16& c) { 66 std::ostream& operator<<(std::ostream& os, const AsReversiblyEscapedUC16& c) {
78 return PrintUC16(os, c.value, IsOK); 67 return PrintUC16(os, c.value, IsOK);
79 } 68 }
80 69
81 70
82 std::ostream& operator<<(std::ostream& os, const AsEscapedUC16ForJSON& c) { 71 std::ostream& operator<<(std::ostream& os, const AsEscapedUC16ForJSON& c) {
83 if (c.value == '\n') return os << "\\n"; 72 if (c.value == '\n') return os << "\\n";
84 if (c.value == '\r') return os << "\\r"; 73 if (c.value == '\r') return os << "\\r";
85 if (c.value == '\t') return os << "\\t"; 74 if (c.value == '\t') return os << "\\t";
86 if (c.value == '\"') return os << "\\\""; 75 if (c.value == '\"') return os << "\\\"";
87 return PrintUC16(os, c.value, IsOK); 76 return PrintUC16(os, c.value, IsOK);
88 } 77 }
89 78
90 79
91 std::ostream& operator<<(std::ostream& os, const AsUC16& c) { 80 std::ostream& operator<<(std::ostream& os, const AsUC16& c) {
92 return PrintUC16(os, c.value, IsPrint); 81 return PrintUC16(os, c.value, IsPrint);
93 } 82 }
94 83
95
96 std::ostream& operator<<(std::ostream& os, const AsUC32& c) {
97 return PrintUC32(os, c.value, IsPrint);
98 }
99
100 } // namespace internal 84 } // namespace internal
101 } // namespace v8 85 } // namespace v8
OLDNEW
« no previous file with comments | « src/ostreams.h ('k') | src/regexp/jsregexp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698