Skip to content

Commit

Permalink
Merge branch 'clairecoloma-master2', ref #13
Browse files Browse the repository at this point in the history
  • Loading branch information
damienalexandre committed Jul 13, 2015
2 parents f2111bc + 569874d commit 9860817
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ CHANGELOG

### ??? ###

* new NoSpaceBeforeComma fixer, cleaning badly placed spaces close to commas

### 0.1.4 (2014-06-17) ###

* add HHVM tests on travis
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ FrenchNoBreakSpace
Replace some classic spaces by non breaking spaces following the French typographic code.
No break space are placed before `:`, thin no break space before `;`, `!` and `?`.

NoSpaceBeforeComma
------------------

Remove space before `,` and make sure there is only one space after.

Hyphen (automatic hyphenation)
------------------------------

Expand Down Expand Up @@ -143,7 +148,7 @@ en_GB
-----

```php
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Dash', 'EnglishQuotes', 'CurlyQuote', 'Hyphen', 'Trademark'));
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Dash', 'EnglishQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'));
$fixer->setLocale('en_GB'); // Needed by the Hyphen Fixer
```

Expand All @@ -153,7 +158,7 @@ fr_FR
Those rules apply most of the recommendations of "Abrégé du code typographique à l'usage de la presse", ISBN: 9782351130667.

```php
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Dash', 'FrenchQuotes', 'FrenchNoBreakSpace', 'CurlyQuote', 'Hyphen', 'Trademark'));
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Dash', 'FrenchQuotes', 'FrenchNoBreakSpace', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'));
$fixer->setLocale('fr_FR'); // Needed by the Hyphen Fixer
```

Expand All @@ -163,7 +168,7 @@ fr_CA
Mostly the same as fr_FR, but the space before punctuation points is not mandatory.

```php
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Dash', 'FrenchQuotes', 'CurlyQuote', 'Hyphen', 'Trademark'));
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Dash', 'FrenchQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'));
$fixer->setLocale('fr_CA'); // Needed by the Hyphen Fixer
```

Expand All @@ -173,7 +178,7 @@ de_DE
Mostly the same as en_GB, according to [Typefacts](http://typefacts.com/) and [Wikipedia](http://de.wikipedia.org/wiki/Typografie_f%C3%BCr_digitale_Texte).

```php
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Dash', 'GermanQuotes', 'CurlyQuote', 'Hyphen', 'Trademark'));
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Dash', 'GermanQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'));
$fixer->setLocale('de_DE'); // Needed by the Hyphen Fixer
```

Expand Down
22 changes: 22 additions & 0 deletions src/JoliTypo/Fixer/NoSpaceBeforeComma.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace JoliTypo\Fixer;

use JoliTypo\Fixer;
use JoliTypo\FixerInterface;
use JoliTypo\StateBag;

/**
* No space before comma (,)
*
* @package JoliTypo\Fixer
*/
class NoSpaceBeforeComma implements FixerInterface
{
public function fix($content, StateBag $state_bag = null)
{
$content = preg_replace('@(\w+) *(,) *@mu', '$1$2 ', $content);

return $content;
}
}
20 changes: 20 additions & 0 deletions tests/JoliTypo/Tests/Fixer/NoSpaceBeforeCommaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace JoliTypo\Tests\Fixer;

use JoliTypo\Fixer;

/**
* @package JoliTypo\Tests\Fixer
*/
class NoSpaceBeforeCommaTest extends \PHPUnit_Framework_TestCase
{
public function testSimpleString()
{
$fixer = new Fixer\NoSpaceBeforeComma();
$this->assertInstanceOf('JoliTypo\Fixer\NoSpaceBeforeComma', $fixer);

$this->assertEquals("Superman, you're my hero", $fixer->fix("Superman,you're my hero"));
$this->assertEquals("Superman, you're my hero", $fixer->fix("Superman ,you're my hero"));
$this->assertEquals("Superman, you're my hero", $fixer->fix("Superman , you're my hero"));
}
}

0 comments on commit 9860817

Please sign in to comment.