summaryrefslogtreecommitdiff
path: root/runtime/mirror/string-inl.h
diff options
context:
space:
mode:
author Narayan Kamath <narayan@google.com> 2015-01-29 20:06:46 +0000
committer Narayan Kamath <narayan@google.com> 2015-02-12 11:54:37 +0000
commita5afcfc73141e5e378d79a326d02c5c2039fb025 (patch)
tree424add9558fb816c4f1d2f4edd128f4f2a086d9a /runtime/mirror/string-inl.h
parent5a3399deaf448c8434d9ba0916ff799b1b791d95 (diff)
Be more lenient with 4 byte UTF-8 sequences.
Accept 4 byte sequences and convert them into surrogate pairs instead of expecting 2 separate 3 byte sequences each encoding one half of a surrogate pair. Note that in addition to supporting 4 byte sequences in strings from JNI, we also tolerate them in dex files. This is mainly for consistency, and there's no need to claim any sort of official support. bug: 18848397 bug: https://code.google.com/p/android/issues/detail?id=81341 Change-Id: Ibc98d29e59d98803e640f2489ea4c56912a59b29
Diffstat (limited to 'runtime/mirror/string-inl.h')
-rw-r--r--runtime/mirror/string-inl.h18
1 files changed, 4 insertions, 14 deletions
diff --git a/runtime/mirror/string-inl.h b/runtime/mirror/string-inl.h
index 14d7de2ffb..4a95519bd0 100644
--- a/runtime/mirror/string-inl.h
+++ b/runtime/mirror/string-inl.h
@@ -33,6 +33,10 @@ inline uint32_t String::ClassSize() {
return Class::ComputeClassSize(true, vtable_entries, 0, 1, 0, 1, 2);
}
+inline uint16_t String::UncheckedCharAt(int32_t index) {
+ return GetCharArray()->Get(index + GetOffset());
+}
+
inline CharArray* String::GetCharArray() {
return GetFieldObject<CharArray>(ValueOffset());
}
@@ -54,20 +58,6 @@ inline String* String::Intern() {
return Runtime::Current()->GetInternTable()->InternWeak(this);
}
-inline uint16_t String::CharAt(int32_t index) {
- // TODO: do we need this? Equals is the only caller, and could
- // bounds check itself.
- DCHECK_GE(count_, 0); // ensures the unsigned comparison is safe.
- if (UNLIKELY(static_cast<uint32_t>(index) >= static_cast<uint32_t>(count_))) {
- Thread* self = Thread::Current();
- ThrowLocation throw_location = self->GetCurrentLocationForThrow();
- self->ThrowNewExceptionF(throw_location, "Ljava/lang/StringIndexOutOfBoundsException;",
- "length=%i; index=%i", count_, index);
- return 0;
- }
- return GetCharArray()->Get(index + GetOffset());
-}
-
inline int32_t String::GetHashCode() {
int32_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(String, hash_code_));
if (UNLIKELY(result == 0)) {