Fix GetUtfLength to add offset to char array data.
GetUtfLength isn't used by much, so I made ToModifiedUtf8 use it so it
can be exercised more. Also added a test to make sure it's working.
Change-Id: I9d569642aaf2313cc70a2e22f631aec138e2e71b
diff --git a/src/object.h b/src/object.h
index 7ba0847..ad8194a 100644
--- a/src/object.h
+++ b/src/object.h
@@ -2216,7 +2216,7 @@
}
int32_t GetUtfLength() const {
- return CountUtf8Bytes(GetCharArray()->GetData(), GetLength());
+ return CountUtf8Bytes(GetCharArray()->GetData() + GetOffset(), GetLength());
}
uint16_t CharAt(int32_t index) const;
@@ -2297,6 +2297,7 @@
static Class* java_lang_String_;
friend struct StringOffsets; // for verifying offset information
+ FRIEND_TEST(ObjectTest, StringLength); // for SetOffset and SetCount
DISALLOW_IMPLICIT_CONSTRUCTORS(String);
};