/* str.h - include file for the counted-string package */

#ifndef _STR_H_
#define _STR_H_

#include <sys/types.h>
#include <sys/queue.h>


/* String. */

typedef struct {
    size_t size, len;
    char* bytes;
    } str;

str* str_create( void );
void str_clear( str* s );
size_t str_len( str* s );
void str_destroy( str* s );
bool str_copy( str* tos, char* frombytes, size_t len );
bool str_append( str* tos, char* frombytes, size_t len );
bool str_append_char( str* tos, char fromc );
bool str_prepend( str* tos, char* frombytes, size_t len );
bool str_prepend_char( str* tos, char fromc );


/* String ring. */

TAILQ_HEAD( str_ring_head, str_ring_entry );
typedef struct str_ring_head str_ring;

str_ring* str_ring_create( void );
bool str_ring_empty( str_ring* sr );
bool str_ring_addfirst( str_ring* sr, str* s );
bool str_ring_addlast( str_ring* sr, str* s );
str* str_ring_removefirst( str_ring* sr );
str* str_ring_removelast( str_ring* sr );
str* str_ring_first( str_ring* sr );
void str_ring_destroy( str_ring* sr );

#endif /* _STR_H_ */
