public static function dumpString(string $value): string
    {
        if ('' === $value) {
            return "''";
        }

        // non UTF-8 string will encode "\xFF" and require <">
        if (!self::isUtf8String($value)) {
            return '"' . \preg_replace_callback(
                // ---------------------------------------------------
                //     0x80 ..    0x7FF => C2 80       ... DF BF
                // ---------------------------------------------------
                //    0x800 ..    0xFFF => E0 A0 80    ... E0 BF BF
                //   0x1000 ..   0xFFFF => E1 80 80    ... EF BF BF
                // ---------------------------------------------------
                //  0x10000 ..  0x3FFFF => F0 90 80 80 ... F0 BF BF BF
                //  0x40000 ..  0xFFFFF => F1 80 80 80 ... F3 BF BF BF
                // 0x100000 .. 0x10FFFF => F4 80 80 80 ... F4 8F BF BF

                // " \x22
                // $ \x24
                // \ \x5C
                '/
                    \\G
                    (?:
                        [\\x20\\x21\\x23\\x25-\\x5B\\x5D-\\x7E]++
                        | [\\xC2-\\xDF] [\\x80-\\xBF]
                        | \\xE0 [\\xA0-\\xBF] [\\x80-\\xBF]
                        | [\\xE1-\\xEF] [\\x80-\\xBF]{2}
                        | \\xF0 [\\x90-\\xBF] [\\x80-\\xBF]{2}
                        | [\\xF1-\\xF3] [\\x80-\\xBF]{3}
                        | \\xF4 [\\x80-\\x8F] [\\x80-\\xBF]{2}
                    )*+
                    \\K
                    (?:
                        ( ["$\\\\] )
                        |
                        ( . )
                    )
                /xs',
                /** @uses _escapeStringCallback() */
                \Closure::fromCallable([__CLASS__, '_escapeStringCallback']),
                $value
            ) . '"';
        }

        // valid UTF-8 string with control ASCII characters
        // also will encode "\xFF" and require <">, but regexp is much simple
        if (\preg_match('/[\\x00-\\x1F\\x7F]/', $value)) {
            return '"' . \preg_replace_callback(
                '/(["$\\\\])|([\\x00-\\x1F\\x7F])/',
                /** @uses _escapeStringCallback() */
                \Closure::fromCallable([__CLASS__, '_escapeStringCallback']),
                $value
            ) . '"';
        }

        return \var_export($value, true);
    }