Last active
November 15, 2017 12:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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