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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // adjusted (e.g., because it points into the middle of a multibyte sequence), | 42 // adjusted (e.g., because it points into the middle of a multibyte sequence), |
43 // it will be set to string16::npos. | 43 // it will be set to string16::npos. |
44 static void AdjustOffsets(const Adjustments& adjustments, | 44 static void AdjustOffsets(const Adjustments& adjustments, |
45 std::vector<size_t>* offsets_for_adjustment); | 45 std::vector<size_t>* offsets_for_adjustment); |
46 | 46 |
47 // Adjusts the single |offset| to reflect the adjustments recorded in | 47 // Adjusts the single |offset| to reflect the adjustments recorded in |
48 // |adjustments|. | 48 // |adjustments|. |
49 static void AdjustOffset(const Adjustments& adjustments, | 49 static void AdjustOffset(const Adjustments& adjustments, |
50 size_t* offset); | 50 size_t* offset); |
51 | 51 |
| 52 // Adjusts all offsets in |offsets_for_unadjustment| to reflect the reverse |
| 53 // of the adjustments recorded in |adjustments|. In other words, the offsets |
| 54 // provided represent offsets into an adjusted string and the caller wants |
| 55 // to know the offsets they correspond to in the original string. If an |
| 56 // offset cannot be successfully unadjusted (e.g., because it points into |
| 57 // the middle of a multibyte sequence), it will be set to string16::npos. |
| 58 static void UnadjustOffsets(const Adjustments& adjustments, |
| 59 std::vector<size_t>* offsets_for_unadjustment); |
| 60 |
| 61 // Adjusts the single |offset| to reflect the reverse of the adjustments |
| 62 // recorded in |adjustments|. |
| 63 static void UnadjustOffset(const Adjustments& adjustments, |
| 64 size_t* offset); |
| 65 |
52 // Combines two sequential sets of adjustments, storing the combined revised | 66 // Combines two sequential sets of adjustments, storing the combined revised |
53 // adjustments in |adjustments_on_adjusted_string|. That is, suppose a | 67 // adjustments in |adjustments_on_adjusted_string|. That is, suppose a |
54 // string was altered in some way, with the alterations recorded as | 68 // string was altered in some way, with the alterations recorded as |
55 // adjustments in |first_adjustments|. Then suppose the resulting string is | 69 // adjustments in |first_adjustments|. Then suppose the resulting string is |
56 // further altered, with the alterations recorded as adjustments scored in | 70 // further altered, with the alterations recorded as adjustments scored in |
57 // |adjustments_on_adjusted_string|, with the offsets recorded in these | 71 // |adjustments_on_adjusted_string|, with the offsets recorded in these |
58 // adjustments being with respect to the intermediate string. This function | 72 // adjustments being with respect to the intermediate string. This function |
59 // combines the two sets of adjustments into one, storing the result in | 73 // combines the two sets of adjustments into one, storing the result in |
60 // |adjustments_on_adjusted_string|, whose offsets are correct with respect | 74 // |adjustments_on_adjusted_string|, whose offsets are correct with respect |
61 // to the original string. | 75 // to the original string. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 if (offset > limit_) | 117 if (offset > limit_) |
104 offset = T::npos; | 118 offset = T::npos; |
105 } | 119 } |
106 | 120 |
107 size_t limit_; | 121 size_t limit_; |
108 }; | 122 }; |
109 | 123 |
110 } // namespace base | 124 } // namespace base |
111 | 125 |
112 #endif // BASE_STRINGS_UTF_OFFSET_STRING_CONVERSIONS_H_ | 126 #endif // BASE_STRINGS_UTF_OFFSET_STRING_CONVERSIONS_H_ |
OLD | NEW |