OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_STRINGS_UTF_OFFSET_STRING_CONVERSIONS_H_ | 5 #ifndef BASE_STRINGS_UTF_OFFSET_STRING_CONVERSIONS_H_ |
6 #define BASE_STRINGS_UTF_OFFSET_STRING_CONVERSIONS_H_ | 6 #define BASE_STRINGS_UTF_OFFSET_STRING_CONVERSIONS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... | |
37 std::vector<size_t>* offsets_for_adjustment); | 37 std::vector<size_t>* offsets_for_adjustment); |
38 | 38 |
39 BASE_EXPORT std::string UTF16ToUTF8AndAdjustOffset( | 39 BASE_EXPORT std::string UTF16ToUTF8AndAdjustOffset( |
40 const base::StringPiece16& utf16, | 40 const base::StringPiece16& utf16, |
41 size_t* offset_for_adjustment); | 41 size_t* offset_for_adjustment); |
42 BASE_EXPORT std::string UTF16ToUTF8AndAdjustOffsets( | 42 BASE_EXPORT std::string UTF16ToUTF8AndAdjustOffsets( |
43 const base::StringPiece16& utf16, | 43 const base::StringPiece16& utf16, |
44 std::vector<size_t>* offsets_for_adjustment); | 44 std::vector<size_t>* offsets_for_adjustment); |
45 | 45 |
46 // Limiting function callable by std::for_each which will replace any value | 46 // Limiting function callable by std::for_each which will replace any value |
47 // which is equal to or greater than |limit| with npos. | 47 // which is greater than |limit| with npos. |
msw
2013/09/04 23:58:50
I share Will's concern that other callers might ha
Peter Kasting
2013/09/05 20:11:59
See bug 284781 comment 16 for the full description
| |
48 template <typename T> | 48 template <typename T> |
49 struct LimitOffset { | 49 struct LimitOffset { |
50 explicit LimitOffset(size_t limit) | 50 explicit LimitOffset(size_t limit) |
51 : limit_(limit) {} | 51 : limit_(limit) {} |
52 | 52 |
53 void operator()(size_t& offset) { | 53 void operator()(size_t& offset) { |
54 if (offset >= limit_) | 54 if (offset > limit_) |
55 offset = T::npos; | 55 offset = T::npos; |
56 } | 56 } |
57 | 57 |
58 size_t limit_; | 58 size_t limit_; |
59 }; | 59 }; |
60 | 60 |
61 // Stack object which, on destruction, will update a vector of offsets based on | 61 // Stack object which, on destruction, will update a vector of offsets based on |
62 // any supplied adjustments. To use, declare one of these, providing the | 62 // any supplied adjustments. To use, declare one of these, providing the |
63 // address of the offset vector to adjust. Then Add() any number of Adjustments | 63 // address of the offset vector to adjust. Then Add() any number of Adjustments |
64 // (each Adjustment gives the |original_offset| of a substring and the lengths | 64 // (each Adjustment gives the |original_offset| of a substring and the lengths |
(...skipping 19 matching lines...) Expand all Loading... | |
84 private: | 84 private: |
85 void AdjustOffset(std::vector<size_t>::iterator offset); | 85 void AdjustOffset(std::vector<size_t>::iterator offset); |
86 | 86 |
87 std::vector<size_t>* offsets_for_adjustment_; | 87 std::vector<size_t>* offsets_for_adjustment_; |
88 std::vector<Adjustment> adjustments_; | 88 std::vector<Adjustment> adjustments_; |
89 }; | 89 }; |
90 | 90 |
91 } // namespace base | 91 } // namespace base |
92 | 92 |
93 #endif // BASE_STRINGS_UTF_OFFSET_STRING_CONVERSIONS_H_ | 93 #endif // BASE_STRINGS_UTF_OFFSET_STRING_CONVERSIONS_H_ |
OLD | NEW |