OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_SPELLCHECKER_WORD_TRIMMER_H_ | 5 #ifndef CHROME_BROWSER_SPELLCHECKER_WORD_TRIMMER_H_ |
6 #define CHROME_BROWSER_SPELLCHECKER_WORD_TRIMMER_H_ | 6 #define CHROME_BROWSER_SPELLCHECKER_WORD_TRIMMER_H_ |
7 | 7 |
| 8 #include <stddef.h> |
| 9 |
8 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
9 | 11 |
10 // Trims |text| to contain only the range from |start| to |end| and |keep| words | 12 // Trims |text| to contain only the range from |start| to |end| and |keep| words |
11 // on either side of the range. The |start| and |end| parameters are character | 13 // on either side of the range. The |start| and |end| parameters are character |
12 // indexes into |text|. The |keep| parameter is the number of words to keep on | 14 // indexes into |text|. The |keep| parameter is the number of words to keep on |
13 // either side of the |start|-|end| range. The function updates |start| in | 15 // either side of the |start|-|end| range. The function updates |start| in |
14 // accordance with the trimming. | 16 // accordance with the trimming. |
15 // | 17 // |
16 // Example: | 18 // Example: |
17 // | 19 // |
18 // size_t start = 14; | 20 // size_t start = 14; |
19 // size_t end = 23; | 21 // size_t end = 23; |
20 // base::string16 text = | 22 // base::string16 text = |
21 // base::ASCIIToUTF16("one two three four five six seven eight"); | 23 // base::ASCIIToUTF16("one two three four five six seven eight"); |
22 // int keep = 2; | 24 // int keep = 2; |
23 // base::string16 trimmed = TrimWords(&start, end, text, keep); | 25 // base::string16 trimmed = TrimWords(&start, end, text, keep); |
24 // DCHECK(trimmed == base::ASCIIToUTF16("two three four five six seven")); | 26 // DCHECK(trimmed == base::ASCIIToUTF16("two three four five six seven")); |
25 // DCHECK(start == 10); | 27 // DCHECK(start == 10); |
26 // | 28 // |
27 base::string16 TrimWords(size_t* start, | 29 base::string16 TrimWords(size_t* start, |
28 size_t end, | 30 size_t end, |
29 const base::string16& text, | 31 const base::string16& text, |
30 size_t keep); | 32 size_t keep); |
31 | 33 |
32 #endif // CHROME_BROWSER_SPELLCHECKER_WORD_TRIMMER_H_ | 34 #endif // CHROME_BROWSER_SPELLCHECKER_WORD_TRIMMER_H_ |
OLD | NEW |