@@ -748,33 +748,48 @@ private function parseWord($word)
748748 {
749749 $ wordLength = mb_strlen ($ word );
750750
751- // Is this word smaller than the minimal length requirement?
752751 if ($ wordLength < $ this ->minHyphenLeft + $ this ->minHyphenRight
753752 || $ wordLength < $ this ->minWordLength ) {
754753 return [$ word ];
755754 }
756755
757756 $ wordLowerCased = mb_strtolower ($ word );
758757
759- // Is it a pre-hyphenated word?
760758 if (isset ($ this ->hyphenation [$ wordLowerCased ])) {
761- $ hyphenation = $ this ->hyphenation [$ wordLowerCased ];
762- $ hyphenationLength = mb_strlen ($ hyphenation );
763- $ parts = [];
764- $ part = '' ;
765- for ($ i = 0 , $ j = 0 ; $ i < $ hyphenationLength ; $ i ++) {
766- if (mb_substr ($ hyphenation , $ i , 1 ) !== '- ' ) {
767- $ part .= mb_substr ($ word , $ j ++, 1 );
768- } else {
769- $ parts [] = $ part ;
770- $ part = '' ;
771- }
772- }
773- if (!empty ($ part )) {
759+ return $ this ->parseWordByHyphenation ($ word , $ wordLowerCased );
760+ } else {
761+ return $ this ->parseWordByPatterns ($ word , $ wordLength , $ wordLowerCased );
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 {
774778 $ parts [] = $ part ;
779+ $ part = '' ;
775780 }
776- return $ parts ;
777781 }
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 );
778793
779794 // Convenience array
780795 $ text = '. ' .$ wordLowerCased .'. ' ;
0 commit comments