Skip to content

Commit

Permalink
Merge branch 'fixEmptyWhitespaceTokens'
Browse files Browse the repository at this point in the history
  • Loading branch information
heiglandreas committed Jun 4, 2018
2 parents 3a0b61a + 62cdff2 commit 1354e79
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Tokenizer/EmptyToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Copyright (c) 2008-2011 Andreas Heigl<andreas@heigl.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @category Hyphenation
* @package Org_Heigl_Hyphenator
* @subpackage Tokenizer
* @author Andreas Heigl <andreas@heigl.org>
* @copyright 2008-2011 Andreas Heigl<andreas@heigl.org>
* @license http://www.opensource.org/licenses/mit-license.php MIT-License
* @version 2.0.beta
* @link http://github.com/heiglandreas/Hyphenator
* @since 11.11.2011
*/

namespace Org\Heigl\Hyphenator\Tokenizer;

/**
* This Class describes a Token containing nothing
*
* @category Hyphenation
* @package Org_Heigl_Hyphenator
* @subpackage Tokenizer
* @author Andreas Heigl <andreas@heigl.org>
* @copyright 2008-2011 Andreas Heigl<andreas@heigl.org>
* @license http://www.opensource.org/licenses/mit-license.php MIT-License
* @version 2.0.beta
* @link http://github.com/heiglandreas/Hyphenator
* @since 04.11.2011
*/
class EmptyToken extends Token
{
//
}
4 changes: 4 additions & 0 deletions src/Tokenizer/WhitespaceTokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ private function tokenize($input)
$splits = preg_split("/([".implode("", $this->whitespaces)."]+)/u", $input, -1, PREG_SPLIT_DELIM_CAPTURE);

foreach ($splits as $split) {
if ($split === '') {
$tokens[] = new EmptyToken($split);
continue;
}
if (preg_match("/^[".implode("", $this->whitespaces)."]+$/um", $split)) {
$tokens[] = new WhitespaceToken($split);
continue;
Expand Down

0 comments on commit 1354e79

Please sign in to comment.