Pixel-Composer/scripts/string_splice/string_splice.gml

38 lines
785 B
Text
Raw Normal View History

2023-07-12 16:28:32 +02:00
function string_splice(str, delim = " ", keep = false) {
2022-01-13 05:24:03 +01:00
var st = [];
var ss = str;
var sp;
2023-07-12 16:28:32 +02:00
if(!is_array(delim)) delim = [ delim ];
2022-01-13 05:24:03 +01:00
2023-07-12 16:28:32 +02:00
while(1) {
sp = 99999;
var found = false;
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(delim); i < n; i++ ) {
2023-07-12 16:28:32 +02:00
var pos = string_pos(delim[i], ss);
if(pos) {
sp = min(sp, pos);
found = true;
}
}
2022-01-13 05:24:03 +01:00
2023-07-12 16:28:32 +02:00
if(!found) { //no delim left
2023-01-04 02:30:04 +01:00
array_push(st, ss);
break;
2022-01-13 05:24:03 +01:00
} else {
2023-07-12 16:28:32 +02:00
var _ss = string_copy(ss, 1, keep? sp : sp - 1);
2023-01-04 02:30:04 +01:00
array_push(st, _ss);
2022-01-13 05:24:03 +01:00
}
2023-07-12 16:28:32 +02:00
2022-01-13 05:24:03 +01:00
ss = string_copy(ss, sp + 1, string_length(ss) - sp);
2023-07-12 16:28:32 +02:00
}
2022-01-13 05:24:03 +01:00
return st;
2022-11-18 03:20:31 +01:00
}
function string_title(str) {
str = string_replace_all(str, "_", " ");
2022-11-18 03:20:31 +01:00
var ch = string_char_at(str, 1);
ch = string_upper(ch);
var rs = string_copy(str, 2, string_length(str) - 1);
return ch + rs;
2022-01-13 05:24:03 +01:00
}