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