| Conditions | 100 |
| Paths | > 20000 |
| Total Lines | 502 |
| Code Lines | 334 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 649 | private static function finishCurrentSpan(string &$result, bool $theEnd = false): void |
||
| 650 | { |
||
| 651 | $textSpan = substr($result, self::$posSpanStart); |
||
| 652 | $result = substr($result, 0, self::$posSpanStart); |
||
| 653 | |||
| 654 | // Get rid of empty spans, so that our check for presence of RTL will work |
||
| 655 | $result = str_replace([ |
||
| 656 | self::START_LTR . self::END_LTR, |
||
| 657 | self::START_RTL . self::END_RTL, |
||
| 658 | ], '', $result); |
||
| 659 | |||
| 660 | // Look for numeric strings that are times (hh:mm:ss). These have to be separated from surrounding numbers. |
||
| 661 | $tempResult = ''; |
||
| 662 | while ($textSpan !== '') { |
||
| 663 | $posColon = strpos($textSpan, ':'); |
||
| 664 | if ($posColon === false) { |
||
| 665 | break; |
||
| 666 | } // No more possible time strings |
||
| 667 | $posLRE = strpos($textSpan, self::UTF8_LRE); |
||
| 668 | if ($posLRE === false) { |
||
| 669 | break; |
||
| 670 | } // No more numeric strings |
||
| 671 | $posPDF = strpos($textSpan, self::UTF8_PDF, $posLRE); |
||
| 672 | if ($posPDF === false) { |
||
| 673 | break; |
||
| 674 | } // No more numeric strings |
||
| 675 | |||
| 676 | $tempResult .= substr($textSpan, 0, $posLRE + 3); // Copy everything preceding the numeric string |
||
| 677 | $numericString = substr($textSpan, $posLRE + 3, $posPDF - $posLRE); // Separate the entire numeric string |
||
| 678 | $textSpan = substr($textSpan, $posPDF + 3); |
||
| 679 | $posColon = strpos($numericString, ':'); |
||
| 680 | if ($posColon === false) { |
||
| 681 | // Nothing that looks like a time here |
||
| 682 | $tempResult .= $numericString; |
||
| 683 | continue; |
||
| 684 | } |
||
| 685 | $posBlank = strpos($numericString . ' ', ' '); |
||
| 686 | $posNbsp = strpos($numericString . ' ', ' '); |
||
| 687 | if ($posBlank < $posNbsp) { |
||
| 688 | $posSeparator = $posBlank; |
||
| 689 | $lengthSeparator = 1; |
||
| 690 | } else { |
||
| 691 | $posSeparator = $posNbsp; |
||
| 692 | $lengthSeparator = 6; |
||
| 693 | } |
||
| 694 | if ($posColon > $posSeparator) { |
||
| 695 | // We have a time string preceded by a blank: Exclude that blank from the numeric string |
||
| 696 | $tempResult .= substr($numericString, 0, $posSeparator); |
||
| 697 | $tempResult .= self::UTF8_PDF; |
||
| 698 | $tempResult .= substr($numericString, $posSeparator, $lengthSeparator); |
||
| 699 | $tempResult .= self::UTF8_LRE; |
||
| 700 | $numericString = substr($numericString, $posSeparator + $lengthSeparator); |
||
| 701 | } |
||
| 702 | |||
| 703 | $posBlank = strpos($numericString, ' '); |
||
| 704 | $posNbsp = strpos($numericString, ' '); |
||
| 705 | if ($posBlank === false && $posNbsp === false) { |
||
| 706 | // The time string isn't followed by a blank |
||
| 707 | $textSpan = $numericString . $textSpan; |
||
| 708 | continue; |
||
| 709 | } |
||
| 710 | |||
| 711 | // We have a time string followed by a blank: Exclude that blank from the numeric string |
||
| 712 | if ($posBlank === false) { |
||
| 713 | $posSeparator = $posNbsp; |
||
| 714 | $lengthSeparator = 6; |
||
| 715 | } elseif ($posNbsp === false) { |
||
| 716 | $posSeparator = $posBlank; |
||
| 717 | $lengthSeparator = 1; |
||
| 718 | } elseif ($posBlank < $posNbsp) { |
||
| 719 | $posSeparator = $posBlank; |
||
| 720 | $lengthSeparator = 1; |
||
| 721 | } else { |
||
| 722 | $posSeparator = $posNbsp; |
||
| 723 | $lengthSeparator = 6; |
||
| 724 | } |
||
| 725 | $tempResult .= substr($numericString, 0, $posSeparator); |
||
| 726 | $tempResult .= self::UTF8_PDF; |
||
| 727 | $tempResult .= substr($numericString, $posSeparator, $lengthSeparator); |
||
| 728 | $posSeparator += $lengthSeparator; |
||
| 729 | $numericString = substr($numericString, $posSeparator); |
||
| 730 | $textSpan = self::UTF8_LRE . $numericString . $textSpan; |
||
| 731 | } |
||
| 732 | $textSpan = $tempResult . $textSpan; |
||
| 733 | $trailingBlanks = ''; |
||
| 734 | $trailingBreaks = ''; |
||
| 735 | |||
| 736 | /* ****************************** LTR text handling ******************************** */ |
||
| 737 | |||
| 738 | if (self::$currentState === 'LTR') { |
||
| 739 | // Move trailing numeric strings to the following RTL text. Include any blanks preceding or following the numeric text too. |
||
| 740 | if (I18N::direction() === 'rtl' && self::$previousState === 'RTL' && !$theEnd) { |
||
| 741 | $trailingString = ''; |
||
| 742 | $savedSpan = $textSpan; |
||
| 743 | while ($textSpan !== '') { |
||
| 744 | // Look for trailing spaces and tentatively move them |
||
| 745 | if (str_ends_with($textSpan, ' ')) { |
||
| 746 | $trailingString = ' ' . $trailingString; |
||
| 747 | $textSpan = substr($textSpan, 0, -1); |
||
| 748 | continue; |
||
| 749 | } |
||
| 750 | if (str_ends_with($textSpan, ' ')) { |
||
| 751 | $trailingString = ' ' . $trailingString; |
||
| 752 | $textSpan = substr($textSpan, 0, -1); |
||
| 753 | continue; |
||
| 754 | } |
||
| 755 | if (substr($textSpan, -3) !== self::UTF8_PDF) { |
||
| 756 | // There is no trailing numeric string |
||
| 757 | $textSpan = $savedSpan; |
||
| 758 | break; |
||
| 759 | } |
||
| 760 | |||
| 761 | // We have a numeric string |
||
| 762 | $posStartNumber = strrpos($textSpan, self::UTF8_LRE); |
||
| 763 | if ($posStartNumber === false) { |
||
| 764 | $posStartNumber = 0; |
||
| 765 | } |
||
| 766 | $trailingString = substr($textSpan, $posStartNumber) . $trailingString; |
||
| 767 | $textSpan = substr($textSpan, 0, $posStartNumber); |
||
| 768 | |||
| 769 | // Look for more spaces and move them too |
||
| 770 | while ($textSpan !== '') { |
||
| 771 | if (str_ends_with($textSpan, ' ')) { |
||
| 772 | $trailingString = ' ' . $trailingString; |
||
| 773 | $textSpan = substr($textSpan, 0, -1); |
||
| 774 | continue; |
||
| 775 | } |
||
| 776 | if (str_ends_with($textSpan, ' ')) { |
||
| 777 | $trailingString = ' ' . $trailingString; |
||
| 778 | $textSpan = substr($textSpan, 0, -1); |
||
| 779 | continue; |
||
| 780 | } |
||
| 781 | break; |
||
| 782 | } |
||
| 783 | |||
| 784 | self::$waitingText = $trailingString . self::$waitingText; |
||
| 785 | break; |
||
| 786 | } |
||
| 787 | } |
||
| 788 | |||
| 789 | $savedSpan = $textSpan; |
||
| 790 | // Move any trailing <br>, optionally preceded or followed by blanks, outside this LTR span |
||
| 791 | while ($textSpan !== '') { |
||
| 792 | if (str_ends_with($textSpan, ' ')) { |
||
| 793 | $trailingBlanks = ' ' . $trailingBlanks; |
||
| 794 | $textSpan = substr($textSpan, 0, -1); |
||
| 795 | continue; |
||
| 796 | } |
||
| 797 | if (str_ends_with('......' . $textSpan, ' ')) { |
||
| 798 | $trailingBlanks = ' ' . $trailingBlanks; |
||
| 799 | $textSpan = substr($textSpan, 0, -6); |
||
| 800 | continue; |
||
| 801 | } |
||
| 802 | break; |
||
| 803 | } |
||
| 804 | while (str_ends_with($textSpan, '<LTRbr>')) { |
||
| 805 | $trailingBreaks = '<br>' . $trailingBreaks; // Plain <br> because it’s outside a span |
||
| 806 | $textSpan = substr($textSpan, 0, -7); |
||
| 807 | } |
||
| 808 | if ($trailingBreaks !== '') { |
||
| 809 | while ($textSpan !== '') { |
||
| 810 | if (str_ends_with($textSpan, ' ')) { |
||
| 811 | $trailingBreaks = ' ' . $trailingBreaks; |
||
| 812 | $textSpan = substr($textSpan, 0, -1); |
||
| 813 | continue; |
||
| 814 | } |
||
| 815 | if (str_ends_with($textSpan, ' ')) { |
||
| 816 | $trailingBreaks = ' ' . $trailingBreaks; |
||
| 817 | $textSpan = substr($textSpan, 0, -6); |
||
| 818 | continue; |
||
| 819 | } |
||
| 820 | break; |
||
| 821 | } |
||
| 822 | self::$waitingText = $trailingBlanks . self::$waitingText; // Put those trailing blanks inside the following span |
||
| 823 | } else { |
||
| 824 | $textSpan = $savedSpan; |
||
| 825 | } |
||
| 826 | |||
| 827 | $trailingBlanks = ''; |
||
| 828 | $trailingPunctuation = ''; |
||
| 829 | $trailingID = ''; |
||
| 830 | $trailingSeparator = ''; |
||
| 831 | $leadingSeparator = ''; |
||
| 832 | |||
| 833 | while (I18N::direction() === 'rtl') { |
||
| 834 | if (str_contains($result, self::START_RTL)) { |
||
| 835 | // Remove trailing blanks for inclusion in a separate LTR span |
||
| 836 | while ($textSpan !== '') { |
||
| 837 | if (str_ends_with($textSpan, ' ')) { |
||
| 838 | $trailingBlanks = ' ' . $trailingBlanks; |
||
| 839 | $textSpan = substr($textSpan, 0, -1); |
||
| 840 | continue; |
||
| 841 | } |
||
| 842 | if (str_ends_with($textSpan, ' ')) { |
||
| 843 | $trailingBlanks = ' ' . $trailingBlanks; |
||
| 844 | $textSpan = substr($textSpan, 0, -1); |
||
| 845 | continue; |
||
| 846 | } |
||
| 847 | break; |
||
| 848 | } |
||
| 849 | |||
| 850 | // Remove trailing punctuation for inclusion in a separate LTR span |
||
| 851 | if ($textSpan === '') { |
||
| 852 | $trailingChar = "\n"; |
||
| 853 | } else { |
||
| 854 | $trailingChar = substr($textSpan, -1); |
||
| 855 | } |
||
| 856 | if (str_contains(self::PUNCTUATION, $trailingChar)) { |
||
| 857 | $trailingPunctuation = $trailingChar; |
||
| 858 | $textSpan = substr($textSpan, 0, -1); |
||
| 859 | } |
||
| 860 | } |
||
| 861 | |||
| 862 | // Remove trailing ID numbers that look like "(xnnn)" for inclusion in a separate LTR span |
||
| 863 | while (true) { |
||
| 864 | if (!str_ends_with($textSpan, ')')) { |
||
| 865 | break; |
||
| 866 | } // There is no trailing ')' |
||
| 867 | $posLeftParen = strrpos($textSpan, '('); |
||
| 868 | if ($posLeftParen === false) { |
||
| 869 | break; |
||
| 870 | } // There is no leading '(' |
||
| 871 | $temp = self::stripLrmRlm(substr($textSpan, $posLeftParen)); // Get rid of UTF8 control codes |
||
| 872 | |||
| 873 | // If the parenthesized text doesn't look like an ID number, |
||
| 874 | // we don't want to touch it. |
||
| 875 | // This check won’t work if somebody uses ID numbers with an unusual format. |
||
| 876 | $offset = 1; |
||
| 877 | $charArray = self::getChar($temp, $offset); // Get 1st character of parenthesized text |
||
| 878 | if (str_contains(self::NUMBERS, $charArray['letter'])) { |
||
| 879 | break; |
||
| 880 | } |
||
| 881 | $offset += $charArray['length']; // Point at 2nd character of parenthesized text |
||
| 882 | if (!str_contains(self::NUMBERS, substr($temp, $offset, 1))) { |
||
| 883 | break; |
||
| 884 | } |
||
| 885 | // 1st character of parenthesized text is alpha, 2nd character is a digit; last has to be a digit too |
||
| 886 | if (!str_contains(self::NUMBERS, substr($temp, -2, 1))) { |
||
| 887 | break; |
||
| 888 | } |
||
| 889 | |||
| 890 | $trailingID = substr($textSpan, $posLeftParen); |
||
| 891 | $textSpan = substr($textSpan, 0, $posLeftParen); |
||
| 892 | break; |
||
| 893 | } |
||
| 894 | |||
| 895 | // Look for " - " or blank preceding the ID number and remove it for inclusion in a separate LTR span |
||
| 896 | if ($trailingID !== '') { |
||
| 897 | while ($textSpan !== '') { |
||
| 898 | if (str_ends_with($textSpan, ' ')) { |
||
| 899 | $trailingSeparator = ' ' . $trailingSeparator; |
||
| 900 | $textSpan = substr($textSpan, 0, -1); |
||
| 901 | continue; |
||
| 902 | } |
||
| 903 | if (str_ends_with($textSpan, ' ')) { |
||
| 904 | $trailingSeparator = ' ' . $trailingSeparator; |
||
| 905 | $textSpan = substr($textSpan, 0, -6); |
||
| 906 | continue; |
||
| 907 | } |
||
| 908 | if (str_ends_with($textSpan, '-')) { |
||
| 909 | $trailingSeparator = '-' . $trailingSeparator; |
||
| 910 | $textSpan = substr($textSpan, 0, -1); |
||
| 911 | continue; |
||
| 912 | } |
||
| 913 | break; |
||
| 914 | } |
||
| 915 | } |
||
| 916 | |||
| 917 | // Look for " - " preceding the text and remove it for inclusion in a separate LTR span |
||
| 918 | $foundSeparator = false; |
||
| 919 | $savedSpan = $textSpan; |
||
| 920 | while ($textSpan !== '') { |
||
| 921 | if (str_starts_with($textSpan, ' ')) { |
||
| 922 | $leadingSeparator = ' ' . $leadingSeparator; |
||
| 923 | $textSpan = substr($textSpan, 1); |
||
| 924 | continue; |
||
| 925 | } |
||
| 926 | if (str_starts_with($textSpan, ' ')) { |
||
| 927 | $leadingSeparator = ' ' . $leadingSeparator; |
||
| 928 | $textSpan = substr($textSpan, 6); |
||
| 929 | continue; |
||
| 930 | } |
||
| 931 | if (str_starts_with($textSpan, '-')) { |
||
| 932 | $leadingSeparator = '-' . $leadingSeparator; |
||
| 933 | $textSpan = substr($textSpan, 1); |
||
| 934 | $foundSeparator = true; |
||
| 935 | continue; |
||
| 936 | } |
||
| 937 | break; |
||
| 938 | } |
||
| 939 | if (!$foundSeparator) { |
||
| 940 | $textSpan = $savedSpan; |
||
| 941 | $leadingSeparator = ''; |
||
| 942 | } |
||
| 943 | break; |
||
| 944 | } |
||
| 945 | |||
| 946 | // We're done: finish the span |
||
| 947 | $textSpan = self::starredName($textSpan, 'LTR'); // Wrap starred name in <u> and </u> tags |
||
| 948 | while (true) { |
||
| 949 | // Remove blanks that precede <LTRbr> |
||
| 950 | if (str_contains($textSpan, ' <LTRbr>')) { |
||
| 951 | $textSpan = str_replace(' <LTRbr>', '<LTRbr>', $textSpan); |
||
| 952 | continue; |
||
| 953 | } |
||
| 954 | if (str_contains($textSpan, ' <LTRbr>')) { |
||
| 955 | $textSpan = str_replace(' <LTRbr>', '<LTRbr>', $textSpan); |
||
| 956 | continue; |
||
| 957 | } |
||
| 958 | break; |
||
| 959 | } |
||
| 960 | if ($leadingSeparator !== '') { |
||
| 961 | $result .= self::START_LTR . $leadingSeparator . self::END_LTR; |
||
| 962 | } |
||
| 963 | $result .= $textSpan . self::END_LTR; |
||
| 964 | if ($trailingSeparator !== '') { |
||
| 965 | $result .= self::START_LTR . $trailingSeparator . self::END_LTR; |
||
| 966 | } |
||
| 967 | if ($trailingID !== '') { |
||
| 968 | $result .= self::START_LTR . $trailingID . self::END_LTR; |
||
| 969 | } |
||
| 970 | if ($trailingPunctuation !== '') { |
||
| 971 | $result .= self::START_LTR . $trailingPunctuation . self::END_LTR; |
||
| 972 | } |
||
| 973 | if ($trailingBlanks !== '') { |
||
| 974 | $result .= self::START_LTR . $trailingBlanks . self::END_LTR; |
||
| 975 | } |
||
| 976 | } |
||
| 977 | |||
| 978 | /* ****************************** RTL text handling ******************************** */ |
||
| 979 | |||
| 980 | if (self::$currentState === 'RTL') { |
||
| 981 | $savedSpan = $textSpan; |
||
| 982 | |||
| 983 | // Move any trailing <br>, optionally followed by blanks, outside this RTL span |
||
| 984 | while ($textSpan !== '') { |
||
| 985 | if (str_ends_with($textSpan, ' ')) { |
||
| 986 | $trailingBlanks = ' ' . $trailingBlanks; |
||
| 987 | $textSpan = substr($textSpan, 0, -1); |
||
| 988 | continue; |
||
| 989 | } |
||
| 990 | if (str_ends_with('......' . $textSpan, ' ')) { |
||
| 991 | $trailingBlanks = ' ' . $trailingBlanks; |
||
| 992 | $textSpan = substr($textSpan, 0, -6); |
||
| 993 | continue; |
||
| 994 | } |
||
| 995 | break; |
||
| 996 | } |
||
| 997 | while (str_ends_with($textSpan, '<RTLbr>')) { |
||
| 998 | $trailingBreaks = '<br>' . $trailingBreaks; // Plain <br> because it’s outside a span |
||
| 999 | $textSpan = substr($textSpan, 0, -7); |
||
| 1000 | } |
||
| 1001 | if ($trailingBreaks !== '') { |
||
| 1002 | self::$waitingText = $trailingBlanks . self::$waitingText; // Put those trailing blanks inside the following span |
||
| 1003 | } else { |
||
| 1004 | $textSpan = $savedSpan; |
||
| 1005 | } |
||
| 1006 | |||
| 1007 | // Move trailing numeric strings to the following LTR text. Include any blanks preceding or following the numeric text too. |
||
| 1008 | if (!$theEnd && I18N::direction() !== 'rtl') { |
||
| 1009 | $trailingString = ''; |
||
| 1010 | $savedSpan = $textSpan; |
||
| 1011 | while ($textSpan !== '') { |
||
| 1012 | // Look for trailing spaces and tentatively move them |
||
| 1013 | if (str_ends_with($textSpan, ' ')) { |
||
| 1014 | $trailingString = ' ' . $trailingString; |
||
| 1015 | $textSpan = substr($textSpan, 0, -1); |
||
| 1016 | continue; |
||
| 1017 | } |
||
| 1018 | if (str_ends_with($textSpan, ' ')) { |
||
| 1019 | $trailingString = ' ' . $trailingString; |
||
| 1020 | $textSpan = substr($textSpan, 0, -1); |
||
| 1021 | continue; |
||
| 1022 | } |
||
| 1023 | if (substr($textSpan, -3) !== self::UTF8_PDF) { |
||
| 1024 | // There is no trailing numeric string |
||
| 1025 | $textSpan = $savedSpan; |
||
| 1026 | break; |
||
| 1027 | } |
||
| 1028 | |||
| 1029 | // We have a numeric string |
||
| 1030 | $posStartNumber = strrpos($textSpan, self::UTF8_LRE); |
||
| 1031 | if ($posStartNumber === false) { |
||
| 1032 | $posStartNumber = 0; |
||
| 1033 | } |
||
| 1034 | $trailingString = substr($textSpan, $posStartNumber) . $trailingString; |
||
| 1035 | $textSpan = substr($textSpan, 0, $posStartNumber); |
||
| 1036 | |||
| 1037 | // Look for more spaces and move them too |
||
| 1038 | while ($textSpan !== '') { |
||
| 1039 | if (str_ends_with($textSpan, ' ')) { |
||
| 1040 | $trailingString = ' ' . $trailingString; |
||
| 1041 | $textSpan = substr($textSpan, 0, -1); |
||
| 1042 | continue; |
||
| 1043 | } |
||
| 1044 | if (str_ends_with($textSpan, ' ')) { |
||
| 1045 | $trailingString = ' ' . $trailingString; |
||
| 1046 | $textSpan = substr($textSpan, 0, -1); |
||
| 1047 | continue; |
||
| 1048 | } |
||
| 1049 | break; |
||
| 1050 | } |
||
| 1051 | |||
| 1052 | self::$waitingText = $trailingString . self::$waitingText; |
||
| 1053 | break; |
||
| 1054 | } |
||
| 1055 | } |
||
| 1056 | |||
| 1057 | // Trailing " - " needs to be prefixed to the following span |
||
| 1058 | if (!$theEnd && str_ends_with('...' . $textSpan, ' - ')) { |
||
| 1059 | $textSpan = substr($textSpan, 0, -3); |
||
| 1060 | self::$waitingText = ' - ' . self::$waitingText; |
||
| 1061 | } |
||
| 1062 | |||
| 1063 | while (I18N::direction() === 'rtl') { |
||
| 1064 | // Look for " - " preceding <RTLbr> and relocate it to the front of the string |
||
| 1065 | $posDashString = strpos($textSpan, ' - <RTLbr>'); |
||
| 1066 | if ($posDashString === false) { |
||
| 1067 | break; |
||
| 1068 | } |
||
| 1069 | $posStringStart = strrpos(substr($textSpan, 0, $posDashString), '<RTLbr>'); |
||
| 1070 | if ($posStringStart === false) { |
||
| 1071 | $posStringStart = 0; |
||
| 1072 | } else { |
||
| 1073 | $posStringStart += 9; |
||
| 1074 | } // Point to the first char following the last <RTLbr> |
||
| 1075 | |||
| 1076 | $textSpan = substr($textSpan, 0, $posStringStart) . ' - ' . substr($textSpan, $posStringStart, $posDashString - $posStringStart) . substr($textSpan, $posDashString + 3); |
||
| 1077 | } |
||
| 1078 | |||
| 1079 | // Strip leading spaces from the RTL text |
||
| 1080 | $countLeadingSpaces = 0; |
||
| 1081 | while ($textSpan !== '') { |
||
| 1082 | if (str_starts_with($textSpan, ' ')) { |
||
| 1083 | $countLeadingSpaces++; |
||
| 1084 | $textSpan = substr($textSpan, 1); |
||
| 1085 | continue; |
||
| 1086 | } |
||
| 1087 | if (str_starts_with($textSpan, ' ')) { |
||
| 1088 | $countLeadingSpaces++; |
||
| 1089 | $textSpan = substr($textSpan, 6); |
||
| 1090 | continue; |
||
| 1091 | } |
||
| 1092 | break; |
||
| 1093 | } |
||
| 1094 | |||
| 1095 | // Strip trailing spaces from the RTL text |
||
| 1096 | $countTrailingSpaces = 0; |
||
| 1097 | while ($textSpan !== '') { |
||
| 1098 | if (str_ends_with($textSpan, ' ')) { |
||
| 1099 | $countTrailingSpaces++; |
||
| 1100 | $textSpan = substr($textSpan, 0, -1); |
||
| 1101 | continue; |
||
| 1102 | } |
||
| 1103 | if (str_ends_with($textSpan, ' ')) { |
||
| 1104 | $countTrailingSpaces++; |
||
| 1105 | $textSpan = substr($textSpan, 0, -6); |
||
| 1106 | continue; |
||
| 1107 | } |
||
| 1108 | break; |
||
| 1109 | } |
||
| 1110 | |||
| 1111 | // Look for trailing " -", reverse it, and relocate it to the front of the string |
||
| 1112 | if (str_ends_with($textSpan, ' -')) { |
||
| 1113 | $posDashString = strlen($textSpan) - 2; |
||
| 1114 | $posStringStart = strrpos(substr($textSpan, 0, $posDashString), '<RTLbr>'); |
||
| 1115 | if ($posStringStart === false) { |
||
| 1116 | $posStringStart = 0; |
||
| 1117 | } else { |
||
| 1118 | $posStringStart += 9; |
||
| 1119 | } // Point to the first char following the last <RTLbr> |
||
| 1120 | |||
| 1121 | $textSpan = substr($textSpan, 0, $posStringStart) . '- ' . substr($textSpan, $posStringStart, $posDashString - $posStringStart) . substr($textSpan, $posDashString + 2); |
||
| 1122 | } |
||
| 1123 | |||
| 1124 | if ($countLeadingSpaces !== 0) { |
||
| 1125 | $newLength = strlen($textSpan) + $countLeadingSpaces; |
||
| 1126 | $textSpan = str_pad($textSpan, $newLength, ' ', I18N::direction() === 'rtl' ? STR_PAD_LEFT : STR_PAD_RIGHT); |
||
| 1127 | } |
||
| 1128 | if ($countTrailingSpaces !== 0) { |
||
| 1129 | if (I18N::direction() === 'ltr') { |
||
| 1130 | if ($trailingBreaks === '') { |
||
| 1131 | // Move trailing RTL spaces to front of following LTR span |
||
| 1132 | $newLength = strlen(self::$waitingText) + $countTrailingSpaces; |
||
| 1133 | self::$waitingText = str_pad(self::$waitingText, $newLength, ' ', STR_PAD_LEFT); |
||
| 1134 | } |
||
| 1135 | } else { |
||
| 1136 | $newLength = strlen($textSpan) + $countTrailingSpaces; |
||
| 1137 | $textSpan = str_pad($textSpan, $newLength); |
||
| 1138 | } |
||
| 1139 | } |
||
| 1140 | |||
| 1141 | // We're done: finish the span |
||
| 1142 | $textSpan = self::starredName($textSpan, 'RTL'); // Wrap starred name in <u> and </u> tags |
||
| 1143 | $result .= $textSpan . self::END_RTL; |
||
| 1144 | } |
||
| 1145 | |||
| 1146 | if (self::$currentState !== 'LTR' && self::$currentState !== 'RTL') { |
||
| 1147 | $result .= $textSpan; |
||
| 1148 | } |
||
| 1149 | |||
| 1150 | $result .= $trailingBreaks; // Get rid of any waiting <br> |
||
| 1151 | } |
||
| 1153 |