CommandHelper
CommandHelper copied to clipboard
Add string_compare function and support integer return type in array_sort function
- Export functionality of Java's
String.compareTo(String)in MethodScript API. - Support integer return type in array_sort closure.
This is useful to convert hacky code such as:
array @arr = array(array('key': 'Hello'), array('key': 'World'), array('key': 'Aaahhh'));
@arr = array_sort(@arr, closure(@left, @right) {
return(array_sort(array(@left['key'], @right['key']), 'STRING')[0] === @right['key']);
});
into:
array @arr = array(array('key': 'Hello'), array('key': 'World'), array('key': 'Aaahhh'));
@arr = array_sort(@arr, closure(@left, @right) {
return(string_compare(@left['key'], @right['key']));
});
As a result from a discussion with @PseudoKnight, we decided that this PR should also include a string_compare_ic() function that works the same as string_compare(), except that it ignores casing.