Changeset View
Changeset View
Standalone View
Standalone View
src/xsprintf/PhutilTerminalString.php
Show All 10 Lines | public function __construct($string) { | ||||
$this->string = $string; | $this->string = $string; | ||||
} | } | ||||
public function __toString() { | public function __toString() { | ||||
return $this->string; | return $this->string; | ||||
} | } | ||||
public function applyWrap() { | public function applyWrap() { | ||||
$string = (string)$this; | $string = phutil_string_cast($this); | ||||
$string = phutil_console_wrap($string); | $string = phutil_console_wrap($string); | ||||
return new self($string); | return new self($string); | ||||
} | } | ||||
public function applyIndent($depth, $with_prefix = true) { | public function applyIndent($depth, $with_prefix = true) { | ||||
$string = (string)$this; | $string = phutil_string_cast($this); | ||||
$string = phutil_console_wrap($string, $depth, $with_prefix); | $string = phutil_console_wrap($string, $depth, $with_prefix); | ||||
return new self($string); | return new self($string); | ||||
} | } | ||||
public static function escapeStringValue($value, $allow_whitespace) { | public static function escapeStringValue($value, $allow_whitespace) { | ||||
if ($value instanceof PhutilTerminalString) { | if ($value instanceof PhutilTerminalString) { | ||||
return (string)$value; | return phutil_string_cast($value); | ||||
} | } | ||||
$value = (string)$value; | if ($value instanceof ArcanistTerminalStringInterface) { | ||||
$value = $value->newTerminalString(); | |||||
return self::escapeStringValue($value, $allow_whitespace); | |||||
} | |||||
if ($value === null) { | |||||
return ''; | |||||
} | |||||
if (is_array($value)) { | |||||
if (!$value) { | |||||
return ''; | |||||
} | |||||
$parts = array(); | |||||
foreach ($value as $part) { | |||||
$part = self::escapeStringValue($part, $allow_whitespace); | |||||
$parts[] = $part; | |||||
} | |||||
return implode('', $parts); | |||||
} | |||||
$value = phutil_string_cast($value); | |||||
static $escape_map; | static $escape_map; | ||||
if ($escape_map === null) { | if ($escape_map === null) { | ||||
$escape_map = array( | $escape_map = array( | ||||
chr(0x00) => '<NUL>', | chr(0x00) => '<NUL>', | ||||
chr(0x07) => '<BEL>', | chr(0x07) => '<BEL>', | ||||
chr(0x08) => '<BS>', | chr(0x08) => '<BS>', | ||||
chr(0x09) => '<TAB>', | chr(0x09) => '<TAB>', | ||||
Show All 39 Lines |