diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-03 20:03:50 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-03 20:03:50 +0000 |
commit | 04866c4c67566d17cdea2e72eb90a6ec79db1a8b (patch) | |
tree | 0e14e8c1fa5bd77b6cba9b44b110426ec596be57 /base/utf_offset_string_conversions.h | |
parent | 623fe74c6c07104c2f09b9822af47813a81d2f1f (diff) | |
download | chromium_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/utf_offset_string_conversions.h')
-rw-r--r-- | base/utf_offset_string_conversions.h | 76 |
1 files changed, 32 insertions, 44 deletions
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_ |