summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-03 20:03:50 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-03 20:03:50 +0000
commit04866c4c67566d17cdea2e72eb90a6ec79db1a8b (patch)
tree0e14e8c1fa5bd77b6cba9b44b110426ec596be57 /base
parent623fe74c6c07104c2f09b9822af47813a81d2f1f (diff)
downloadchromium_src-04866c4c67566d17cdea2e72eb90a6ec79db1a8b.zip
chromium_src-04866c4c67566d17cdea2e72eb90a6ec79db1a8b.tar.gz
chromium_src-04866c4c67566d17cdea2e72eb90a6ec79db1a8b.tar.bz2
Eliminate wstring from base/utf_offset_string_conversions.h, net/base/escape.h, and net/base/net_util.h, and reduce the API surfaces in various places slightly where possible.
BUG=23581 TEST=none Review URL: http://codereview.chromium.org/6898026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83948 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/utf_offset_string_conversions.cc200
-rw-r--r--base/utf_offset_string_conversions.h76
-rw-r--r--base/utf_offset_string_conversions_unittest.cc148
3 files changed, 139 insertions, 285 deletions
diff --git a/base/utf_offset_string_conversions.cc b/base/utf_offset_string_conversions.cc
index 6f51ca9..e5f8c81 100644
--- a/base/utf_offset_string_conversions.cc
+++ b/base/utf_offset_string_conversions.cc
@@ -14,26 +14,23 @@ using base::PrepareForUTF16Or32Output;
using base::ReadUnicodeCharacter;
using base::WriteUnicodeCharacter;
-// Generalized Unicode converter -----------------------------------------------
-
// Converts the given source Unicode character type to the given destination
// Unicode character type as a STL string. The given input buffer and size
// determine the source, and the given output STL string will be replaced by
// the result.
-template<typename SRC_CHAR>
-bool ConvertUnicode(const SRC_CHAR* src,
+bool ConvertUnicode(const char* src,
size_t src_len,
- std::wstring* output,
+ string16* output,
std::vector<size_t>* offsets_for_adjustment) {
if (offsets_for_adjustment) {
std::for_each(offsets_for_adjustment->begin(),
offsets_for_adjustment->end(),
- LimitOffset<std::wstring>(src_len));
+ LimitOffset<string16>(src_len));
}
// ICU requires 32-bit numbers.
bool success = true;
- AdjustOffset::Adjustments adjustments;
+ OffsetAdjuster offset_adjuster(offsets_for_adjustment);
int32 src_len32 = static_cast<int32>(src_len);
for (int32 i = 0; i < src_len32; i++) {
uint32 code_point;
@@ -50,195 +47,98 @@ bool ConvertUnicode(const SRC_CHAR* src,
// character read, not after it (so that incrementing it in the loop
// increment will place it at the right location), so we need to account
// for that in determining the amount that was read.
- adjustments.push_back(AdjustOffset::Adjustment(
- original_i, i - original_i + 1, chars_written));
+ offset_adjuster.Add(OffsetAdjuster::Adjustment(original_i,
+ i - original_i + 1, chars_written));
}
}
-
- // Make offset adjustment.
- if (offsets_for_adjustment && !adjustments.empty()) {
- std::for_each(offsets_for_adjustment->begin(),
- offsets_for_adjustment->end(),
- AdjustOffset(adjustments));
- }
-
return success;
}
-// UTF-8 <-> Wide --------------------------------------------------------------
-
-bool UTF8ToWideAndAdjustOffset(const char* src,
- size_t src_len,
- std::wstring* output,
- size_t* offset_for_adjustment) {
- std::vector<size_t> offsets;
- if (offset_for_adjustment)
- offsets.push_back(*offset_for_adjustment);
- PrepareForUTF16Or32Output(src, src_len, output);
- bool ret = ConvertUnicode(src, src_len, output, &offsets);
- if (offset_for_adjustment)
- *offset_for_adjustment = offsets[0];
- return ret;
-}
-
-bool UTF8ToWideAndAdjustOffsets(const char* src,
- size_t src_len,
- std::wstring* output,
- std::vector<size_t>* offsets_for_adjustment) {
- PrepareForUTF16Or32Output(src, src_len, output);
- return ConvertUnicode(src, src_len, output, offsets_for_adjustment);
-}
-
-std::wstring UTF8ToWideAndAdjustOffset(const base::StringPiece& utf8,
- size_t* offset_for_adjustment) {
- std::vector<size_t> offsets;
- if (offset_for_adjustment)
- offsets.push_back(*offset_for_adjustment);
- std::wstring result;
- UTF8ToWideAndAdjustOffsets(utf8.data(), utf8.length(), &result,
- &offsets);
- if (offset_for_adjustment)
- *offset_for_adjustment = offsets[0];
- return result;
-}
-
-std::wstring UTF8ToWideAndAdjustOffsets(const base::StringPiece& utf8,
- std::vector<size_t>*
- offsets_for_adjustment) {
- std::wstring result;
- UTF8ToWideAndAdjustOffsets(utf8.data(), utf8.length(), &result,
- offsets_for_adjustment);
- return result;
-}
-
-// UTF-16 <-> Wide -------------------------------------------------------------
-
-#if defined(WCHAR_T_IS_UTF16)
-
-// When wide == UTF-16, then conversions are a NOP.
-bool UTF16ToWideAndAdjustOffset(const char16* src,
+bool UTF8ToUTF16AndAdjustOffset(const char* src,
size_t src_len,
- std::wstring* output,
- size_t* offset_for_adjustment) {
- output->assign(src, src_len);
- if (offset_for_adjustment && (*offset_for_adjustment >= src_len))
- *offset_for_adjustment = std::wstring::npos;
- return true;
-}
-
-bool UTF16ToWideAndAdjustOffsets(const char16* src,
- size_t src_len,
- std::wstring* output,
- std::vector<size_t>* offsets_for_adjustment) {
- output->assign(src, src_len);
- if (offsets_for_adjustment) {
- std::for_each(offsets_for_adjustment->begin(),
- offsets_for_adjustment->end(),
- LimitOffset<std::wstring>(src_len));
- }
- return true;
-}
-
-std::wstring UTF16ToWideAndAdjustOffset(const string16& utf16,
- size_t* offset_for_adjustment) {
- if (offset_for_adjustment && (*offset_for_adjustment >= utf16.length()))
- *offset_for_adjustment = std::wstring::npos;
- return utf16;
-}
-
-std::wstring UTF16ToWideAndAdjustOffsets(
- const string16& utf16,
- std::vector<size_t>* offsets_for_adjustment) {
- if (offsets_for_adjustment) {
- std::for_each(offsets_for_adjustment->begin(),
- offsets_for_adjustment->end(),
- LimitOffset<std::wstring>(utf16.length()));
- }
- return utf16;
-}
-
-#elif defined(WCHAR_T_IS_UTF32)
-
-bool UTF16ToWideAndAdjustOffset(const char16* src,
- size_t src_len,
- std::wstring* output,
+ string16* output,
size_t* offset_for_adjustment) {
std::vector<size_t> offsets;
if (offset_for_adjustment)
offsets.push_back(*offset_for_adjustment);
- output->clear();
- // Assume that normally we won't have any non-BMP characters so the counts
- // will be the same.
- output->reserve(src_len);
+ PrepareForUTF16Or32Output(src, src_len, output);
bool ret = ConvertUnicode(src, src_len, output, &offsets);
if (offset_for_adjustment)
*offset_for_adjustment = offsets[0];
return ret;
}
-bool UTF16ToWideAndAdjustOffsets(const char16* src,
+bool UTF8ToUTF16AndAdjustOffsets(const char* src,
size_t src_len,
- std::wstring* output,
+ string16* output,
std::vector<size_t>* offsets_for_adjustment) {
- output->clear();
- // Assume that normally we won't have any non-BMP characters so the counts
- // will be the same.
- output->reserve(src_len);
+ PrepareForUTF16Or32Output(src, src_len, output);
return ConvertUnicode(src, src_len, output, offsets_for_adjustment);
}
-std::wstring UTF16ToWideAndAdjustOffset(const string16& utf16,
+string16 UTF8ToUTF16AndAdjustOffset(const base::StringPiece& utf8,
size_t* offset_for_adjustment) {
std::vector<size_t> offsets;
if (offset_for_adjustment)
offsets.push_back(*offset_for_adjustment);
- std::wstring result;
- UTF16ToWideAndAdjustOffsets(utf16.data(), utf16.length(), &result,
+ string16 result;
+ UTF8ToUTF16AndAdjustOffsets(utf8.data(), utf8.length(), &result,
&offsets);
if (offset_for_adjustment)
*offset_for_adjustment = offsets[0];
return result;
}
-std::wstring UTF16ToWideAndAdjustOffsets(
- const string16& utf16,
+string16 UTF8ToUTF16AndAdjustOffsets(
+ const base::StringPiece& utf8,
std::vector<size_t>* offsets_for_adjustment) {
- std::wstring result;
- UTF16ToWideAndAdjustOffsets(utf16.data(), utf16.length(), &result,
+ string16 result;
+ UTF8ToUTF16AndAdjustOffsets(utf8.data(), utf8.length(), &result,
offsets_for_adjustment);
return result;
}
-#endif // defined(WCHAR_T_IS_UTF32)
+OffsetAdjuster::Adjustment::Adjustment(size_t original_offset,
+ size_t original_length,
+ size_t output_length)
+ : original_offset(original_offset),
+ original_length(original_length),
+ output_length(output_length) {
+}
+
+OffsetAdjuster::OffsetAdjuster(std::vector<size_t>* offsets_for_adjustment)
+ : offsets_for_adjustment_(offsets_for_adjustment) {
+}
-AdjustOffset::Adjustment::Adjustment(size_t location,
- size_t old_length,
- size_t new_length)
- : location(location),
- old_length(old_length),
- new_length(new_length) {}
+OffsetAdjuster::~OffsetAdjuster() {
+ if (!offsets_for_adjustment_ || adjustments_.empty())
+ return;
+ for (std::vector<size_t>::iterator i(offsets_for_adjustment_->begin());
+ i != offsets_for_adjustment_->end(); ++i)
+ AdjustOffset(i);
+}
-AdjustOffset::AdjustOffset(const Adjustments& adjustments)
- : adjustments_(adjustments) {}
+void OffsetAdjuster::Add(const Adjustment& adjustment) {
+ adjustments_.push_back(adjustment);
+}
-void AdjustOffset::operator()(size_t& offset) {
- if (offset == std::wstring::npos)
+void OffsetAdjuster::AdjustOffset(std::vector<size_t>::iterator offset) {
+ if (*offset == string16::npos)
return;
size_t adjustment = 0;
- for (Adjustments::const_iterator i = adjustments_.begin();
+ for (std::vector<Adjustment>::const_iterator i = adjustments_.begin();
i != adjustments_.end(); ++i) {
- size_t location = i->location;
- if (offset == location && i->new_length == 0) {
- offset = std::wstring::npos;
+ if (*offset == i->original_offset && i->output_length == 0) {
+ *offset = string16::npos;
return;
}
- if (offset <= location)
+ if (*offset <= i->original_offset)
break;
- if (offset < (location + i->old_length)) {
- offset = std::wstring::npos;
+ if (*offset < (i->original_offset + i->original_length)) {
+ *offset = string16::npos;
return;
}
- adjustment += (i->old_length - i->new_length);
+ adjustment += (i->original_length - i->output_length);
}
- offset -= adjustment;
+ *offset -= adjustment;
}
diff --git a/base/utf_offset_string_conversions.h b/base/utf_offset_string_conversions.h
index 76247a6..4c87f83 100644
--- a/base/utf_offset_string_conversions.h
+++ b/base/utf_offset_string_conversions.h
@@ -21,37 +21,21 @@ class StringPiece;
// will be adjusted to point at the same logical place in the result strings.
// If this isn't possible because an offset points past the end of the source
// strings or into the middle of a multibyte sequence, the offending offset will
-// be set to std::wstring::npos. |offset[s]_for_adjustment| may be NULL.
-BASE_API bool UTF8ToWideAndAdjustOffset(const char* src,
- size_t src_len,
- std::wstring* output,
- size_t* offset_for_adjustment);
-BASE_API bool UTF8ToWideAndAdjustOffsets(
- const char* src,
- size_t src_len,
- std::wstring* output,
- std::vector<size_t>* offsets_for_adjustment);
-
-BASE_API std::wstring UTF8ToWideAndAdjustOffset(const base::StringPiece& utf8,
- size_t* offset_for_adjustment);
-BASE_API std::wstring UTF8ToWideAndAdjustOffsets(
- const base::StringPiece& utf8,
- std::vector<size_t>* offsets_for_adjustment);
-
-BASE_API bool UTF16ToWideAndAdjustOffset(const char16* src,
+// be set to string16::npos. |offset[s]_for_adjustment| may be NULL.
+BASE_API bool UTF8ToUTF16AndAdjustOffset(const char* src,
size_t src_len,
- std::wstring* output,
+ string16* output,
size_t* offset_for_adjustment);
-BASE_API bool UTF16ToWideAndAdjustOffsets(
- const char16* src,
+BASE_API bool UTF8ToUTF16AndAdjustOffsets(
+ const char* src,
size_t src_len,
- std::wstring* output,
+ string16* output,
std::vector<size_t>* offsets_for_adjustment);
-BASE_API std::wstring UTF16ToWideAndAdjustOffset(const string16& utf16,
- size_t* offset_for_adjustment);
-BASE_API std::wstring UTF16ToWideAndAdjustOffsets(
- const string16& utf16,
+BASE_API string16 UTF8ToUTF16AndAdjustOffset(const base::StringPiece& utf8,
+ size_t* offset_for_adjustment);
+BASE_API string16 UTF8ToUTF16AndAdjustOffsets(
+ const base::StringPiece& utf8,
std::vector<size_t>* offsets_for_adjustment);
// Limiting function callable by std::for_each which will replace any value
@@ -69,30 +53,34 @@ struct LimitOffset {
size_t limit_;
};
-// Adjustment function called by std::transform which will adjust any offset
-// that occurs after one or more modified substrings. To use, create any
-// number of AdjustOffset::Adjustments, drop them into a vector, then call
-// std::transform with the transform function being something similar to
-// AdjustOffset(adjustments). Each Adjustment gives the original |location|
-// of the encoded section and the |old_length| and |new_length| of the section
-// before and after decoding.
-struct BASE_API AdjustOffset {
- // Helper structure which indicates where an encoded character occurred
- // and how long that encoding was.
+// Stack object which, on destruction, will update a vector of offsets based on
+// any supplied adjustments. To use, declare one of these, providing the
+// address of the offset vector to adjust. Then Add() any number of Adjustments
+// (each Adjustment gives the |original_offset| of a substring and the lengths
+// of the substring before and after transforming). When the OffsetAdjuster
+// goes out of scope, all the offsets in the provided vector will be updated.
+class BASE_API OffsetAdjuster {
+ public:
struct BASE_API Adjustment {
- Adjustment(size_t location, size_t old_length, size_t new_length);
+ Adjustment(size_t original_offset,
+ size_t original_length,
+ size_t output_length);
- size_t location;
- size_t old_length;
- size_t new_length;
+ size_t original_offset;
+ size_t original_length;
+ size_t output_length;
};
- typedef std::vector<Adjustment> Adjustments;
+ explicit OffsetAdjuster(std::vector<size_t>* offsets_for_adjustment);
+ ~OffsetAdjuster();
+
+ void Add(const Adjustment& adjustment);
- explicit AdjustOffset(const Adjustments& adjustments);
- void operator()(size_t& offset);
+ private:
+ void AdjustOffset(std::vector<size_t>::iterator offset);
- const Adjustments& adjustments_;
+ std::vector<size_t>* offsets_for_adjustment_;
+ std::vector<Adjustment> adjustments_;
};
#endif // BASE_UTF_OFFSET_STRING_CONVERSIONS_H_
diff --git a/base/utf_offset_string_conversions_unittest.cc b/base/utf_offset_string_conversions_unittest.cc
index b731b9e..1a56f9d 100644
--- a/base/utf_offset_string_conversions_unittest.cc
+++ b/base/utf_offset_string_conversions_unittest.cc
@@ -13,72 +13,29 @@ namespace base {
namespace {
-static const size_t kNpos = std::wstring::npos;
-
-// Given a null-terminated string of wchar_t with each wchar_t representing
-// a UTF-16 code unit, returns a string16 made up of wchar_t's in the input.
-// Each wchar_t should be <= 0xFFFF and a non-BMP character (> U+FFFF)
-// should be represented as a surrogate pair (two UTF-16 units)
-// *even* where wchar_t is 32-bit (Linux and Mac).
-//
-// This is to help write tests for functions with string16 params until
-// the C++ 0x UTF-16 literal is well-supported by compilers.
-string16 BuildString16(const wchar_t* s) {
-#if defined(WCHAR_T_IS_UTF16)
- return string16(s);
-#elif defined(WCHAR_T_IS_UTF32)
- string16 u16;
- while (*s != 0) {
- DCHECK(static_cast<unsigned int>(*s) <= 0xFFFFu);
- u16.push_back(*s++);
- }
- return u16;
-#endif
-}
+static const size_t kNpos = string16::npos;
} // namespace
TEST(UTFOffsetStringConversionsTest, AdjustOffset) {
- struct UTF8ToWideCase {
+ struct UTF8ToUTF16Case {
const char* utf8;
size_t input_offset;
size_t output_offset;
- } utf8_to_wide_cases[] = {
+ } utf8_to_utf16_cases[] = {
{"", 0, kNpos},
{"\xe4\xbd\xa0\xe5\xa5\xbd", 1, kNpos},
{"\xe4\xbd\xa0\xe5\xa5\xbd", 3, 1},
{"\xed\xb0\x80z", 3, 1},
{"A\xF0\x90\x8C\x80z", 1, 1},
{"A\xF0\x90\x8C\x80z", 2, kNpos},
-#if defined(WCHAR_T_IS_UTF16)
{"A\xF0\x90\x8C\x80z", 5, 3},
-#elif defined(WCHAR_T_IS_UTF32)
- {"A\xF0\x90\x8C\x80z", 5, 2},
-#endif
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(utf8_to_wide_cases); ++i) {
- size_t offset = utf8_to_wide_cases[i].input_offset;
- UTF8ToWideAndAdjustOffset(utf8_to_wide_cases[i].utf8, &offset);
- EXPECT_EQ(utf8_to_wide_cases[i].output_offset, offset);
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(utf8_to_utf16_cases); ++i) {
+ size_t offset = utf8_to_utf16_cases[i].input_offset;
+ UTF8ToUTF16AndAdjustOffset(utf8_to_utf16_cases[i].utf8, &offset);
+ EXPECT_EQ(utf8_to_utf16_cases[i].output_offset, offset);
}
-
-#if defined(WCHAR_T_IS_UTF32)
- struct UTF16ToWideCase {
- const wchar_t* wide;
- size_t input_offset;
- size_t output_offset;
- } utf16_to_wide_cases[] = {
- {L"\xD840\xDC00\x4E00", 0, 0},
- {L"\xD840\xDC00\x4E00", 1, kNpos},
- {L"\xD840\xDC00\x4E00", 2, 1},
- };
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(utf16_to_wide_cases); ++i) {
- size_t offset = utf16_to_wide_cases[i].input_offset;
- UTF16ToWideAndAdjustOffset(BuildString16(utf16_to_wide_cases[i].wide),
- &offset);
- EXPECT_EQ(utf16_to_wide_cases[i].output_offset, offset);
- }
-#endif
}
TEST(UTFOffsetStringConversionsTest, LimitOffsets) {
@@ -88,7 +45,7 @@ TEST(UTFOffsetStringConversionsTest, LimitOffsets) {
for (size_t t = 0; t < kItems; ++t)
size_ts.push_back(t);
std::for_each(size_ts.begin(), size_ts.end(),
- LimitOffset<std::wstring>(kLimit));
+ LimitOffset<string16>(kLimit));
size_t unlimited_count = 0;
for (std::vector<size_t>::iterator ti = size_ts.begin(); ti != size_ts.end();
++ti) {
@@ -102,7 +59,7 @@ TEST(UTFOffsetStringConversionsTest, LimitOffsets) {
for (size_t t = kItems; t > 0; --t)
size_ts.push_back(t - 1);
std::for_each(size_ts.begin(), size_ts.end(),
- LimitOffset<std::wstring>(kLimit));
+ LimitOffset<string16>(kLimit));
unlimited_count = 0;
for (std::vector<size_t>::iterator ti = size_ts.begin(); ti != size_ts.end();
++ti) {
@@ -116,49 +73,58 @@ TEST(UTFOffsetStringConversionsTest, AdjustOffsets) {
// Imagine we have strings as shown in the following cases where the
// X's represent encoded characters.
// 1: abcXXXdef ==> abcXdef
- std::vector<size_t> offsets;
- for (size_t t = 0; t < 9; ++t)
- offsets.push_back(t);
- AdjustOffset::Adjustments adjustments;
- adjustments.push_back(AdjustOffset::Adjustment(3, 3, 1));
- std::for_each(offsets.begin(), offsets.end(), AdjustOffset(adjustments));
- size_t expected_1[] = {0, 1, 2, 3, kNpos, kNpos, 4, 5, 6};
- EXPECT_EQ(offsets.size(), arraysize(expected_1));
- for (size_t i = 0; i < arraysize(expected_1); ++i)
- EXPECT_EQ(expected_1[i], offsets[i]);
+ {
+ std::vector<size_t> offsets;
+ for (size_t t = 0; t < 9; ++t)
+ offsets.push_back(t);
+ {
+ OffsetAdjuster offset_adjuster(&offsets);
+ offset_adjuster.Add(OffsetAdjuster::Adjustment(3, 3, 1));
+ }
+ size_t expected_1[] = {0, 1, 2, 3, kNpos, kNpos, 4, 5, 6};
+ EXPECT_EQ(offsets.size(), arraysize(expected_1));
+ for (size_t i = 0; i < arraysize(expected_1); ++i)
+ EXPECT_EQ(expected_1[i], offsets[i]);
+ }
// 2: XXXaXXXXbcXXXXXXXdefXXX ==> XaXXbcXXXXdefX
- offsets.clear();
- for (size_t t = 0; t < 23; ++t)
- offsets.push_back(t);
- adjustments.clear();
- adjustments.push_back(AdjustOffset::Adjustment(0, 3, 1));
- adjustments.push_back(AdjustOffset::Adjustment(4, 4, 2));
- adjustments.push_back(AdjustOffset::Adjustment(10, 7, 4));
- adjustments.push_back(AdjustOffset::Adjustment(20, 3, 1));
- std::for_each(offsets.begin(), offsets.end(), AdjustOffset(adjustments));
- size_t expected_2[] = {0, kNpos, kNpos, 1, 2, kNpos, kNpos, kNpos, 4, 5, 6,
- kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 10, 11, 12,
- 13, kNpos, kNpos};
- EXPECT_EQ(offsets.size(), arraysize(expected_2));
- for (size_t i = 0; i < arraysize(expected_2); ++i)
- EXPECT_EQ(expected_2[i], offsets[i]);
+ {
+ std::vector<size_t> offsets;
+ for (size_t t = 0; t < 23; ++t)
+ offsets.push_back(t);
+ {
+ OffsetAdjuster offset_adjuster(&offsets);
+ offset_adjuster.Add(OffsetAdjuster::Adjustment(0, 3, 1));
+ offset_adjuster.Add(OffsetAdjuster::Adjustment(4, 4, 2));
+ offset_adjuster.Add(OffsetAdjuster::Adjustment(10, 7, 4));
+ offset_adjuster.Add(OffsetAdjuster::Adjustment(20, 3, 1));
+ }
+ size_t expected_2[] = {0, kNpos, kNpos, 1, 2, kNpos, kNpos, kNpos, 4, 5, 6,
+ kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 10, 11, 12,
+ 13, kNpos, kNpos};
+ EXPECT_EQ(offsets.size(), arraysize(expected_2));
+ for (size_t i = 0; i < arraysize(expected_2); ++i)
+ EXPECT_EQ(expected_2[i], offsets[i]);
+ }
// 3: XXXaXXXXbcdXXXeXX ==> aXXXXbcdXXXe
- offsets.clear();
- for (size_t t = 0; t < 17; ++t)
- offsets.push_back(t);
- adjustments.clear();
- adjustments.push_back(AdjustOffset::Adjustment(0, 3, 0));
- adjustments.push_back(AdjustOffset::Adjustment(4, 4, 4));
- adjustments.push_back(AdjustOffset::Adjustment(11, 3, 3));
- adjustments.push_back(AdjustOffset::Adjustment(15, 2, 0));
- std::for_each(offsets.begin(), offsets.end(), AdjustOffset(adjustments));
- size_t expected_3[] = {kNpos, kNpos, kNpos, 0, 1, kNpos, kNpos, kNpos, 5, 6,
- 7, 8, kNpos, kNpos, 11, kNpos, kNpos};
- EXPECT_EQ(offsets.size(), arraysize(expected_3));
- for (size_t i = 0; i < arraysize(expected_3); ++i)
- EXPECT_EQ(expected_3[i], offsets[i]);
+ {
+ std::vector<size_t> offsets;
+ for (size_t t = 0; t < 17; ++t)
+ offsets.push_back(t);
+ {
+ OffsetAdjuster offset_adjuster(&offsets);
+ offset_adjuster.Add(OffsetAdjuster::Adjustment(0, 3, 0));
+ offset_adjuster.Add(OffsetAdjuster::Adjustment(4, 4, 4));
+ offset_adjuster.Add(OffsetAdjuster::Adjustment(11, 3, 3));
+ offset_adjuster.Add(OffsetAdjuster::Adjustment(15, 2, 0));
+ }
+ size_t expected_3[] = {kNpos, kNpos, kNpos, 0, 1, kNpos, kNpos, kNpos, 5, 6,
+ 7, 8, kNpos, kNpos, 11, kNpos, kNpos};
+ EXPECT_EQ(offsets.size(), arraysize(expected_3));
+ for (size_t i = 0; i < arraysize(expected_3); ++i)
+ EXPECT_EQ(expected_3[i], offsets[i]);
+ }
}
} // namaspace base