Pixel-Composer/scripts/string_cut/string_cut.gml

56 lines
1.0 KiB
Plaintext
Raw Normal View History

2022-12-12 09:08:03 +01:00
function string_cut(str, w, tail = "...", scale = 1) {
var ww = 0;
var ind = 1;
var ss = "";
var _str = str;
var tw = string_width(tail) * scale;
2022-11-01 03:06:03 +01:00
if(string_width(str) <= w) return str;
2022-01-13 05:24:03 +01:00
var amo = string_length(str);
for( var i = 1; i <= amo; i++ ) {
var ch = string_char_at(str, 1);
str = string_copy(str, 2, string_length(str) - 1);
2022-11-01 03:06:03 +01:00
var _w = string_width(ch) * scale;
2022-01-13 05:24:03 +01:00
ww += _w;
var _tl = string_width(str) * scale;
if(ww + tw > w)
return ww + _tl <= w? _str : ss + tail;
ss += ch;
2022-01-13 05:24:03 +01:00
}
return ss;
}
function string_cut_line(str, w) {
var i = 1;
var ss = "";
var ww = 0;
while(i <= string_length(str) ) {
var _chr = string_char_at(str, i);
ss += _chr;
ww += string_width(_chr);
if(ww > w) {
ww = 0;
ss += "\n";
}
i++;
}
return ss;
2023-06-05 18:27:53 +02:00
}
function string_reduce(str) {
str = string_lower(str);
str = string_replace_all(str, " ", "_");
str = string_replace_all(str, "\\", "");
str = string_replace_all(str, "/", "");
str = string_replace_all(str, "'", "");
return str;
2022-01-13 05:24:03 +01:00
}