-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NumericFixer to add Non Breaking Space between numeric and unit
fix #15.
- Loading branch information
1 parent
2ce5ce2
commit 351221f
Showing
9 changed files
with
95 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace JoliTypo\Fixer; | ||
|
||
use JoliTypo\Fixer; | ||
use JoliTypo\FixerInterface; | ||
use JoliTypo\StateBag; | ||
|
||
/** | ||
* Add nbsp between numeric and units. | ||
*/ | ||
class Numeric implements FixerInterface | ||
{ | ||
public function fix($content, StateBag $state_bag = null) | ||
{ | ||
// Support a wide range of currencies | ||
$content = preg_replace('@([\dº])( +)([º°%฿₵¢₡$₫֏€ƒ₲₴₭£₤₺₦₨₱៛₹$₪৳₸₮₩¥\w]{1})@', '$1'.Fixer::NO_BREAK_SPACE.'$3', $content); | ||
|
||
return $content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
namespace JoliTypo\Tests\Fixer; | ||
|
||
use JoliTypo\Fixer; | ||
|
||
class NumericTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testNumericUnits() | ||
{ | ||
$fixer = new Fixer\Numeric(); | ||
$this->assertInstanceOf('JoliTypo\Fixer\Numeric', $fixer); | ||
|
||
$this->assertEquals("Test", $fixer->fix("Test")); | ||
$this->assertEquals("1".Fixer::NO_BREAK_SPACE."h", $fixer->fix("1 h")); | ||
$this->assertEquals("2".Fixer::NO_BREAK_SPACE."฿", $fixer->fix("2 ฿")); | ||
$this->assertEquals("3".Fixer::NO_BREAK_SPACE."things", $fixer->fix("3 things")); | ||
$this->assertEquals("4,5".Fixer::NO_BREAK_SPACE."km", $fixer->fix("4,5 km")); | ||
$this->assertEquals("5.1".Fixer::NO_BREAK_SPACE."deg", $fixer->fix("5.1 deg")); | ||
$this->assertEquals("6".Fixer::NO_BREAK_SPACE."ºC", $fixer->fix("6 ºC")); | ||
$this->assertEquals("7".Fixer::NO_BREAK_SPACE."$", $fixer->fix("7 $")); | ||
$this->assertEquals("8º".Fixer::NO_BREAK_SPACE."18′ 30″", $fixer->fix("8º 18′ 30″")); | ||
$this->assertEquals("9".Fixer::NO_BREAK_SPACE."hours", $fixer->fix("9 hours")); | ||
$this->assertEquals("10e position", $fixer->fix("10e position")); // We can't fix this reliably | ||
$this->assertEquals("nº".Fixer::NO_BREAK_SPACE."11", $fixer->fix("nº 11")); | ||
$this->assertEquals("12".Fixer::NO_BREAK_SPACE."%", $fixer->fix("12 %")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
in which
?