282 {
283 if (max_count == 0 ||
IsNull())
284 return std::u16string();
285
286 std::optional<int> endpoint_comparison =
288 if (!endpoint_comparison)
289 return std::u16string();
290
292 ? anchor_->AsLeafTextPosition()
293 : focus_->AsLeafTextPosition();
295 ? focus_->AsLeafTextPosition()
296 : anchor_->AsLeafTextPosition();
297
298 std::u16string range_text;
299 size_t computed_newlines_count = 0;
300 bool is_first_non_whitespace_leaf = true;
301 bool crossed_paragraph_boundary = false;
302 bool is_first_unignored_leaf = true;
303 bool found_trailing_newline = false;
304
305 while (!
start->IsNullPosition()) {
308
309 if (include_ignored || !
start->IsIgnored()) {
310 if (concatenation_behavior ==
312 !
start->IsInWhiteSpace()) {
313 if (is_first_non_whitespace_leaf) {
314
315
316
317
318 crossed_paragraph_boundary =
319 !is_first_unignored_leaf &&
start->AtStartOfParagraph();
320 }
321
322
323
324 if (crossed_paragraph_boundary && !found_trailing_newline) {
326 computed_newlines_count++;
327 }
328
329 is_first_non_whitespace_leaf = false;
330 crossed_paragraph_boundary = false;
331 }
332
333 int current_end_offset = (
start->GetAnchor() !=
end->GetAnchor())
334 ?
start->MaxTextOffset()
335 :
end->text_offset();
336
337 if (current_end_offset >
start->text_offset()) {
338 int characters_to_append =
339 (max_count > 0)
340 ?
std::min(max_count -
static_cast<int>(range_text.length()),
341 current_end_offset -
start->text_offset())
342 : current_end_offset -
start->text_offset();
343
344 range_text +=
start->GetText().substr(
start->text_offset(),
345 characters_to_append);
346
347
348 found_trailing_newline =
349 start->IsInLineBreak() ||
350 (found_trailing_newline &&
start->IsInWhiteSpace());
351 }
352
354 static_cast<int>(range_text.length()) <= max_count);
355 is_first_unignored_leaf = false;
356 }
357
358 if (
start->GetAnchor() ==
end->GetAnchor() ||
359 static_cast<int>(range_text.length()) == max_count) {
360 break;
361 } else if (concatenation_behavior ==
363 !crossed_paragraph_boundary && !is_first_non_whitespace_leaf) {
364 start =
start->CreateNextLeafTextPosition(&crossed_paragraph_boundary);
365 } else {
367 }
368 }
369
370 if (appended_newlines_count)
371 *appended_newlines_count = computed_newlines_count;
372 return range_text;
373 }
std::unique_ptr< AXPositionType > AXPositionInstance
static float min(float r, float g, float b)
std::u16string ASCIIToUTF16(std::string src)