mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-11-14 14:33:53 +01:00
77 lines
1.8 KiB
Plaintext
77 lines
1.8 KiB
Plaintext
// 2024-04-16 08:41:19
|
|
function string_to_array(str) { #region
|
|
var amo = string_length(str);
|
|
var arr = array_create(amo);
|
|
for( var i = 0; i < amo; i++ )
|
|
arr[i] = string_char_at(str, i + 1);
|
|
return arr;
|
|
} #endregion
|
|
|
|
function string_partial_match(str, key) { #region
|
|
var amo = string_length(str);
|
|
var run = 1;
|
|
var consec = 0;
|
|
var conMax = 0;
|
|
var misMatch = 0;
|
|
var kchr = string_char_at(key, run);
|
|
|
|
for( var i = 1; i <= amo; i++ ) {
|
|
var ch = string_char_at(str, i);
|
|
if(ch == kchr) {
|
|
consec++;
|
|
conMax = max(conMax, consec);
|
|
run++;
|
|
if(run > string_length(key)) return conMax - (misMatch + (amo - i));
|
|
kchr = string_char_at(key, run);
|
|
} else {
|
|
consec = 0;
|
|
misMatch += amo - i;
|
|
}
|
|
}
|
|
|
|
return -9999;
|
|
} #endregion
|
|
|
|
function string_real(val, digMax = 999, decMin = 5) { #region
|
|
if(is_string(val)) return val;
|
|
if(is_struct(val)) return string(val);
|
|
|
|
if(is_array(val)) {
|
|
var s = "[";
|
|
var i = 0, n = array_length(val);
|
|
repeat( n ) { s += (i? ", " : "") + string_real(val[i]); i++; }
|
|
return s + "]";
|
|
}
|
|
|
|
if(val == 0 || !is_numeric(val)) return "0";
|
|
|
|
var pres, p = 1;
|
|
var presMax = min(decMin, digMax - ceil(log10(ceil(abs(val)))));
|
|
for( pres = 0; pres < presMax; pres++ ) {
|
|
if(frac(val * p) == 0)
|
|
break;
|
|
p *= 10;
|
|
}
|
|
|
|
return string_format(val, -1, pres);
|
|
} #endregion
|
|
|
|
function string_char_last(str, shift = 0) { #region
|
|
INLINE
|
|
return string_char_at(str, string_length(str) - shift);
|
|
} #endregion
|
|
|
|
function filename_name_only(name) { #region
|
|
name = filename_name(name);
|
|
return string_replace(name, filename_ext(name), "")
|
|
} #endregion
|
|
|
|
function string_to_var(str) { #region
|
|
INLINE
|
|
return string_replace_all(string_lower(str), " ", "_");
|
|
} #endregion
|
|
|
|
function string_quote(str) { #region
|
|
INLINE
|
|
return $"\"{str}\"";
|
|
} #endregion |