"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "odt2txt-0.4/strbuf.h" of archive odt2txt-0.4.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /*
    2  * strbuf.c: A simple string buffer
    3  *
    4  * Copyright (c) 2006-2008 Dennis Stosberg <dennis@stosberg.net>
    5  *
    6  * This program is free software; you can redistribute it and/or
    7  * modify it under the terms of the GNU General Public License,
    8  * version 2 as published by the Free Software Foundation
    9  */
   10 
   11 #ifndef STRBUF_H
   12 #define STRBUF_H
   13 
   14 #include "mem.h"
   15 #include "zlib.h"
   16 
   17 typedef struct strbuf {
   18 	char *data;
   19 	size_t len;
   20 	size_t buf_sz;
   21 	int opt;
   22 } STRBUF;
   23 
   24 enum strbuf_opt {
   25 	STRBUF_NULLOK = 1
   26 };
   27 
   28 /*
   29  * Initialize a new empty string buffer.
   30  */
   31 STRBUF *strbuf_new(void);
   32 
   33 /*
   34  * Free a string buffer.
   35  */
   36 void strbuf_free(STRBUF *buf);
   37 
   38 /*
   39  * Appends the n first characters from str to the string buffer.
   40  *
   41  * Returns the new length of the string buffer.
   42  */
   43 size_t strbuf_append_n(STRBUF *buf, const char *str, size_t n);
   44 
   45 /*
   46  * Appends str to the string buffer.
   47  *
   48  * Returns the new length of the string buffer.
   49  */
   50 size_t strbuf_append(STRBUF *buf, const char *str);
   51 
   52 /*
   53  * Reads a zlib-compressed data stream from in and appends
   54  * it to the buffer out.  Returns the number of appended characters.
   55  */
   56 size_t strbuf_append_inflate(STRBUF *buf, FILE *in);
   57 
   58 /*
   59  * Returns a pointer to the contained string.
   60  */
   61 const char *strbuf_get(STRBUF *buf);
   62 
   63 /*
   64  * Returns the length of the contained string.
   65  */
   66 size_t strbuf_len(STRBUF *buf);
   67 
   68 /*
   69  * Reallocs the data structure in the string buffer to use not more
   70  * memory than necessary.
   71  */
   72 void strbuf_shrink(STRBUF *buf);
   73 
   74 /*
   75  * Creates a string buffer from a *char without copying.
   76  */
   77 STRBUF *strbuf_slurp(char *str);
   78 STRBUF *strbuf_slurp_n(char *str, size_t len);
   79 
   80 /*
   81  * Returns the contained string and destroys the string buffer.
   82  */
   83 char *strbuf_spit(STRBUF *buf);
   84 
   85 /*
   86  * Substitute characters in the string buffer buf from start
   87  * (inclusive) to end (exclusive) and replace them with *subst. The
   88  * first character in the string has the index 0.
   89  *
   90  * Returns the change of the length of the string contained at *buf.
   91  * The return value is negative, if the string is shortened, zero if
   92  * the length is unchanged and positive if the length increases.
   93  *
   94  * If start is bigger than stop, their values are automatically
   95  * swapped.
   96  */
   97 int strbuf_subst(STRBUF *buf, size_t start, size_t stop,
   98 	      const char *subst);
   99 
  100 /*
  101  * Set options for the string buffer
  102  */
  103 void strbuf_setopt(STRBUF *buf, enum strbuf_opt opt);
  104 
  105 /*
  106  * Unset an option for the string buffer
  107  */
  108 void strbuf_unsetopt(STRBUF *buf, enum strbuf_opt opt);
  109 
  110 /*
  111  * Return the crc32 checksum of the buffer content.
  112  */
  113 unsigned int strbuf_crc32(STRBUF *buf);
  114 
  115 #endif /* STRBUF_H */
  116