Copy next run of same-script non-tag letters to buffer [NUL terminated] Buffer ALWAYS has leading space and trailing space space space NUL
| 799 | // Copy next run of same-script non-tag letters to buffer [NUL terminated] |
| 800 | // Buffer ALWAYS has leading space and trailing space space space NUL |
| 801 | bool ScriptScanner::GetOneScriptSpan(LangSpan* span) { |
| 802 | if (!letters_marks_only_) { |
| 803 | // Return non-tag text, including punctuation and digits |
| 804 | return GetOneTextSpan(span); |
| 805 | } |
| 806 | |
| 807 | span->text = script_buffer_; |
| 808 | span->text_bytes = 0; |
| 809 | span->offset = next_byte_ - start_byte_; |
| 810 | span->ulscript = UNKNOWN_ULSCRIPT; |
| 811 | span->lang = UNKNOWN_LANGUAGE; |
| 812 | span->truncated = false; |
| 813 | |
| 814 | // struct timeval script_start, script_mid, script_end; |
| 815 | |
| 816 | int put_soft_limit = kMaxScriptBytes - kWithinScriptTail; |
| 817 | if ((kMaxScriptBytes <= byte_length_) && |
| 818 | (byte_length_ < (2 * kMaxScriptBytes))) { |
| 819 | // Try to split the last two fragments in half |
| 820 | put_soft_limit = byte_length_ / 2; |
| 821 | } |
| 822 | |
| 823 | |
| 824 | int spanscript; // The script of this span |
| 825 | int sc = UNKNOWN_ULSCRIPT; // The script of next character |
| 826 | int tlen = 0; |
| 827 | int plen = 0; |
| 828 | |
| 829 | script_buffer_[0] = ' '; // Always a space at front of output |
| 830 | script_buffer_[1] = '\0'; |
| 831 | int take = 0; |
| 832 | int put = 1; // Start after the initial space |
| 833 | |
| 834 | // Build offsets from span->text back to start_byte_ + span->offset |
| 835 | // This mapping reflects deletion of non-letters, expansion of |
| 836 | // entities, etc. |
| 837 | map2original_.Clear(); |
| 838 | map2original_.Delete(span->offset); // So that MapBack(0) gives offset |
| 839 | |
| 840 | // Get to the first real non-tag letter or entity that is a letter |
| 841 | int skip = SkipToFrontOfSpan(next_byte_, byte_length_, &spanscript); |
| 842 | next_byte_ += skip; |
| 843 | byte_length_ -= skip; |
| 844 | |
| 845 | if (skip != 1) { |
| 846 | map2original_.Delete(skip); |
| 847 | map2original_.Insert(1); |
| 848 | } else { |
| 849 | map2original_.Copy(1); |
| 850 | } |
| 851 | if (byte_length_ <= 0) { |
| 852 | map2original_.Reset(); |
| 853 | return false; // No more letters to be found |
| 854 | } |
| 855 | |
| 856 | // There is at least one letter, so we know the script for this span |
| 857 | span->ulscript = (ULScript)spanscript; |
| 858 |
nothing calls this directly
no test coverage detected