"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/sds.c" between
redis-6.2.4.tar.gz and redis-6.2.5.tar.gz

About: redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

sds.c  (redis-6.2.4):sds.c  (redis-6.2.5)
skipping to change at line 762 skipping to change at line 762
ep = end = s+sdslen(s)-1; ep = end = s+sdslen(s)-1;
while(sp <= end && strchr(cset, *sp)) sp++; while(sp <= end && strchr(cset, *sp)) sp++;
while(ep > sp && strchr(cset, *ep)) ep--; while(ep > sp && strchr(cset, *ep)) ep--;
len = (sp > ep) ? 0 : ((ep-sp)+1); len = (sp > ep) ? 0 : ((ep-sp)+1);
if (s != sp) memmove(s, sp, len); if (s != sp) memmove(s, sp, len);
s[len] = '\0'; s[len] = '\0';
sdssetlen(s,len); sdssetlen(s,len);
return s; return s;
} }
/* Changes the input string to be a subset of the original.
* It does not release the free space in the string, so a call to
* sdsRemoveFreeSpace may be wise after. */
void sdssubstr(sds s, size_t start, size_t len) {
/* Clamp out of range input */
size_t oldlen = sdslen(s);
if (start >= oldlen) start = len = 0;
if (len > oldlen-start) len = oldlen-start;
/* Move the data */
if (len) memmove(s, s+start, len);
s[len] = 0;
sdssetlen(s,len);
}
/* Turn the string into a smaller (or equal) string containing only the /* Turn the string into a smaller (or equal) string containing only the
* substring specified by the 'start' and 'end' indexes. * substring specified by the 'start' and 'end' indexes.
* *
* start and end can be negative, where -1 means the last character of the * start and end can be negative, where -1 means the last character of the
* string, -2 the penultimate character, and so forth. * string, -2 the penultimate character, and so forth.
* *
* The interval is inclusive, so the start and end characters will be part * The interval is inclusive, so the start and end characters will be part
* of the resulting string. * of the resulting string.
* *
* The string is modified in-place. * The string is modified in-place.
* *
* NOTE: this function can be misleading and can have unexpected behaviour,
* specifically when you want the length of the new string to be 0.
* Having start==end will result in a string with one character.
* please consider using sdssubstr instead.
*
* Example: * Example:
* *
* s = sdsnew("Hello World"); * s = sdsnew("Hello World");
* sdsrange(s,1,-1); => "ello World" * sdsrange(s,1,-1); => "ello World"
*/ */
void sdsrange(sds s, ssize_t start, ssize_t end) { void sdsrange(sds s, ssize_t start, ssize_t end) {
size_t newlen, len = sdslen(s); size_t newlen, len = sdslen(s);
if (len == 0) return; if (len == 0) return;
if (start < 0) { if (start < 0)
start = len+start; start = len + start;
if (start < 0) start = 0; if (end < 0)
} end = len + end;
if (end < 0) {
end = len+end;
if (end < 0) end = 0;
}
newlen = (start > end) ? 0 : (end-start)+1; newlen = (start > end) ? 0 : (end-start)+1;
if (newlen != 0) { sdssubstr(s, start, newlen);
if (start >= (ssize_t)len) {
newlen = 0;
} else if (end >= (ssize_t)len) {
end = len-1;
newlen = (start > end) ? 0 : (end-start)+1;
}
}
if (start && newlen) memmove(s, s+start, newlen);
s[newlen] = 0;
sdssetlen(s,newlen);
} }
/* Apply tolower() to every character of the sds string 's'. */ /* Apply tolower() to every character of the sds string 's'. */
void sdstolower(sds s) { void sdstolower(sds s) {
size_t len = sdslen(s), j; size_t len = sdslen(s), j;
for (j = 0; j < len; j++) s[j] = tolower(s[j]); for (j = 0; j < len; j++) s[j] = tolower(s[j]);
} }
/* Apply toupper() to every character of the sds string 's'. */ /* Apply toupper() to every character of the sds string 's'. */
skipping to change at line 1357 skipping to change at line 1362
test_cond("sdsrange(...,1,100)", test_cond("sdsrange(...,1,100)",
sdslen(y) == 3 && memcmp(y,"iao\0",4) == 0); sdslen(y) == 3 && memcmp(y,"iao\0",4) == 0);
sdsfree(y); sdsfree(y);
y = sdsdup(x); y = sdsdup(x);
sdsrange(y,100,100); sdsrange(y,100,100);
test_cond("sdsrange(...,100,100)", test_cond("sdsrange(...,100,100)",
sdslen(y) == 0 && memcmp(y,"\0",1) == 0); sdslen(y) == 0 && memcmp(y,"\0",1) == 0);
sdsfree(y); sdsfree(y);
y = sdsdup(x);
sdsrange(y,4,6);
test_cond("sdsrange(...,4,6)",
sdslen(y) == 0 && memcmp(y,"\0",1) == 0);
sdsfree(y);
y = sdsdup(x);
sdsrange(y,3,6);
test_cond("sdsrange(...,3,6)",
sdslen(y) == 1 && memcmp(y,"o\0",2) == 0);
sdsfree(y);
sdsfree(x); sdsfree(x);
x = sdsnew("foo"); x = sdsnew("foo");
y = sdsnew("foa"); y = sdsnew("foa");
test_cond("sdscmp(foo,foa)", sdscmp(x,y) > 0); test_cond("sdscmp(foo,foa)", sdscmp(x,y) > 0);
sdsfree(y); sdsfree(y);
sdsfree(x); sdsfree(x);
x = sdsnew("bar"); x = sdsnew("bar");
y = sdsnew("bar"); y = sdsnew("bar");
test_cond("sdscmp(bar,bar)", sdscmp(x,y) == 0); test_cond("sdscmp(bar,bar)", sdscmp(x,y) == 0);
 End of changes. 6 change blocks. 
20 lines changed or deleted 37 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)