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

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: 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
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index ca04df567c082a3df3ca1581cecfeb6a687f5a59..266ce0fecccf1aac1bcebb1fcd0d605e6076c6d2 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -5072,6 +5072,12 @@ int32_t String::CharAt(intptr_t index) const {
}
+void String::SetCharAt(intptr_t index, int32_t value) const {
+ // String is an abstract class.
+ UNREACHABLE();
+}
+
+
bool String::Equals(const Instance& other) const {
if (this->raw() == other.raw()) {
// Both handles point to the same raw instance.
@@ -5721,6 +5727,61 @@ const char* String::ToCString() const {
}
+template<typename T>
+static RawString* CaseMappingImpl(T mapping,
+ const String& str,
+ Heap::Space space) {
+ ASSERT(!str.IsNull());
Ivan Posva 2011/10/18 22:01:13 Please add a TODO in this function that outlines s
cshapiro 2011/10/20 02:35:05 Done. I have added a TODO here about speculation.
+ bool has_mapping = false;
+ int32_t dst_max = -1;
+ intptr_t len = str.Length();
+ 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) {
+ const OneByteString& onestr =
+ OneByteString::Handle(OneByteString::New(len, space));
+ for (intptr_t i = 0; i < len; ++i) {
+ onestr.SetCharAt(i, mapping(str.CharAt(i)));
+ }
+ return onestr.raw();
+ }
+ if (dst_max <= 0xFFFF) {
+ const TwoByteString& twostr =
+ TwoByteString::Handle(TwoByteString::New(len, space));
+ for (intptr_t i = 0; i < len; ++i) {
+ twostr.SetCharAt(i, mapping(str.CharAt(i)));
+ }
+ return twostr.raw();
+ }
+ ASSERT(dst_max > 0xFFFF);
+ const FourByteString& fourstr =
+ FourByteString::Handle(FourByteString::New(len, space));
+ for (intptr_t i = 0; i < len; ++i) {
+ fourstr.SetCharAt(i, mapping(str.CharAt(i)));
+ }
+ return fourstr.raw();
+}
+
+
+RawString* String::ToUpperCase(const String& str, Heap::Space space) {
+ return CaseMappingImpl(CaseMapping::ToUpper, str, space);
+}
+
+
+RawString* String::ToLowerCase(const String& str, Heap::Space space) {
+ return CaseMappingImpl(CaseMapping::ToLower, str, space);
+}
+
+
RawOneByteString* OneByteString::New(intptr_t len,
Heap::Space space) {
Isolate* isolate = Isolate::Current();

Powered by Google App Engine
This is Rietveld 408576698