summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/mirror/string-inl.h5
-rw-r--r--test/021-string2/expected.txt4
-rw-r--r--test/021-string2/src/Main.java25
3 files changed, 33 insertions, 1 deletions
diff --git a/runtime/mirror/string-inl.h b/runtime/mirror/string-inl.h
index 6870fda075..95516ace9f 100644
--- a/runtime/mirror/string-inl.h
+++ b/runtime/mirror/string-inl.h
@@ -305,8 +305,11 @@ inline int32_t String::GetHashCode() {
template<typename MemoryType>
bool String::AllASCII(const MemoryType* const chars, const int length) {
+ static_assert(std::is_unsigned<MemoryType>::value, "Expecting unsigned MemoryType");
for (int i = 0; i < length; ++i) {
- if (chars[i] >= 0x80) {
+ // Valid ASCII characters are in range 1..0x7f. Zero is not considered ASCII
+ // because it would complicate the detection of ASCII strings in Modified-UTF8.
+ if ((chars[i] - 1u) >= 0x7fu) {
return false;
}
}
diff --git a/test/021-string2/expected.txt b/test/021-string2/expected.txt
index a9c6eb87bd..f269c7cf3e 100644
--- a/test/021-string2/expected.txt
+++ b/test/021-string2/expected.txt
@@ -1,2 +1,6 @@
Got expected npe
OK
+ true true true true
+ true true true true
+ true true true true
+ true true true true
diff --git a/test/021-string2/src/Main.java b/test/021-string2/src/Main.java
index 51351e1835..df0a3ddf48 100644
--- a/test/021-string2/src/Main.java
+++ b/test/021-string2/src/Main.java
@@ -92,6 +92,31 @@ public class Main {
testCompareToAndEquals();
testIndexOf();
+
+ String s0_0 = "\u0000";
+ String s0_1 = new String(s0_0);
+ String s0_2 = new String(new char[] { '\u0000' });
+ String s0_3 = s0_0 + "";
+ System.out.println(
+ " " + $noinline$equals(s0_0, s0_0) +
+ " " + $noinline$equals(s0_0, s0_1) +
+ " " + $noinline$equals(s0_0, s0_2) +
+ " " + $noinline$equals(s0_0, s0_3));
+ System.out.println(
+ " " + $noinline$equals(s0_1, s0_0) +
+ " " + $noinline$equals(s0_1, s0_1) +
+ " " + $noinline$equals(s0_1, s0_2) +
+ " " + $noinline$equals(s0_1, s0_3));
+ System.out.println(
+ " " + $noinline$equals(s0_2, s0_0) +
+ " " + $noinline$equals(s0_2, s0_1) +
+ " " + $noinline$equals(s0_2, s0_2) +
+ " " + $noinline$equals(s0_2, s0_3));
+ System.out.println(
+ " " + $noinline$equals(s0_3, s0_0) +
+ " " + $noinline$equals(s0_3, s0_1) +
+ " " + $noinline$equals(s0_3, s0_2) +
+ " " + $noinline$equals(s0_3, s0_3));
}
public static void testCompareToAndEquals() {