HomePhabricator

Add a `phutil_fnmatch` function

Authored by joshuaspence.

Description

Add a phutil_fnmatch function

Summary:
Ref T5105. This function is an improved version of fnmatch. Internally, this function converts a glob pattern into a regular expression and is based on Symfony\Component\Finder\Glob, with influence from editorconfig-core-js.

The PHP fnmatch() is inadequate for our use case for a variety of reasons:

  • Lack of error handling (fnmatch('{', '') does not throw an exception).
  • Lack of support for {} groupings (fnmatch('{a,b}', 'a') returns false).
  • **/* only matches in subdirectories (fnmatch('**/file', $x) matches $x = 'subdir/file' but does not match $x = 'file').
NOTE: At the moment, phutil_fnmatch() doesn't support $flags, whereas fnmatch does. In the future, we may wish to implement these flags. Currently, $flags is basiically equivalent to 0.

Test Plan: Added unit tests.

Reviewers: Blessed Reviewers, epriestley

Reviewed By: Blessed Reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T5105

Differential Revision: https://secure.phabricator.com/D11444

Details

Committed
joshuaspenceJan 28 2015, 8:37 PM
Pushed
joshuaspenceJan 28 2015, 8:39 PM
Reviewer
Blessed Reviewers
Differential Revision
D11444: Add a `phutil_fnmatch` function
Parents
rPHU2acdbcbd19ef: Add a `phutil_ini_decode` function
Branches
Unknown
Tags
Unknown
Tasks
T5105: Ensure that `ArcanistTextLinter` respects `.editorconfig` settings