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

Side by Side Diff: base/utf_offset_string_conversions.h

Issue 8747001: Reintroduce password support to NativeTextfieldViews (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new implementation, linux only 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef BASE_UTF_OFFSET_STRING_CONVERSIONS_H_ 5 #ifndef BASE_UTF_OFFSET_STRING_CONVERSIONS_H_
6 #define BASE_UTF_OFFSET_STRING_CONVERSIONS_H_ 6 #define BASE_UTF_OFFSET_STRING_CONVERSIONS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/base_export.h" 12 #include "base/base_export.h"
13 #include "base/string16.h" 13 #include "base/string16.h"
14 #include "base/string_piece.h" 14 #include "base/string_piece.h"
15 15
16 // Returns false if s[index-1] is a high surrogate and s[index] is a low
17 // surrogate, true otherwise.
18 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.
19
20 // |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
21 // |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
22 // instead of UTF-8 C strings. They count the number of 16-bit words between the
23 // indices that are not the second half of a valid surrogate pair. When the
24 // string is valid UTF-16 and the indices satisfy IsValidUtf16Index (the usual
25 // case), this is equal to the number of code points between the indices. When
26 // 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.
27 // and Utf16OffsetToIndex(s, i, k) == i + k.
28 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
29 size_t from,
30 size_t to);
31 BASE_EXPORT size_t Utf16OffsetToIndex(const string16& s,
msw 2012/02/22 00:33:26 Similarly, this function isn't just converting an
32 size_t pos,
33 ptrdiff_t offset);
34
16 // Like the conversions in utf_string_conversions.h, but also takes one or more 35 // Like the conversions in utf_string_conversions.h, but also takes one or more
17 // offsets (|offset[s]_for_adjustment|) into the source strings, each offset 36 // offsets (|offset[s]_for_adjustment|) into the source strings, each offset
18 // will be adjusted to point at the same logical place in the result strings. 37 // will be adjusted to point at the same logical place in the result strings.
19 // If this isn't possible because an offset points past the end of the source 38 // If this isn't possible because an offset points past the end of the source
20 // strings or into the middle of a multibyte sequence, the offending offset will 39 // strings or into the middle of a multibyte sequence, the offending offset will
21 // be set to string16::npos. |offset[s]_for_adjustment| may be NULL. 40 // be set to string16::npos. |offset[s]_for_adjustment| may be NULL.
22 BASE_EXPORT bool UTF8ToUTF16AndAdjustOffset(const char* src, 41 BASE_EXPORT bool UTF8ToUTF16AndAdjustOffset(const char* src,
23 size_t src_len, 42 size_t src_len,
24 string16* output, 43 string16* output,
25 size_t* offset_for_adjustment); 44 size_t* offset_for_adjustment);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 void Add(const Adjustment& adjustment); 100 void Add(const Adjustment& adjustment);
82 101
83 private: 102 private:
84 void AdjustOffset(std::vector<size_t>::iterator offset); 103 void AdjustOffset(std::vector<size_t>::iterator offset);
85 104
86 std::vector<size_t>* offsets_for_adjustment_; 105 std::vector<size_t>* offsets_for_adjustment_;
87 std::vector<Adjustment> adjustments_; 106 std::vector<Adjustment> adjustments_;
88 }; 107 };
89 108
90 #endif // BASE_UTF_OFFSET_STRING_CONVERSIONS_H_ 109 #endif // BASE_UTF_OFFSET_STRING_CONVERSIONS_H_
OLDNEW
« no previous file with comments | « no previous file | base/utf_offset_string_conversions.cc » ('j') | base/utf_offset_string_conversions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698