Modify the string substituting all the occurrences of the set of * characters specified in the 'from' string to the corresponding character * in the 'to' array. * * For instance: sdsmapchars(mystring, "ho", "01", 2) * will have the effect of turning the string "hello" into "0ell1". * * The function returns the sds string pointer, that is always the same * as the input pointer since no resi
| 1076 | * The function returns the sds string pointer, that is always the same |
| 1077 | * as the input pointer since no resize is needed. */ |
| 1078 | sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen) { |
| 1079 | size_t j, i, l = sdslen(s); |
| 1080 | |
| 1081 | for (j = 0; j < l; j++) { |
| 1082 | for (i = 0; i < setlen; i++) { |
| 1083 | if (s[j] == from[i]) { |
| 1084 | s[j] = to[i]; |
| 1085 | break; |
| 1086 | } |
| 1087 | } |
| 1088 | } |
| 1089 | return s; |
| 1090 | } |
| 1091 | |
| 1092 | /* Join an array of C strings using the specified separator (also a C string). |
| 1093 | * Returns the result as an sds string. */ |