returns the original string with trailing whitespace removed.
| 100 | |
| 101 | // returns the original string with trailing whitespace removed. |
| 102 | SIValue AR_RTRIM(SIValue *argv, int argc, void *private_data) { |
| 103 | if(SIValue_IsNull(argv[0])) return SI_NullVal(); |
| 104 | |
| 105 | char *str = argv[0].stringval; |
| 106 | |
| 107 | size_t i = strlen(str); |
| 108 | while(i > 0 && str[i - 1] == ' ') { |
| 109 | i --; |
| 110 | } |
| 111 | |
| 112 | char *trimmed = rm_malloc((i + 1) * sizeof(char)); |
| 113 | strncpy(trimmed, str, i); |
| 114 | trimmed[i] = '\0'; |
| 115 | |
| 116 | return SI_TransferStringVal(trimmed); |
| 117 | } |
| 118 | |
| 119 | // incase the parameter type is |
| 120 | // 1. string - returns a string in which the order of all characters in the original string have been reversed. |
no test coverage detected