/** * Returns the paths to the subdirectories found by a wildcard pattern. * * Wildcard patterns use "\*" to match zero or more arbitrary characters, except the character of "/", and "?" to * match any single arbitrary character, again except the character of "/". For example, "\*.png" pattern searches * for all PNG images in the *current* directory, and "/path/to/any\*subdir/\*thumb-year-201?\*" searches for all * thumbnail images dated by the years of 2010-2019 and that are contained in the directories with a path matching * the rest of the pattern. Distinct from regular expressions, wildcard patterns need to be anchored at both ends, * so if the pattern in the last example was not concluded with "\*", no images would be found. Wildcards also * support character classes, such as "[abc]" and "[0-9]" as well as "[^abc]" and "[^0-9]", which however is only a * small portion of what regular expressions can do. * * To also search among the subdirectories that are contained in the subdirectories of the specified wildcard * pattern and so on, you can use `findDirectoriesRecursive` method. * * The returned paths are always absolute. * * @param string $wildcardPattern The wildcard pattern to be used for searching. * @param bool $sort **OPTIONAL. Default is** `false`. Tells whether the returned paths should be sorted, in the * ascending order. * * @return CArrayObject The paths to the subdirectories found by the wildcard pattern specified. * * @link #method_findDirectoriesRecursive findDirectoriesRecursive */ public static function findDirectories($wildcardPattern, $sort = false) { assert('is_cstring($wildcardPattern) && is_bool($sort)', vs(isset($this), get_defined_vars())); $wildcardPattern = CFilePath::frameworkPath($wildcardPattern); $paSearchRes = glob($wildcardPattern, GLOB_NOSORT | GLOB_ONLYDIR); assert('is_cmap($paSearchRes)', vs(isset($this), get_defined_vars())); $searchRes = CArray::fromPArray($paSearchRes); if ($sort) { CArray::sortUStringsNatCi($searchRes); } return oop_a($searchRes); }
public function testSortUStringsNatCi() { $array = CArray::fromElements("c", "B", "d", "E", "D", "C", "a", "e", "b", "A3", "A20", "A100"); CArray::sortUStringsNatCi($array, CUString::COLLATION_DEFAULT); $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "A3", "A20", "A100", "b", "B", "C", "c", "d", "D", "e", "E"))); $array = CArray::fromElements("č", "B", "d", "E", "D", "C", "á", "ê", "b", "A3", "A20", "A100"); CArray::sortUStringsNatCi($array, CUString::COLLATION_IGNORE_ACCENTS); $this->assertTrue(CArray::equals($array, CArray::fromElements("á", "A3", "A20", "A100", "b", "B", "C", "č", "d", "D", "ê", "E"))); $array = CArray::fromElements(" c", ",B", ".d", ":E", ";D", "!C", "?a", "\"e", "(b", "[A3", "[A20", "[A100"); CArray::sortUStringsNatCi($array, CUString::COLLATION_IGNORE_NONWORD); $this->assertTrue(CArray::equals($array, CArray::fromElements("?a", "[A3", "[A20", "[A100", "(b", ",B", "!C", " c", ".d", ";D", "\"e", ":E"))); $array = CArray::fromElements("c", "B", "d", "E", "D", "C", "a", "e", "b", "A3", "A20", "A100"); CArray::sortUStringsNatCi($array, CUString::COLLATION_UPPERCASE_FIRST); $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "A3", "A20", "A100", "b", "B", "C", "c", "d", "D", "e", "E"))); }
/** * Sorts the elements in an array of Unicode or ASCII strings, in the ascending order, case-insensitively, using * natural order comparison. * * To illustrate natural order with an example, an array with strings "a100", "a20", "a3" would be sorted into the * same array with `sortUStringsCi` method, but as "a3", "a20", "a100" with this method, which is the order a human * being would choose. * * @param bitfield $collationFlags **OPTIONAL. Default is** `CUStringObject::COLLATION_DEFAULT`. The Unicode * collation option(s) to be used for string comparison. See the [CUStringObject](CUStringObject.html) class for * information on collation options. * @param CULocale $inLocale **OPTIONAL. Default is** *the application's default locale*. The locale in which * strings are to be compared with each other. * * @return void * * @link CUStringObject.html CUStringObject */ public function sortUStringsNatCi($collationFlags = CUStringObject::COLLATION_DEFAULT, CULocale $inLocale = null) { CArray::sortUStringsNatCi($this->m_splArray, $collationFlags, $inLocale); }