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
3 // found in the LICENSE file.
5 #include "ui/accessibility/ax_text_utils.h"
7 #include "base/logging.h"
8 #include "base/strings/string_util.h"
12 size_t FindAccessibleTextBoundary(const base::string16
& text
,
13 const std::vector
<int>& line_breaks
,
14 TextBoundaryType boundary
,
16 TextBoundaryDirection direction
) {
17 size_t text_size
= text
.size();
18 DCHECK(start_offset
<= text_size
);
20 if (boundary
== CHAR_BOUNDARY
) {
21 if (direction
== FORWARDS_DIRECTION
&& start_offset
< text_size
)
22 return start_offset
+ 1;
25 } else if (boundary
== LINE_BOUNDARY
) {
26 if (direction
== FORWARDS_DIRECTION
) {
27 for (size_t j
= 0; j
< line_breaks
.size(); ++j
) {
28 size_t line_break
= line_breaks
[j
] >= 0 ? line_breaks
[j
] : 0;
29 if (line_break
> start_offset
)
34 for (size_t j
= line_breaks
.size(); j
!= 0; --j
) {
35 size_t line_break
= line_breaks
[j
- 1] >= 0 ? line_breaks
[j
- 1] : 0;
36 if (line_break
< start_offset
)
43 size_t result
= start_offset
;
46 if (direction
== FORWARDS_DIRECTION
) {
47 if (result
>= text_size
)
59 NOTREACHED(); // These are handled above.
62 if (IsWhitespace(text
[pos
]))
65 case PARAGRAPH_BOUNDARY
:
66 if (text
[pos
] == '\n')
69 case SENTENCE_BOUNDARY
:
70 if ((text
[pos
] == '.' || text
[pos
] == '!' || text
[pos
] == '?') &&
71 (pos
== text_size
- 1 || IsWhitespace(text
[pos
+ 1]))) {
80 if (direction
== FORWARDS_DIRECTION
) {