@@ -748,19 +748,51 @@ 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
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 );
760762 }
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 );
761793
762794 // Convenience array
763- $ text = '. ' .mb_strtolower ( $ word ) .'. ' ;
795+ $ text = '. ' .$ wordLowerCased .'. ' ;
764796 $ textLength = $ wordLength + 2 ;
765797 $ patternLength = $ this ->maxPattern < $ textLength
766798 ? $ this ->maxPattern
0 commit comments