Index: base/strings/utf_offset_string_conversions.cc |
diff --git a/base/strings/utf_offset_string_conversions.cc b/base/strings/utf_offset_string_conversions.cc |
index 731175f97367cd7cf6f14b14c4e05af920626556..e8688ffbbe5e304db4448d58234bf16ad433f7ba 100644 |
--- a/base/strings/utf_offset_string_conversions.cc |
+++ b/base/strings/utf_offset_string_conversions.cc |
@@ -37,7 +37,7 @@ void OffsetAdjuster::AdjustOffset(const Adjustments& adjustments, |
size_t* offset) { |
if (*offset == string16::npos) |
return; |
- size_t adjustment = 0; |
+ int adjustment = 0; |
willchan no longer on Chromium
2014/04/25 00:07:20
QQ: Why did this switch to int? Also, is it imposs
Mark P
2014/04/25 02:29:02
Although it doesn't generally happen, it in theory
willchan no longer on Chromium
2014/04/25 05:24:43
Great.
|
for (Adjustments::const_iterator i = adjustments.begin(); |
i != adjustments.end(); ++i) { |
if (*offset <= i->original_offset) |
@@ -52,6 +52,37 @@ void OffsetAdjuster::AdjustOffset(const Adjustments& adjustments, |
} |
// static |
+void OffsetAdjuster::UnadjustOffsets( |
+ const Adjustments& adjustments, |
+ std::vector<size_t>* offsets_for_unadjustment) { |
+ if (!offsets_for_unadjustment || adjustments.empty()) |
+ return; |
+ for (std::vector<size_t>::iterator i(offsets_for_unadjustment->begin()); |
+ i != offsets_for_unadjustment->end(); ++i) |
+ UnadjustOffset(adjustments, &(*i)); |
+} |
+ |
+// static |
+void OffsetAdjuster::UnadjustOffset(const Adjustments& adjustments, |
+ size_t* offset) { |
+ if (*offset == string16::npos) |
+ return; |
+ int adjustment = 0; |
+ for (Adjustments::const_iterator i = adjustments.begin(); |
+ i != adjustments.end(); ++i) { |
+ if (*offset + adjustment <= i->original_offset) |
+ break; |
+ adjustment += (i->original_length - i->output_length); |
+ if ((*offset + adjustment) < |
+ (i->original_offset + i->original_length)) { |
+ *offset = string16::npos; |
+ return; |
+ } |
+ } |
+ *offset += adjustment; |
+} |
+ |
+// static |
void OffsetAdjuster::MergeSequentialAdjustments( |
const Adjustments& first_adjustments, |
Adjustments* adjustments_on_adjusted_string) { |