@@ -748,19 +748,51 @@ private function parseWord($word)
748
748
{
749
749
$ wordLength = mb_strlen ($ word );
750
750
751
- // Is this word smaller than the minimal length requirement?
752
751
if ($ wordLength < $ this ->minHyphenLeft + $ this ->minHyphenRight
753
752
|| $ wordLength < $ this ->minWordLength ) {
754
753
return [$ word ];
755
754
}
756
755
757
- // Is it a pre-hyphenated word?
758
- if (isset ($ this ->hyphenation [$ word ])) {
759
- return mb_split ('- ' , $ this ->hyphenation [$ word ]);
756
+ $ wordLowerCased = mb_strtolower ($ word );
757
+
758
+ if (isset ($ this ->hyphenation [$ wordLowerCased ])) {
759
+ return $ this ->parseWordByHyphenation ($ word , $ wordLowerCased );
760
+ } else {
761
+ return $ this ->parseWordByPatterns ($ word , $ wordLength , $ wordLowerCased );
760
762
}
763
+ }
764
+
765
+ private function parseWordByHyphenation ($ word , $ wordLowerCased = null )
766
+ {
767
+ $ wordLowerCased = $ wordLowerCased ?: mb_strtolower ($ word );
768
+
769
+ $ hyphenation = $ this ->hyphenation [$ wordLowerCased ];
770
+ $ hyphenationLength = mb_strlen ($ hyphenation );
771
+
772
+ $ parts = [];
773
+ $ part = '' ;
774
+ for ($ i = 0 , $ j = 0 ; $ i < $ hyphenationLength ; $ i ++) {
775
+ if (mb_substr ($ hyphenation , $ i , 1 ) !== '- ' ) {
776
+ $ part .= mb_substr ($ word , $ j ++, 1 );
777
+ } else {
778
+ $ parts [] = $ part ;
779
+ $ part = '' ;
780
+ }
781
+ }
782
+ if (!empty ($ part )) {
783
+ $ parts [] = $ part ;
784
+ }
785
+
786
+ return $ parts ;
787
+ }
788
+
789
+ private function parseWordByPatterns ($ word , $ wordLength = 0 , $ wordLowerCased = null )
790
+ {
791
+ $ wordLength = $ wordLength > 0 ? $ wordLength : mb_strlen ($ word );
792
+ $ wordLowerCased = $ wordLowerCased ?: mb_strtolower ($ word );
761
793
762
794
// Convenience array
763
- $ text = '. ' .mb_strtolower ( $ word ) .'. ' ;
795
+ $ text = '. ' .$ wordLowerCased .'. ' ;
764
796
$ textLength = $ wordLength + 2 ;
765
797
$ patternLength = $ this ->maxPattern < $ textLength
766
798
? $ this ->maxPattern
0 commit comments