ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ProvideUTF8CodepointRange.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 {
39  private static function oneByteRangeExcept(array $ignore = []): array
40  {
41  $byte_range = range(0, 0xFE);
42  $set_names = array_map(fn(int $codepoint) => 'Codepoint: ' . $codepoint, $byte_range);
43 
44  return array_combine(
45  $set_names,
46  array_map(
47  fn(string $chr, int $codepoint) => (
48  self::ctype_alnum($chr) || in_array($chr, $ignore, true) ?
49  self::asDataProviderArgs($chr, 'assertSame') :
50  self::asDataProviderArgs(self::isAscii($codepoint) ? $chr : self::twoByteChar($codepoint), 'assertNotSame')
51  ),
52  array_map(chr(...), $byte_range),
53  $byte_range
54  )
55  );
56  }
57 
61  private static function ctype_alnum(string $chr): bool
62  {
63  return preg_match('/^[a-zA-Z0-9]+$/', $chr) > 0;
64  }
65 
66  private static function isAscii(int $codepoint): bool
67  {
68  return $codepoint <= 127;
69  }
70 
75  private static function twoByteChar(int $codepoint): string
76  {
77  return chr($codepoint >> 6 & 0x3f | 0xc0) . chr($codepoint & 0x3f | 0x80);
78  }
79 
84  private static function asDataProviderArgs(string $chr, string $method): array
85  {
86  return [$chr, $chr, $method];
87  }
88 }