Last active
October 25, 2023 17:30
-
-
Save tinkerer-red/bac440768e5ed1cee78d9d7918ab3724 to your computer and use it in GitHub Desktop.
GMString
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
///feather ignore all | |
function GMString(_val_or_format, _arg1=undefined, _arg2=undefined, _arg3=undefined, _arg4=undefined, _arg5=undefined, _arg6=undefined, _arg7=undefined, _arg8=undefined, _arg9=undefined, _arg10=undefined, _arg11=undefined, _arg12=undefined, _arg13=undefined, _arg14=undefined, _arg15=undefined) : __GMString__() constructor{ | |
str = string(_val_or_format, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13, _arg14, _arg15); | |
length = string_length(str); | |
} | |
function GMStringExt(_val_or_format, _arg_array) : __GMString__() constructor{ | |
str = string_ext(_val_or_format, _arg_array); | |
length = string_length(str); | |
} | |
function GMStringFormat(_val, _total, _dec) : __GMString__() constructor{ | |
str = string_format(_val, _total, _dec); | |
length = string_length(str); | |
} | |
function GMStringJoin(_delim, _arg1=undefined, _arg2=undefined, _arg3=undefined, _arg4=undefined, _arg5=undefined, _arg6=undefined, _arg7=undefined, _arg8=undefined, _arg9=undefined, _arg10=undefined, _arg11=undefined, _arg12=undefined, _arg13=undefined, _arg14=undefined, _arg15=undefined) : __GMString__() constructor{ | |
str = string_join(_delim, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13, _arg14, _arg15); | |
length = string_length(str); | |
} | |
function GMStringJoinExt(_delim, _arg_array, _offset=0, _length=array_length(_arg_array)) : __GMString__() constructor{ | |
str = string_join_ext(_delim, _arg_array, _offset, _length); | |
length = string_length(str); | |
} | |
function GMStringConcat(_arg0, _arg1=undefined, _arg2=undefined, _arg3=undefined, _arg4=undefined, _arg5=undefined, _arg6=undefined, _arg7=undefined, _arg8=undefined, _arg9=undefined, _arg10=undefined, _arg11=undefined, _arg12=undefined, _arg13=undefined, _arg14=undefined, _arg15=undefined) : __GMString__() constructor{ | |
str = string_concat(_arg0, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13, _arg14, _arg15); | |
length = string_length(str); | |
} | |
function GMStringConcatExt(_val_array, _offset=0, _length=array_length(_val_array)) : __GMString__() constructor{ | |
str = string_concat_ext(_val_array, _offset, _length); | |
length = string_length(str); | |
} | |
function __GMString__() constructor { | |
//Character Code | |
static byte_at = function(_index) { return string_byte_at(str, _index); }; | |
static byte_length = function() { return string_byte_length(str); }; | |
static set_byte_at = function(_index, _val) { string_set_byte_at(str, _index, _val); length = string_length(str); return self; }; | |
static char_at = function(_index) { return string_char_at(str, _index); }; | |
static ord_at = function(_index) { return string_ord_at(str, _index); }; | |
//Searching and Information | |
//static length = function() { return string_length(str); }; | |
static pos = function(_substr) { return string_pos(_substr, str); }; | |
static pos_ext = function(_substr, _startpos) { return string_pos_ext(_substr, str, _startpos); }; | |
static last_pos = function(_substr) { return string_last_pos(_substr, str); }; | |
static last_pos_ext = function(_substr, _startpos) { return string_last_pos_ext(_substr, str, _startpos); }; | |
static starts_with = function(_substr) { return string_starts_with(str, _substr); }; | |
static ends_with = function(_substr) { return string_ends_with(str, _substr); }; | |
static count = function(_substr) { return string_count(_substr, str); }; | |
//Manipulating Strings | |
static copy = function(_index, _count) { return new GMString(string_copy(str, _index, _count)); }; | |
static digits = function() { return new GMString(string_digits(str)); }; | |
static insert = function(_substr, _index) { return new GMString(string_insert(_substr, str, _index)); }; | |
static letters = function() { return new GMString(string_letters(str)); }; | |
static lettersdigits = function() { return new GMString(string_lettersdigits(str)); }; | |
static lower = function() { return new GMString(string_lower(str)); }; | |
static replace = function(_substr, _newstr) { return new GMString(string_replace(str, _substr, _newstr)); }; | |
static replace_all = function(_substr, _newstr) { return new GMString(string_replace_all(str, _substr, _newstr)); }; | |
static upper = function() { return new GMString(string_upper(str)); }; | |
static hash_to_newline = function() { return new GMString(string_hash_to_newline(str)); }; | |
static trim = function(_substr) { return new GMString(string_trim(str, _substr)); }; | |
static trim_start = function(_substr) { return new GMString(string_trim_start(str, _substr)); }; | |
static trim_end = function(_substr) { return new GMString(string_trim_end(str, _substr)); }; | |
static split = function(_delim, _remove_empty=false, _max_splits=infinity) { return string_split(str, _delim, _remove_empty, _max_splits); }; | |
static split_ext = function(_delim_array, _remove_empty=false, _max_splits=infinity) { return string_split_ext(str, _delim_array, _remove_empty, _max_splits); }; | |
//Manipulating This String | |
static concat = function(_arg0, _arg1=undefined, _arg2=undefined, _arg3=undefined, _arg4=undefined, _arg5=undefined, _arg6=undefined, _arg7=undefined, _arg8=undefined, _arg9=undefined, _arg10=undefined, _arg11=undefined, _arg12=undefined, _arg13=undefined, _arg14=undefined) { str = string_concat(str, _arg0, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13, _arg14); length = string_length(str); return self; }; | |
static concat_ext = function(_values_array, _offset=0, _length=array_length(_values_array)) { | |
var _new_values_array = [str]; | |
array_copy(_new_values_array, 1, _values_array, _offset, _length); | |
str = string_concat_ext(_new_values_array, 0, array_length(_new_values_array)); | |
length = string_length(str) | |
return self; | |
} | |
static join = function(_delim, _arg0, _arg1=undefined, _arg2=undefined, _arg3=undefined, _arg4=undefined, _arg5=undefined, _arg6=undefined, _arg7=undefined, _arg8=undefined, _arg9=undefined, _arg10=undefined, _arg11=undefined, _arg12=undefined, _arg13=undefined, _arg14=undefined) { str = string_join(_delim, str, _arg0, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13, _arg14); length = string_length(str); length = string_length(str); return self; }; | |
static join_ext = function(_delim, _values_array, _offset=0, _length=array_length(_values_array)) { | |
var _new_values_array = [str]; | |
array_copy(_new_values_array, 1, _values_array, _offset, _length); | |
str = string_join_ext(_delim, _new_values_array, 0, array_length(_new_values_array)); | |
length = string_length(str); | |
return self; | |
} | |
//Drawing-Related | |
static width = function(_font=draw_get_font()) { var _pre_font=draw_get_font(); draw_set_font(_font); var _r=string_width(str); draw_set_font(_pre_font); return _r; }; | |
static width_ext = function(_sep, _w, _font=draw_get_font()) { var _pre_font=draw_get_font(); draw_set_font(_font); var _r=string_width_ext(str, _sep, _w); draw_set_font(_pre_font); return _r; }; | |
static height = function(_font=draw_get_font()) { var _pre_font=draw_get_font(); draw_set_font(_font); var _r=string_height(str); draw_set_font(_pre_font); return _r; }; | |
static height_ext = function(_sep, _w, _font=draw_get_font()) { var _pre_font=draw_get_font(); draw_set_font(_font); var _r=string_height_ext(str, _sep, _w); draw_set_font(_pre_font); return _r; }; | |
//Iteration | |
static foreach = function(_func, _pos=0, _length=string_length(str)) { string_foreach(str, _func, _pos, _length) return self; }; | |
//Methods | |
static toString = function() { return str; }; | |
static valueOf = function(){ return real(str); } | |
//Debugging: show_debug_message and show_debug_message_ext | |
static get_clipboard_text = function() { str = clipboard_get_text; length = string_length(str); return self}; | |
static set_clipboard_text = function() { clipboard_set_text(str); return self }; | |
//these are not capable of being used as they are already keywords for GML Alternitives are supplied as replacements | |
//static delete = function(_index, _count) { return new GMString(string_delete(str, _index, _count)); }; | |
//static repeat = function(_count) { return new GMString(string_repeat(str, _count)); }; | |
static remove = function(_index, _count) { return new GMString(string_delete(str, _index, _count)); }; | |
static repeated = function(_count) { return new GMString(string_repeat(str, _count)); }; | |
//javascript methods | |
//note these are still 1 indexed string methods | |
//string flags are ignored, though if someone is interested in adding them please reach out. | |
static slice = function(_start, _end=string_length(str)+1) { | |
var _pos = (_start >= 0) ? _start : string_length(str)+1+_start; | |
_end = (_end >= 0) ? _end : string_length(str)+1+_end; | |
var _count = _end-_pos; | |
return new GMString(string_copy(str, _pos, _count)); | |
}; | |
static substring = function(_start, _end=string_length(str)+1) { | |
_start = max(_start, 0); | |
_end = max(_end , 0); | |
return slice(_start, _end); | |
} | |
static substr = function(_start, _count=string_length(str)+1) { | |
var _pos = (_start >= 0) ? _start : string_length(str)+1+_start; | |
return new GMString(string_copy(str, _pos, _count)); | |
} | |
static replaceAll = replace_all; | |
static toUpperCase = function() { str = string_upper(str); return self; }; | |
static toLowerCase = function() { str = string_lower(str); return self; }; | |
static trimStart = trim_start; | |
static trimEnd = trim_end; | |
static padStart = function(_count, _substr) { | |
str = string_repeat(_substr, _count)+str; | |
length = string_length(str) | |
return self; | |
} | |
static padEnd = function(_count, _substr) { | |
str = str+string_repeat(_substr, _count); | |
length = string_length(str) | |
return self; | |
} | |
static charAt = char_at; | |
static charCodeAt = byte_at; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment