Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Bom | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| exists | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| remove | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @license MIT |
| 5 | * @author hazuki3417<hazuki3417@gmail.com> |
| 6 | * @copyright 2024 hazuki3417 all rights reserved. |
| 7 | */ |
| 8 | |
| 9 | namespace Selen\Str; |
| 10 | |
| 11 | /** |
| 12 | * Byte Order Markに関する処理を提供するクラス |
| 13 | */ |
| 14 | class Bom |
| 15 | { |
| 16 | /** |
| 17 | * NOTE: 文字コードでBOM文字を作成。正規表現パターンではないので注意。 |
| 18 | */ |
| 19 | |
| 20 | /** @var string UTF-8のBOM文字列 */ |
| 21 | public const UTF_8 = '\xEF\xBB\xBF'; |
| 22 | |
| 23 | /** |
| 24 | * 文字列にByte Order Markが存在するか確認します |
| 25 | * |
| 26 | * @param string $value 文字列を渡します |
| 27 | * |
| 28 | * @return bool 存在する場合はtrueを、それ以外の場合はfalseを返します |
| 29 | */ |
| 30 | public static function exists(string $value): bool |
| 31 | { |
| 32 | $bom = self::UTF_8; |
| 33 | return preg_match("/{$bom}/", $value); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * 文字列からByte Order Markを除去します |
| 38 | * |
| 39 | * @param string $value 文字列を渡します |
| 40 | * |
| 41 | * @return string BOM文字を除去した文字列を返します |
| 42 | */ |
| 43 | public static function remove(string $value): string |
| 44 | { |
| 45 | $bom = self::UTF_8; |
| 46 | $replaceStr = ''; |
| 47 | return preg_replace("/{$bom}/", $replaceStr, $value); |
| 48 | } |
| 49 | } |