You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.1 KiB
C

9 years ago
#include <string.h>
#include <sys/param.h>
#include <ctype.h>
#include "strings.h"
#include "sds.h"
RedisModuleString *RMUtil_CreateFormattedString(RedisModuleCtx *ctx, const char *fmt, ...) {
9 years ago
sds s = sdsempty();
va_list ap;
va_start(ap, fmt);
s = sdscatvprintf(s, fmt, ap);
va_end(ap);
RedisModuleString *ret = RedisModule_CreateString(ctx, (const char *)s, sdslen(s));
sdsfree(s);
return ret;
}
int RMUtil_StringEquals(RedisModuleString *s1, RedisModuleString *s2) {
9 years ago
9 years ago
9 years ago
const char *c1, *c2;
size_t l1, l2;
c1 = RedisModule_StringPtrLen(s1, &l1);
c2 = RedisModule_StringPtrLen(s2, &l2);
return strncmp(c1, c2, MAX(l1, l2)) == 0;
9 years ago
}
void RMUtil_StringToLower(RedisModuleString *s) {
9 years ago
size_t l;
char *c = (char *)RedisModule_StringPtrLen(s, &l);
size_t i;
for (i = 0; i < l; i++) {
*c = tolower(*c);
++c;
}
}
void RMUtil_StringToUpper(RedisModuleString *s) {
9 years ago
size_t l;
char *c = (char *)RedisModule_StringPtrLen(s, &l);
size_t i;
for (i = 0; i < l; i++) {
*c = toupper(*c);
++c;
}
9 years ago
}