Skip to content

Instantly share code, notes, and snippets.

@McTwist
Last active November 15, 2017 12:46
Show Gist options
  • Save McTwist/1606d73d96e990874941ab6c4a608dec to your computer and use it in GitHub Desktop.
Save McTwist/1606d73d96e990874941ab6c4a608dec to your computer and use it in GitHub Desktop.
A secure way to echo out strings in TorqueScript larger than 4095 characters
// Echo a huge string in a safe way
// Note: It will try to make the output consistent, but too long chunks with
// no newline will break the consistency
function echos(%str)
{
// Maximum amount of characters that can be output with normal echo
%max = 4095;
%len = strlen(%str);
for (%i = 0; %i < %len; %i += getMin(%size + 1, %max))
{
%size = %max;
%pos = strpos(%str, "\n", %i);
if (%pos > %i && %pos < %i + %size)
%size = %pos - %i;
echo(getSubStr(%str, %i, %size));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment