Chromium Code Reviews| Index: base/utf_offset_string_conversions.cc |
| diff --git a/base/utf_offset_string_conversions.cc b/base/utf_offset_string_conversions.cc |
| index 26d28f55233720242a46a26b96c715dc725d2ee1..a02236ee4d4568968f5038c588d1e65a3852f868 100644 |
| --- a/base/utf_offset_string_conversions.cc |
| +++ b/base/utf_offset_string_conversions.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/utf_string_conversion_utils.h" |
| using base::PrepareForUTF16Or32Output; |
| +using base::PrepareForUTF8Output; |
| using base::ReadUnicodeCharacter; |
| using base::WriteUnicodeCharacter; |
| @@ -18,14 +19,15 @@ using base::WriteUnicodeCharacter; |
| // 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. |
| -bool ConvertUnicode(const char* src, |
| +template<typename SrcChar, typename DestStdString> |
| +bool ConvertUnicode(const SrcChar* src, |
| size_t src_len, |
| - string16* output, |
| + DestStdString* output, |
| std::vector<size_t>* offsets_for_adjustment) { |
| if (offsets_for_adjustment) { |
| std::for_each(offsets_for_adjustment->begin(), |
| offsets_for_adjustment->end(), |
| - LimitOffset<string16>(src_len)); |
| + LimitOffset<DestStdString>(src_len)); |
| } |
| // ICU requires 32-bit numbers. |
| @@ -98,6 +100,30 @@ string16 UTF8ToUTF16AndAdjustOffsets( |
| return result; |
| } |
| +std::string UTF16ToUTF8AndAdjustOffset( |
| + const base::StringPiece16& utf16, |
| + size_t* offset_for_adjustment) { |
| + std::vector<size_t> offsets; |
| + if (offset_for_adjustment) |
| + offsets.push_back(*offset_for_adjustment); |
| + std::string result; |
|
brettw
2011/09/07 19:28:07
The 8->16 version above just calls the vector vers
kinaba
2011/09/07 19:54:47
Done.
|
| + PrepareForUTF8Output(utf16.data(), utf16.length(), &result); |
| + ConvertUnicode(utf16.data(), utf16.length(), &result, &offsets); |
| + if (offset_for_adjustment) |
| + *offset_for_adjustment = offsets[0]; |
| + return result; |
| +} |
| + |
| +std::string UTF16ToUTF8AndAdjustOffsets( |
| + const base::StringPiece16& utf16, |
| + std::vector<size_t>* offsets_for_adjustment) { |
| + std::string result; |
| + PrepareForUTF8Output(utf16.data(), utf16.length(), &result); |
| + ConvertUnicode(utf16.data(), utf16.length(), &result, offsets_for_adjustment); |
| + return result; |
| +} |
| + |
|
brettw
2011/09/07 19:28:07
Only one blank line needed.
kinaba
2011/09/07 19:54:47
Done.
|
| + |
| OffsetAdjuster::Adjustment::Adjustment(size_t original_offset, |
| size_t original_length, |
| size_t output_length) |