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

Unified Diff: runtime/vm/object.cc

Issue 8333001: Implement case mapping using the Unicode default case mapping algorithm. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Renamed result string variables. Created 9 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/unicode.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index ca04df567c082a3df3ca1581cecfeb6a687f5a59..d871ab0906e91aa8d6ce30d2042410bd7f98ff15 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -5721,6 +5721,48 @@ const char* String::ToCString() const {
}
+RawString* String::Transform(int32_t (*mapping)(int32_t ch),
+ const String& str,
+ Heap::Space space) {
+ ASSERT(!str.IsNull());
+ bool has_mapping = false;
+ int32_t dst_max = 0;
+ intptr_t len = str.Length();
+ // TODO(cshapiro): assume a transform is required, rollback if not.
+ for (intptr_t i = 0; i < len; ++i) {
+ int32_t src = str.CharAt(i);
+ int32_t dst = mapping(src);
+ if (src != dst) {
+ has_mapping = true;
+ }
+ dst_max = Utils::Maximum(dst_max, dst);
+ }
+ if (!has_mapping) {
+ return str.raw();
+ }
+ if (dst_max <= 0xFF) {
+ return OneByteString::Transform(mapping, str, space);
+ }
+ if (dst_max <= 0xFFFF) {
+ return TwoByteString::Transform(mapping, str, space);
+ }
+ ASSERT(dst_max > 0xFFFF);
+ return FourByteString::Transform(mapping, str, space);
+}
+
+
+RawString* String::ToUpperCase(const String& str, Heap::Space space) {
+ // TODO(cshapiro): create a fast-path for OneByteString instances.
+ return Transform(CaseMapping::ToUpper, str, space);
+}
+
+
+RawString* String::ToLowerCase(const String& str, Heap::Space space) {
+ // TODO(cshapiro): create a fast-path for OneByteString instances.
+ return Transform(CaseMapping::ToLower, str, space);
+}
+
+
RawOneByteString* OneByteString::New(intptr_t len,
Heap::Space space) {
Isolate* isolate = Isolate::Current();
@@ -5823,6 +5865,22 @@ RawOneByteString* OneByteString::SubString(const OneByteString& str,
}
+RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch),
+ const String& str,
+ Heap::Space space) {
+ ASSERT(!str.IsNull());
+ intptr_t len = str.Length();
+ const OneByteString& result =
+ OneByteString::Handle(OneByteString::New(len, space));
+ for (intptr_t i = 0; i < len; ++i) {
+ int32_t ch = mapping(str.CharAt(i));
+ ASSERT(ch >= 0 && ch <= 0xFF);
+ *result.CharAddr(i) = ch;
+ }
+ return result.raw();
+}
+
+
const char* OneByteString::ToCString() const {
return String::ToCString();
}
@@ -5922,12 +5980,27 @@ RawTwoByteString* TwoByteString::SubString(const TwoByteString& str,
}
+RawTwoByteString* TwoByteString::Transform(int32_t (*mapping)(int32_t ch),
+ const String& str,
+ Heap::Space space) {
+ ASSERT(!str.IsNull());
+ intptr_t len = str.Length();
+ const TwoByteString& result =
+ TwoByteString::Handle(TwoByteString::New(len, space));
+ for (intptr_t i = 0; i < len; ++i) {
+ int32_t ch = mapping(str.CharAt(i));
+ ASSERT(ch >= 0 && ch <= 0xFFFF);
+ *result.CharAddr(i) = ch;
+ }
+ return result.raw();
+}
+
+
const char* TwoByteString::ToCString() const {
return String::ToCString();
}
-
RawFourByteString* FourByteString::New(intptr_t len,
Heap::Space space) {
Isolate* isolate = Isolate::Current();
@@ -6014,6 +6087,22 @@ RawFourByteString* FourByteString::SubString(const FourByteString& str,
}
+RawFourByteString* FourByteString::Transform(int32_t (*mapping)(int32_t ch),
+ const String& str,
+ Heap::Space space) {
+ ASSERT(!str.IsNull());
+ intptr_t len = str.Length();
+ const FourByteString& result =
+ FourByteString::Handle(FourByteString::New(len, space));
+ for (intptr_t i = 0; i < len; ++i) {
+ int32_t ch = mapping(str.CharAt(i));
+ ASSERT(ch >= 0 && ch <= 0x10FFFF);
+ *result.CharAddr(i) = ch;
+ }
+ return result.raw();
+}
+
+
const char* FourByteString::ToCString() const {
return String::ToCString();
}
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/unicode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698