PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Calculation / Internal / WildcardMatch.php

WildcardMatch.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Calculation/Internal/WildcardMatch.php

40 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\Internal;
4
5 class WildcardMatch
6 {
7 private const SEARCH_SET = [
8 '~~', // convert double tilde to unprintable value
9 '~\*', // convert tilde backslash asterisk to [*] (matches literal asterisk in regexp)
10 '\*', // convert backslash asterisk to .* (matches string of any length in regexp)
11 '~\?', // convert tilde backslash question to [?] (matches literal question mark in regexp)
12 '\?', // convert backslash question to . (matches one character in regexp)
13 "\x1c", // convert original double tilde to single tilde
14 ];
15
16 private const REPLACEMENT_SET = [
17 "\x1c",
18 '[*]',
19 '.*',
20 '[?]',
21 '.',
22 '~',
23 ];
24
25 public static function wildcard(string $wildcard): string
26 {
27 // Preg Escape the wildcard, but protecting the Excel * and ? search characters
28 return str_replace(self::SEARCH_SET, self::REPLACEMENT_SET, preg_quote($wildcard, '/'));
29 }
30
31 public static function compare(?string $value, string $wildcard): bool
32 {
33 if ($value === '' || $value === null) {
34 return false;
35 }
36
37 return (bool) preg_match("/^{$wildcard}\$/mui", $value);
38 }
39 }
40