Chromium Code Reviews| 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..a63d6a46d02e761f3c99cbe67c0cc087bb65e14c 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,36 @@ |
| #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 IsValidCodePointIndex(const string16& s, size_t index); |
| + |
| +// |Utf16IndexToOffset| returns the number of code points between |base| and |
| +// |pos| in the given string. |Utf16OffsetToIndex| returns the index that is |
| +// |offset| code points away from the given |base| index. These functions are |
| +// named after glib's |g_utf8_pointer_to_offset| and |g_utf8_offset_to_pointer|, |
| +// which perform the same function for UTF-8. |
| +// Unpaired surrogates in the string are counted as BMP characters. If an |
| +// argument index points to the middle of a surrogate pair, it is treated as |
| +// though it pointed to the end of that pair (in other words, the first word of |
| +// any surrogate pair is the one that is counted). The index returned by |
| +// |Utf16OffsetToIndex| never points to the middle of a surrogate pair. |
| +// The following identities hold: |
| +// If |s| contains no surrogate pairs, then |
| +// Utf16IndexToOffset(s, base, pos) == pos - base |
| +// Utf16OffsetToIndex(s, base, offset) == base + offset |
| +// If |pos| does not point to the middle of a surrogate pair, then |
| +// Utf16OffsetToIndex(s, base, Utf16IndexToOffset(s, base, pos)) == pos |
| +// Always, |
| +// Utf16IndexToOffset(s, base, Utf16OffsetToIndex(s, base, ofs)) == ofs |
| +// Utf16IndexToOffset(s, i, j) == -Utf16IndexToOffset(s, j, i) |
| +BASE_EXPORT ptrdiff_t Utf16IndexToOffset(const string16& s, |
|
xji
2012/02/25 00:06:14
since those functions only used in RenderTextLinux
benrg
2012/03/01 17:18:00
The problem is that restricting these functions to
|
| + size_t base, |
| + size_t pos); |
| +BASE_EXPORT size_t Utf16OffsetToIndex(const string16& s, |
| + size_t base, |
| + 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. |