Skip to content

Commit

Permalink
Refined regex
Browse files Browse the repository at this point in the history
  • Loading branch information
mauretto78 committed Aug 8, 2023
1 parent 11af7c2 commit bd46e92
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 39 deletions.
10 changes: 0 additions & 10 deletions src/Filters/Sprintf/language/de-AT/not_allowed.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Filters/Sprintf/language/de-CH/not_allowed.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Filters/Sprintf/language/de-DE/not_allowed.php

This file was deleted.

8 changes: 7 additions & 1 deletion src/Filters/SprintfToPH.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public function __construct() {
* 20%-zar - ignored
*</code>
*
* @see
* - https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265-SW1
* - https://en.cppreference.com/w/c/io/fprintf
* - https://www.php.net/manual/en/function.sprintf.php
* - https://www.w3resource.com/c-programming/stdio/c_library_method_sprintf.php
*
* @param $segment
*
* @return string
Expand All @@ -45,7 +51,7 @@ public function transform( $segment ) {
$segment = $sprintfLocker->lock( $segment );

// Octal parsing is disabled due to Hungarian percentages 20%-os
$regex = '/(?:\x25\x25)|(\x25(?:(?:[1-9]\d*)\$|\((?:[^\)]+)\))?(?:\+)?(?:0|[+-]?\'[^$])?(?:-)?(?:\d+)?(?:\.(?:\d+))?((?:[hjlqtzL]{0,2}([ac-gopsuxAC-GOSUX]{1})|(\-[a-z]{1,3}))(?![\d\w])|(?:#@[\w]+@)|(?:@)))/';
$regex = '/(?:\x25\x25)|(\x25(?:(?:[1-9]\d*)\$|\((?:[^\)]+)\))?(?:\+)?(?:0|[+-]?\'[^$])?(?:-)?(?:\d+)?(?:\.(?:\d+))?((?:[hjlqtzL]{0,2}[ac-giopsuxAC-GOSUX]{1})(?![\d\w])|(?:#@[\w]+@)|(?:@)))/';


preg_match_all( $regex, $segment, $vars, PREG_SET_ORDER );
Expand Down
8 changes: 0 additions & 8 deletions tests/SprintfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ private function runTests($notAllowed, $languageToTest)

$this->assertEquals($segment, $segmentL1);
$this->assertEquals($segment, $segmentL2);

$filter = MateCatFilter::getInstance( new FeatureSet(), 'en-US', 'it-IT' );

$segmentL1 = $filter->fromLayer0ToLayer1( $segment );
$segmentL2 = $filter->fromLayer0ToLayer2( $segment );

$this->assertNotEquals($segment, $segmentL1);
$this->assertNotEquals($segment, $segmentL2);
}
}
}

0 comments on commit bd46e92

Please sign in to comment.