crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs | LICENSE

buffer (1002B)


      1 #ifndef _BUFFER_
      2 #define _BUFFER_
      3 
      4 #include "../error/error"
      5 
      6 class Buffer {
      7 public:
      8     Buffer();
      9     Buffer(Buffer const &other);
     10     ~Buffer();
     11 
     12     Buffer &operator= (Buffer const &other);
     13     Buffer &operator= (char const *b);
     14 
     15     void set (char const *b, unsigned len);
     16     void add (char const *b, unsigned len);
     17     char const *data() const;
     18     int strfind (char const *s) const;
     19     char &operator[] (unsigned index);
     20     string stringat (unsigned index, unsigned len) const;
     21     void removeat (unsigned index, unsigned len = 1);
     22     void insertat (unsigned index, char const *s, unsigned len);
     23     void insertat (unsigned index, string s);
     24 
     25     // This ones are called often so let's inline them.
     26     unsigned size() const {
     27 	return (buf_len);
     28     }
     29     char charat (unsigned index) const {
     30 	if (index >= buf_len)
     31 	    return (0);
     32 	return (buf_data[index]);
     33     }
     34 	
     35 private:
     36     void copy (Buffer const &other);
     37     void destroy();
     38     
     39     char *buf_data;
     40     unsigned buf_len;
     41 };
     42 
     43 #endif