Commit 5f77a604 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Introduce TextIteratorTextState::GetTextForTesting() as replacement of Substring()

This patch introduces |TextIteratorTextState::GetTextForTesting()| as
replacement of |Substring()|, because it is called only one place and it takes
whole text, for improving code health.

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: Id71f35c82c1906dfea9503a77506a6a437246bae
Reviewed-on: https://chromium-review.googlesource.com/1125584Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572519}
parent 973e9ee0
...@@ -123,8 +123,7 @@ std::string TextIteratorTest::IterateWithIterator( ...@@ -123,8 +123,7 @@ std::string TextIteratorTest::IterateWithIterator(
String text_chunks; String text_chunks;
for (; !iterator.AtEnd(); iterator.Advance()) { for (; !iterator.AtEnd(); iterator.Advance()) {
text_chunks.append('['); text_chunks.append('[');
text_chunks.append( text_chunks.append(iterator.GetText().GetTextForTesting());
iterator.GetText().Substring(0, iterator.GetText().length()));
text_chunks.append(']'); text_chunks.append(']');
} }
return std::string(text_chunks.Utf8().data()); return std::string(text_chunks.Utf8().data());
......
...@@ -73,18 +73,10 @@ UChar TextIteratorTextState::CharacterAt(unsigned index) const { ...@@ -73,18 +73,10 @@ UChar TextIteratorTextState::CharacterAt(unsigned index) const {
return text_[text_start_offset_ + index]; return text_[text_start_offset_ + index];
} }
String TextIteratorTextState::Substring(unsigned position, String TextIteratorTextState::GetTextForTesting() const {
unsigned length) const { if (single_character_buffer_)
SECURITY_DCHECK(position <= this->length());
SECURITY_DCHECK(position + length <= this->length());
if (!length)
return g_empty_string;
if (single_character_buffer_) {
DCHECK_EQ(position, 0u);
DCHECK_EQ(length, 1u);
return String(&single_character_buffer_, 1); return String(&single_character_buffer_, 1);
} return text_.Substring(text_start_offset_, length());
return text_.Substring(text_start_offset_ + position, length);
} }
void TextIteratorTextState::AppendTextToStringBuilder( void TextIteratorTextState::AppendTextToStringBuilder(
......
...@@ -49,7 +49,7 @@ class CORE_EXPORT TextIteratorTextState { ...@@ -49,7 +49,7 @@ class CORE_EXPORT TextIteratorTextState {
// Return properties of the current text. // Return properties of the current text.
unsigned length() const { return text_length_; } unsigned length() const { return text_length_; }
UChar CharacterAt(unsigned index) const; UChar CharacterAt(unsigned index) const;
String Substring(unsigned position, unsigned length) const; String GetTextForTesting() const;
void AppendTextToStringBuilder(StringBuilder&, void AppendTextToStringBuilder(StringBuilder&,
unsigned position = 0, unsigned position = 0,
unsigned max_length = UINT_MAX) const; unsigned max_length = UINT_MAX) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment