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

Unified Diff: src/string-stream.cc

Issue 8188: Some new regexp infrastructure. (Closed)
Patch Set: Created 12 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: src/string-stream.cc
diff --git a/src/string-stream.cc b/src/string-stream.cc
index 81cbea51bd4e79d9c02a79d3a8a9c0a34ab4db04..4390fa17cd932e9dda9271846298025248eb26cd 100644
--- a/src/string-stream.cc
+++ b/src/string-stream.cc
@@ -93,13 +93,13 @@ static bool IsControlChar(char c) {
}
-void StringStream::Add(const char* format, Vector<FmtElm> elms) {
+void StringStream::Add(Vector<const char> format, Vector<FmtElm> elms) {
// If we already ran out of space then return immediately.
if (space() == 0)
return;
int offset = 0;
int elm = 0;
- while (format[offset] != '\0') {
+ while (offset < format.length()) {
if (format[offset] != '%' || elm == elms.length()) {
Put(format[offset]);
offset++;
@@ -111,12 +111,11 @@ void StringStream::Add(const char* format, Vector<FmtElm> elms) {
// Skip over the whole control character sequence until the
// format element type
temp[format_length++] = format[offset++];
- // '\0' is not a control character so we don't have to
- // explicitly check for the end of the string
- while (IsControlChar(format[offset]))
+ while (offset < format.length() && IsControlChar(format[offset]))
temp[format_length++] = format[offset++];
+ if (offset >= format.length())
+ return;
char type = format[offset];
- if (type == '\0') return;
temp[format_length++] = type;
temp[format_length] = '\0';
offset++;
@@ -128,6 +127,13 @@ void StringStream::Add(const char* format, Vector<FmtElm> elms) {
Add(value);
break;
}
+ case 'w': {
+ ASSERT_EQ(FmtElm::LC_STR, current.type_);
+ Vector<const uc16> value = *current.data_.u_lc_str_;
+ for (int i = 0; i < value.length(); i++)
+ Put(value[i]);
+ break;
+ }
case 'o': {
ASSERT_EQ(FmtElm::OBJ, current.type_);
Object* obj = current.data_.u_obj_;
@@ -137,8 +143,8 @@ void StringStream::Add(const char* format, Vector<FmtElm> elms) {
case 'i': case 'd': case 'u': case 'x': case 'c': case 'p': {
int value = current.data_.u_int_;
EmbeddedVector<char, 24> formatted;
- OS::SNPrintF(formatted, temp.start(), value);
- Add(formatted.start());
+ int length = OS::SNPrintF(formatted, temp.start(), value);
+ Add(Vector<const char>(formatted.start(), length));
break;
}
default:
@@ -147,10 +153,8 @@ void StringStream::Add(const char* format, Vector<FmtElm> elms) {
}
}
- // Verify that the buffer is 0-terminated and doesn't contain any
- // other 0-characters.
+ // Verify that the buffer is 0-terminated
ASSERT(buffer_[length_] == '\0');
- ASSERT(strlen(buffer_) == length_);
}
@@ -181,6 +185,11 @@ void StringStream::PrintObject(Object* o) {
void StringStream::Add(const char* format) {
+ Add(CStrVector(format));
+}
+
+
+void StringStream::Add(Vector<const char> format) {
Add(format, Vector<FmtElm>::empty());
}
@@ -188,14 +197,14 @@ void StringStream::Add(const char* format) {
void StringStream::Add(const char* format, FmtElm arg0) {
const char argc = 1;
FmtElm argv[argc] = { arg0 };
- Add(format, Vector<FmtElm>(argv, argc));
+ Add(CStrVector(format), Vector<FmtElm>(argv, argc));
}
void StringStream::Add(const char* format, FmtElm arg0, FmtElm arg1) {
const char argc = 2;
FmtElm argv[argc] = { arg0, arg1 };
- Add(format, Vector<FmtElm>(argv, argc));
+ Add(CStrVector(format), Vector<FmtElm>(argv, argc));
}
@@ -203,7 +212,7 @@ void StringStream::Add(const char* format, FmtElm arg0, FmtElm arg1,
FmtElm arg2) {
const char argc = 3;
FmtElm argv[argc] = { arg0, arg1, arg2 };
- Add(format, Vector<FmtElm>(argv, argc));
+ Add(CStrVector(format), Vector<FmtElm>(argv, argc));
}
« src/parser.cc ('K') | « src/string-stream.h ('k') | test/cctest/SConscript » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698