1<?php 2 3declare(strict_types=1); 4 5namespace Antlr\Antlr4\Runtime\Utils; 6 7final class StringUtils 8{ 9 private const ENCODING = 'UTF-8'; 10 11 private function __construct() 12 { 13 } 14 15 public static function escapeWhitespace(string $string, bool $escapeSpaces = false) : string 16 { 17 if ($string === '') { 18 return $string; 19 } 20 21 $string = \str_replace(["\n", "\r", "\t"], ['\n', '\r', '\t'], $string); 22 23 if ($escapeSpaces) { 24 $string = \preg_replace('/ /', "\u00B7", $string); 25 } 26 27 return $string ?? ''; 28 } 29 30 public static function char(int $code) : string 31 { 32 return \mb_chr($code, self::ENCODING); 33 } 34 35 public static function codePoint(string $code) : int 36 { 37 return \mb_ord($code, self::ENCODING); 38 } 39} 40