mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 23:29:54 +00:00
Implemented TextFormat::colorize() (#1837)
Implemented TextFormat::colorize() See 4c46087ffccc7f26835a1fc5bbf2ac60397884f9 for the initial discussion
This commit is contained in:
parent
3ea72a0bf9
commit
af7aef70db
@ -80,6 +80,18 @@ abstract class TextFormat{
|
|||||||
return str_replace("\x1b", "", preg_replace("/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/", "", $string));
|
return str_replace("\x1b", "", preg_replace("/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/", "", $string));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces placeholders of § with the correct character. Only valid codes (as in the constants of the TextFormat class) will be converted.
|
||||||
|
*
|
||||||
|
* @param string $string
|
||||||
|
* @param string $placeholder default "&"
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function colorize(string $string, string $placeholder = "&") : string{
|
||||||
|
return preg_replace('/' . preg_quote($placeholder, "/") . '([0-9a-fk-or])/u', TextFormat::ESCAPE . '$1', $string);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an JSON-formatted string with colors/markup
|
* Returns an JSON-formatted string with colors/markup
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user