PageRenderTime 96ms CodeModel.GetById 28ms app.highlight 37ms RepoModel.GetById 15ms app.codeStats 1ms

/hiredis/sds.h

http://github.com/nicolasff/webdis
C++ Header | 105 lines | 63 code | 12 blank | 30 comment | 0 complexity | fcac58c6726607965d9936766e697a1f MD5 | raw file
  1/* SDS (Simple Dynamic Strings), A C dynamic strings library.
  2 *
  3 * Copyright (c) 2006-2014, Salvatore Sanfilippo <antirez at gmail dot com>
  4 * All rights reserved.
  5 *
  6 * Redistribution and use in source and binary forms, with or without
  7 * modification, are permitted provided that the following conditions are met:
  8 *
  9 *   * Redistributions of source code must retain the above copyright notice,
 10 *     this list of conditions and the following disclaimer.
 11 *   * Redistributions in binary form must reproduce the above copyright
 12 *     notice, this list of conditions and the following disclaimer in the
 13 *     documentation and/or other materials provided with the distribution.
 14 *   * Neither the name of Redis nor the names of its contributors may be used
 15 *     to endorse or promote products derived from this software without
 16 *     specific prior written permission.
 17 *
 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 28 * POSSIBILITY OF SUCH DAMAGE.
 29 */
 30
 31#ifndef __SDS_H
 32#define __SDS_H
 33
 34#define SDS_MAX_PREALLOC (1024*1024)
 35
 36#include <sys/types.h>
 37#include <stdarg.h>
 38#ifdef _MSC_VER
 39#include "win32.h"
 40#endif
 41
 42typedef char *sds;
 43
 44struct sdshdr {
 45    int len;
 46    int free;
 47    char buf[];
 48};
 49
 50static inline size_t sdslen(const sds s) {
 51    struct sdshdr *sh = (struct sdshdr *)(s-sizeof *sh);
 52    return sh->len;
 53}
 54
 55static inline size_t sdsavail(const sds s) {
 56    struct sdshdr *sh = (struct sdshdr *)(s-sizeof *sh);
 57    return sh->free;
 58}
 59
 60sds sdsnewlen(const void *init, size_t initlen);
 61sds sdsnew(const char *init);
 62sds sdsempty(void);
 63size_t sdslen(const sds s);
 64sds sdsdup(const sds s);
 65void sdsfree(sds s);
 66size_t sdsavail(const sds s);
 67sds sdsgrowzero(sds s, size_t len);
 68sds sdscatlen(sds s, const void *t, size_t len);
 69sds sdscat(sds s, const char *t);
 70sds sdscatsds(sds s, const sds t);
 71sds sdscpylen(sds s, const char *t, size_t len);
 72sds sdscpy(sds s, const char *t);
 73
 74sds sdscatvprintf(sds s, const char *fmt, va_list ap);
 75#ifdef __GNUC__
 76sds sdscatprintf(sds s, const char *fmt, ...)
 77    __attribute__((format(printf, 2, 3)));
 78#else
 79sds sdscatprintf(sds s, const char *fmt, ...);
 80#endif
 81
 82sds sdscatfmt(sds s, char const *fmt, ...);
 83void sdstrim(sds s, const char *cset);
 84void sdsrange(sds s, int start, int end);
 85void sdsupdatelen(sds s);
 86void sdsclear(sds s);
 87int sdscmp(const sds s1, const sds s2);
 88sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count);
 89void sdsfreesplitres(sds *tokens, int count);
 90void sdstolower(sds s);
 91void sdstoupper(sds s);
 92sds sdsfromlonglong(long long value);
 93sds sdscatrepr(sds s, const char *p, size_t len);
 94sds *sdssplitargs(const char *line, int *argc);
 95sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen);
 96sds sdsjoin(char **argv, int argc, char *sep, size_t seplen);
 97sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen);
 98
 99/* Low level functions exposed to the user API */
100sds sdsMakeRoomFor(sds s, size_t addlen);
101void sdsIncrLen(sds s, int incr);
102sds sdsRemoveFreeSpace(sds s);
103size_t sdsAllocSize(sds s);
104
105#endif