Skip to content

Commit

Permalink
TASK: Adjusted hyphenation service
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-K committed Jan 17, 2017
1 parent 5826d6f commit b919581
Showing 1 changed file with 10 additions and 33 deletions.
43 changes: 10 additions & 33 deletions Classes/Service/HyphenationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,9 @@
* This script belongs to the TYPO3 Flow Package "Wegmeister.Hyphenator".
* This service handles the hyphenation of texts.
*
* wegmeister/hyphenator 1.0.0
* wegmeister/hyphenator 1.1.0
* Neos-Integration of the phpHyphenator with some enhancements on
* the pattern-converter by Benjamin Klix
*
* phpHyphenator 1.6.1
* Enhanced by Erik Krause
*
* based on
*
* phpHyphenator 1.6
* Enhanced by Liedtke.IT Jens Liedtke
* PHP version of the JavaScript Hyphenator version 3.1.0 by
* Mathias Nater, <a href = "mailto:[email protected]">[email protected]</a>
*
* based on
*
* phpHyphenator 1.5
* Developed by yellowgreen designbüro
* PHP version of the JavaScript Hyphenator 1.0 (Beta) by Matthias Nater
*
* Licensed under Creative Commons Attribution-Share Alike 2.5 Switzerland
* http://creativecommons.org/licenses/by-sa/2.5/ch/deed.en
*
* Associated pages:
* http://www.dokuwiki.org/plugin:hyphenation
*
* Special thanks to:
* Dave Gööck (webvariants.de)
* Markus Birth (birth-online.de)
* Nico Wenig (yellowgreen.de)
*/

use TYPO3\Flow\Annotations as Flow;
Expand Down Expand Up @@ -135,7 +108,7 @@ public function hyphenate($text, $locale = null)
->setFilters('Simple')
->setTokenizers('Whitespace,Punctuation');

$this->hyphenators[$locale] = new Hyphenator\Hyphenator;
$this->hyphenators[$locale] = new Hyphenator\Hyphenator();
$this->hyphenators[$locale]->setOptions($options);
}

Expand All @@ -158,7 +131,12 @@ public function hyphenate($text, $locale = null)
$word .= $char;
} else {
if ($word !== '') {
$output[] = $this->wordHyphenation($word, $locale);
$hyphenatedWord = $this->wordHyphenation($word, $locale);
if (is_array($hyphenatedWord)) {
$output[] = $hyphenatedWord[0];
} else {
$output[] = $hyphenatedWord;
}
$word = '';
}
if ($tag !== '' || $char === '<') {
Expand All @@ -180,7 +158,7 @@ public function hyphenate($text, $locale = null)
}
}

$text = join($output);
$text = implode($output);
return mb_substr($text, 0, mb_strlen($text) - 1);
}

Expand All @@ -193,8 +171,7 @@ public function hyphenate($text, $locale = null)
*/
protected function wordHyphenation($word, $locale)
{
if (mb_strlen($word) < $this->settings['shortestPattern']
|| mb_strpos($word, $this->settings['hyphen']) !== false
if (mb_strpos($word, $this->settings['hyphen']) !== false
|| mb_strpos($word, $this->settings['altHyphen']) !== false) {
return $word;
}
Expand Down

0 comments on commit b919581

Please sign in to comment.