| 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 #include "base/strings/utf_offset_string_conversions.h" | 5 #include "base/strings/utf_offset_string_conversions.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 void OffsetAdjuster::Add(const Adjustment& adjustment) { | 141 void OffsetAdjuster::Add(const Adjustment& adjustment) { |
| 142 adjustments_.push_back(adjustment); | 142 adjustments_.push_back(adjustment); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void OffsetAdjuster::AdjustOffset(std::vector<size_t>::iterator offset) { | 145 void OffsetAdjuster::AdjustOffset(std::vector<size_t>::iterator offset) { |
| 146 if (*offset == string16::npos) | 146 if (*offset == string16::npos) |
| 147 return; | 147 return; |
| 148 size_t adjustment = 0; | 148 size_t adjustment = 0; |
| 149 for (std::vector<Adjustment>::const_iterator i = adjustments_.begin(); | 149 for (std::vector<Adjustment>::const_iterator i = adjustments_.begin(); |
| 150 i != adjustments_.end(); ++i) { | 150 i != adjustments_.end(); ++i) { |
| 151 if (*offset == i->original_offset && i->output_length == 0) { | |
| 152 *offset = string16::npos; | |
| 153 return; | |
| 154 } | |
| 155 if (*offset <= i->original_offset) | 151 if (*offset <= i->original_offset) |
| 156 break; | 152 break; |
| 157 if (*offset < (i->original_offset + i->original_length)) { | 153 if (*offset < (i->original_offset + i->original_length)) { |
| 158 *offset = string16::npos; | 154 *offset = string16::npos; |
| 159 return; | 155 return; |
| 160 } | 156 } |
| 161 adjustment += (i->original_length - i->output_length); | 157 adjustment += (i->original_length - i->output_length); |
| 162 } | 158 } |
| 163 *offset -= adjustment; | 159 *offset -= adjustment; |
| 164 } | 160 } |
| 165 | 161 |
| 166 } // namespace base | 162 } // namespace base |
| OLD | NEW |