Index: base/utf_offset_string_conversions.h |
diff --git a/base/utf_offset_string_conversions.h b/base/utf_offset_string_conversions.h |
index 97b641edda8b49a9a9797ec4cd08966f2400c277..ee897a3c87d7b3e5b5c32cc6dbe22969f9caba7e 100644 |
--- a/base/utf_offset_string_conversions.h |
+++ b/base/utf_offset_string_conversions.h |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -13,6 +13,25 @@ |
#include "base/string16.h" |
#include "base/string_piece.h" |
+// Returns false if s[index-1] is a high surrogate and s[index] is a low |
+// surrogate, true otherwise. |
+BASE_EXPORT bool IsValidUtf16Index(const string16& s, size_t index); |
xji
2012/02/18 01:28:47
Maybe IsValidCharacterIndex or IsValidCodePointInd
benrg
2012/02/24 19:07:44
Changed to IsValidCodePointIndex.
|
+ |
+// |Utf16IndexToOffset| and |Utf16OffsetToIndex| are similar to GLib's |
xji
2012/02/18 01:28:47
Maybe add a comment like "Converts between UTF16 i
benrg
2012/02/22 02:25:43
I don't know the rules, but there are many functio
|
+// |g_utf8_pointer_to_offset| and |g_utf8_offset_to_pointer|, but using string16 |
msw
2012/02/22 00:33:26
I guess you're not converting a single position (l
benrg
2012/02/22 02:25:43
These functions use (string16&, size_t) pairs wher
|
+// instead of UTF-8 C strings. They count the number of 16-bit words between the |
+// indices that are not the second half of a valid surrogate pair. When the |
+// string is valid UTF-16 and the indices satisfy IsValidUtf16Index (the usual |
+// case), this is equal to the number of code points between the indices. When |
+// the string contains no surrogate pairs, Utf16IndexToOffset(s, i, j) == i - j |
xji
2012/02/18 01:28:47
== j - i
benrg
2012/02/24 19:07:44
Oops. Fixed in rewritten documentation.
|
+// and Utf16OffsetToIndex(s, i, k) == i + k. |
+BASE_EXPORT ptrdiff_t Utf16IndexToOffset(const string16& s, |
msw
2012/02/22 00:33:26
This function isn't converting an index to an offs
benrg
2012/02/22 02:25:43
The same is true of g_utf8_pointer_to_offset. I ha
benrg
2012/02/24 19:07:44
I couldn't think of better names for the functions
|
+ size_t from, |
+ size_t to); |
+BASE_EXPORT size_t Utf16OffsetToIndex(const string16& s, |
msw
2012/02/22 00:33:26
Similarly, this function isn't just converting an
|
+ size_t pos, |
+ ptrdiff_t offset); |
+ |
// Like the conversions in utf_string_conversions.h, but also takes one or more |
// offsets (|offset[s]_for_adjustment|) into the source strings, each offset |
// will be adjusted to point at the same logical place in the result strings. |