Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: base/utf_offset_string_conversions.h

Issue 9467017: Password support for NativeTextfieldViews, in the model (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/utf_offset_string_conversions.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
+ 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.
« no previous file with comments | « no previous file | base/utf_offset_string_conversions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698