Homec4science

Add a `phutil_fnmatch` function

Authored by Joshua Spence <josh@joshuaspence.com> on Jan 28 2015, 21:11.

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
Joshua Spence <josh@joshuaspence.com>Jan 28 2015, 21:37
Pushed
aubortMar 17 2017, 12:03
Parents
rPHU2acdbcbd19ef: Add a `phutil_ini_decode` function
Branches
Unknown
Tags
Unknown

Event Timeline

Joshua Spence <josh@joshuaspence.com> committed rPHU04f81f9d9e66: Add a `phutil_fnmatch` function (authored by Joshua Spence <josh@joshuaspence.com>).Jan 28 2015, 21:37