@@ -54,6 +54,7 @@ class Syllable
5454 private $ patterns = null ;
5555 private $ maxPattern = null ;
5656 private $ hyphenation = null ;
57+ private $ userHyphenations = array ();
5758
5859 /**
5960 * Character encoding to use.
@@ -137,6 +138,19 @@ public function setLanguage($language)
137138 $ this ->setSource (new File ($ language , self ::$ languageDir ));
138139 }
139140
141+ /**
142+ * Add custom hyphenation patterns for words using a '-' to explicitly specify hyphenation (if any)
143+ * @param array $hyphenations
144+ * @return void
145+ */
146+ public function addHyphenations (array $ hyphenations )
147+ {
148+ foreach ($ hyphenations as $ pattern ) {
149+ $ word = str_replace ('- ' , '' , $ pattern );
150+ $ this ->userHyphenations [$ word ] = $ pattern ;
151+ }
152+ }
153+
140154 /**
141155 * Set the hyphen text or object to use as a hyphen marker.
142156 *
@@ -755,18 +769,19 @@ private function parseWord($word)
755769
756770 $ wordLowerCased = mb_strtolower ($ word );
757771
772+ if (isset ($ this ->userHyphenations [$ wordLowerCased ])) {
773+ return $ this ->parseWordByHyphenation ($ this ->userHyphenations [$ wordLowerCased ], $ word , $ wordLowerCased );
774+ }
775+
758776 if (isset ($ this ->hyphenation [$ wordLowerCased ])) {
759- return $ this ->parseWordByHyphenation ($ word , $ wordLowerCased );
760- } else {
761- return $ this ->parseWordByPatterns ($ word , $ wordLength , $ wordLowerCased );
777+ return $ this ->parseWordByHyphenation ($ this ->hyphenation [$ wordLowerCased ], $ word , $ wordLowerCased );
762778 }
779+
780+ return $ this ->parseWordByPatterns ($ word , $ wordLength , $ wordLowerCased );
763781 }
764782
765- private function parseWordByHyphenation ($ word , $ wordLowerCased = null )
783+ private function parseWordByHyphenation ($ hyphenation , $ word , $ wordLowerCased = null )
766784 {
767- $ wordLowerCased = $ wordLowerCased ?: mb_strtolower ($ word );
768-
769- $ hyphenation = $ this ->hyphenation [$ wordLowerCased ];
770785 $ hyphenationLength = mb_strlen ($ hyphenation );
771786
772787 $ parts = [];
0 commit comments