StringUtil.php 808 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the nelexa/zip package.
  5. * (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace PhpZip\Util;
  10. /**
  11. * String Util.
  12. *
  13. * @internal
  14. */
  15. final class StringUtil
  16. {
  17. public static function endsWith(string $haystack, string $needle): bool
  18. {
  19. return $needle === '' || ($haystack !== '' && substr_compare($haystack, $needle, -\strlen($needle)) === 0);
  20. }
  21. public static function isBinary(string $string): bool
  22. {
  23. return strpos($string, "\0") !== false;
  24. }
  25. public static function isASCII(string $name): bool
  26. {
  27. return preg_match('~[^\x20-\x7e]~', $name) === 0;
  28. }
  29. }