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_UTF_OFFSET_STRING_CONVERSIONS_H_ | 5 #ifndef BASE_UTF_OFFSET_STRING_CONVERSIONS_H_ |
6 #define BASE_UTF_OFFSET_STRING_CONVERSIONS_H_ | 6 #define BASE_UTF_OFFSET_STRING_CONVERSIONS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 size_t limit_; | 69 size_t limit_; |
70 }; | 70 }; |
71 | 71 |
72 // Adjustment function called by std::transform which will adjust any offset | 72 // Adjustment function called by std::transform which will adjust any offset |
73 // that occurs after one or more modified substrings. To use, create any | 73 // that occurs after one or more modified substrings. To use, create any |
74 // number of AdjustOffset::Adjustments, drop them into a vector, then call | 74 // number of AdjustOffset::Adjustments, drop them into a vector, then call |
75 // std::transform with the transform function being something similar to | 75 // std::transform with the transform function being something similar to |
76 // AdjustOffset(adjustments). Each Adjustment gives the original |location| | 76 // AdjustOffset(adjustments). Each Adjustment gives the original |location| |
77 // of the encoded section and the |old_length| and |new_length| of the section | 77 // of the encoded section and the |old_length| and |new_length| of the section |
78 // before and after decoding. | 78 // before and after decoding. |
79 struct AdjustOffset { | 79 struct BASE_API AdjustOffset { |
80 // Helper structure which indicates where an encoded character occurred | 80 // Helper structure which indicates where an encoded character occurred |
81 // and how long that encoding was. | 81 // and how long that encoding was. |
82 struct Adjustment { | 82 struct BASE_API Adjustment { |
83 Adjustment(size_t location, size_t old_length, size_t new_length); | 83 Adjustment(size_t location, size_t old_length, size_t new_length); |
84 | 84 |
85 size_t location; | 85 size_t location; |
86 size_t old_length; | 86 size_t old_length; |
87 size_t new_length; | 87 size_t new_length; |
88 }; | 88 }; |
89 | 89 |
90 typedef std::vector<Adjustment> Adjustments; | 90 typedef std::vector<Adjustment> Adjustments; |
91 | 91 |
92 explicit AdjustOffset(const Adjustments& adjustments); | 92 explicit AdjustOffset(const Adjustments& adjustments); |
93 void operator()(size_t& offset); | 93 void operator()(size_t& offset); |
94 | 94 |
95 const Adjustments& adjustments_; | 95 const Adjustments& adjustments_; |
96 }; | 96 }; |
97 | 97 |
98 #endif // BASE_UTF_OFFSET_STRING_CONVERSIONS_H_ | 98 #endif // BASE_UTF_OFFSET_STRING_CONVERSIONS_H_ |
OLD | NEW |