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

Unified Diff: src/api.cc

Issue 11852019: Prepare API for webkit use of Latin-1 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Changed mind Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 0563443b8bdf1248a2b3bf78bd837bceb406c6d2..1d577257674b62a48273dc55d5fc1240cfc44b34 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -3893,6 +3893,15 @@ bool String::MayContainNonAscii() const {
}
+bool String::IsOneByte() const {
+ i::Handle<i::String> str = Utils::OpenHandle(this);
+ if (IsDeadCheck(str->GetIsolate(), "v8::String::MayContainNonAscii()")) {
Yang 2013/01/14 11:21:38 This should reflect the method name since this str
+ return false;
+ }
+ return str->IsOneByteConvertible();
+}
+
+
class Utf8LengthVisitor {
public:
explicit Utf8LengthVisitor()
@@ -4194,32 +4203,52 @@ int String::WriteAscii(char* buffer,
}
+template<typename CharType>
+struct WriteHelper {
+ static inline int Write(const String* string,
+ CharType* buffer,
+ int start,
+ int length,
+ int options) {
+ i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate();
+ if (IsDeadCheck(isolate, "v8::String::Write()")) return 0;
+ LOG_API(isolate, "String::Write");
+ ENTER_V8(isolate);
+ ASSERT(start >= 0 && length >= -1);
+ i::Handle<i::String> str = Utils::OpenHandle(string);
+ isolate->string_tracker()->RecordWrite(str);
+ if (options & String::HINT_MANY_WRITES_EXPECTED) {
+ // Flatten the string for efficiency. This applies whether we are
+ // using StringCharacterStream or Get(i) to access the characters.
+ FlattenString(str);
+ }
+ int end = start + length;
+ if ((length == -1) || (length > str->length() - start) )
+ end = str->length();
+ if (end < 0) return 0;
+ i::String::WriteToFlat(*str, buffer, start, end);
+ if (!(options & String::NO_NULL_TERMINATION) &&
+ (length == -1 || end - start < length)) {
+ buffer[end - start] = '\0';
+ }
+ return end - start;
+ }
+};
+
+
+int String::WriteOneByte(uint8_t* buffer,
+ int start,
+ int length,
+ int options) const {
+ return WriteHelper<uint8_t>::Write(this, buffer, start, length, options);
+}
+
+
int String::Write(uint16_t* buffer,
int start,
int length,
int options) const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- if (IsDeadCheck(isolate, "v8::String::Write()")) return 0;
- LOG_API(isolate, "String::Write");
- ENTER_V8(isolate);
- ASSERT(start >= 0 && length >= -1);
- i::Handle<i::String> str = Utils::OpenHandle(this);
- isolate->string_tracker()->RecordWrite(str);
- if (options & HINT_MANY_WRITES_EXPECTED) {
- // Flatten the string for efficiency. This applies whether we are
- // using StringCharacterStream or Get(i) to access the characters.
- FlattenString(str);
- }
- int end = start + length;
- if ((length == -1) || (length > str->length() - start) )
- end = str->length();
- if (end < 0) return 0;
- i::String::WriteToFlat(*str, buffer, start, end);
- if (!(options & NO_NULL_TERMINATION) &&
- (length == -1 || end - start < length)) {
- buffer[end - start] = '\0';
- }
- return end - start;
+ return WriteHelper<uint16_t>::Write(this, buffer, start, length, options);
}
« no previous file with comments | « include/v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698