* Returns the null terminated UTF-8 encoded text string for the current * object at the given level. Use delete [] to free after use. */
| 554 | * object at the given level. Use delete [] to free after use. |
| 555 | */ |
| 556 | char* ResultIterator::GetUTF8Text(PageIteratorLevel level) const { |
| 557 | if (it_->word() == NULL) return NULL; // Already at the end! |
| 558 | STRING text; |
| 559 | switch (level) { |
| 560 | case RIL_BLOCK: |
| 561 | { |
| 562 | ResultIterator pp(*this); |
| 563 | do { |
| 564 | pp.AppendUTF8ParagraphText(&text); |
| 565 | } while (pp.Next(RIL_PARA) && pp.it_->block() == it_->block()); |
| 566 | } |
| 567 | break; |
| 568 | case RIL_PARA: |
| 569 | AppendUTF8ParagraphText(&text); |
| 570 | break; |
| 571 | case RIL_TEXTLINE: |
| 572 | { |
| 573 | ResultIterator it(*this); |
| 574 | it.MoveToLogicalStartOfTextline(); |
| 575 | it.IterateAndAppendUTF8TextlineText(&text); |
| 576 | } |
| 577 | break; |
| 578 | case RIL_WORD: |
| 579 | AppendUTF8WordText(&text); |
| 580 | break; |
| 581 | case RIL_SYMBOL: |
| 582 | { |
| 583 | bool reading_direction_is_ltr = |
| 584 | current_paragraph_is_ltr_ ^ in_minor_direction_; |
| 585 | if (at_beginning_of_minor_run_) { |
| 586 | text += reading_direction_is_ltr ? kLRM : kRLM; |
| 587 | } |
| 588 | text = it_->word()->BestUTF8(blob_index_, !reading_direction_is_ltr); |
| 589 | if (IsAtFinalSymbolOfWord()) AppendSuffixMarks(&text); |
| 590 | } |
| 591 | break; |
| 592 | } |
| 593 | int length = text.length() + 1; |
| 594 | char* result = new char[length]; |
| 595 | strncpy(result, text.string(), length); |
| 596 | return result; |
| 597 | } |
| 598 | |
| 599 | void ResultIterator::AppendUTF8WordText(STRING *text) const { |
| 600 | if (!it_->word()) return; |
no test coverage detected