incase the parameter type is 1. string - returns a string in which the order of all characters in the original string have been reversed. 2. array - returns an array in which the order of all elements in the original array have been reversed.
| 120 | // 1. string - returns a string in which the order of all characters in the original string have been reversed. |
| 121 | // 2. array - returns an array in which the order of all elements in the original array have been reversed. |
| 122 | SIValue AR_REVERSE(SIValue *argv, int argc, void *private_data) { |
| 123 | if(SIValue_IsNull(argv[0])) return SI_NullVal(); |
| 124 | |
| 125 | SIValue value = argv[0]; |
| 126 | if(SI_TYPE(value) == T_STRING) { |
| 127 | // string reverse |
| 128 | char *str = value.stringval; |
| 129 | size_t str_len = strlen(str); |
| 130 | char *reverse = rm_malloc((str_len + 1) * sizeof(char)); |
| 131 | |
| 132 | char *reverse_i = reverse + str_len; |
| 133 | utf8proc_int32_t c; |
| 134 | utf8proc_ssize_t w; |
| 135 | while(str[0] != 0) { |
| 136 | w = utf8proc_iterate((const utf8proc_uint8_t *)str, -1, &c); |
| 137 | str += w; |
| 138 | reverse_i -= w; |
| 139 | utf8proc_encode_char(c, (utf8proc_uint8_t *)reverse_i); |
| 140 | } |
| 141 | reverse[str_len] = '\0'; |
| 142 | return SI_TransferStringVal(reverse); |
| 143 | } else { |
| 144 | SIValue reverse = SI_CloneValue(value); |
| 145 | array_reverse(reverse.array); |
| 146 | return reverse; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // returns a substring of the original string, beginning with a 0-based index start and length. |
| 151 | SIValue AR_SUBSTRING(SIValue *argv, int argc, void *private_data) { |
nothing calls this directly
no test coverage detected