#ifndef WONKY_STRING_H
#define WONKY_STRING_H WONKY_STRING_H
#include <wonky_string.hh>
#include <wonky_array.h>
/*
utf8 string
*/
struct wonky_str
{
/*cstring*/
unsigned char * _wonky_arr cs; /*wonky_array that is also \0 terminated*/
size_t number_of_glyphs;
};
struct wonky_string__stream_state
{
struct wonky_str *str;
size_t where;
};
struct wonky_str wonky_string_make();
struct wonky_str wonky_string_copy(const struct wonky_str str);
struct wonky_str wonky_string_from_cstr(const char *str);
size_t wonky_string_number_of_bytes(const struct wonky_str str);
size_t wonky_string_recount_glyphs(struct wonky_str *str);
size_t wonky_string_length(const struct wonky_str str);
_Bool wonky_string_oom(struct wonky_str str);
/*get element(unicode) value from index'th glyph, indices starting from 0*/
uint32_t wonky_string_glyph(const struct wonky_str str,size_t glyph_index);
/*returns the index of the starting byte of the utf8 encoded glyph_indexed glyph*/
size_t wonky_string_glyph_position(const struct wonky_str str,size_t glyph_index);
/*returns index of starting byte of next valid glyph after byte_index'th byte in string*/
size_t wonky_string_following_glyph_position(const struct wonky_str str,size_t byte_index);
/*
returns index of starting byte of next valid glyph going backwards in string after
byte_index'th byte in string.
TODO: currently not implemented and returns byte_index
*/
size_t wonky_string_previous_glyph_position(const struct wonky_str str,size_t byte_index);
/*
returns glyph value of utf8 encoded glyph starting at byte_index'th index'th byte of string
if utf8 encoded glyph at byte_index'th byte is invalid this function returns 0
*/
uint32_t wonky_string_glyph_at_position(const struct wonky_str str,size_t byte_index);
struct wonky_str_mark* wonky_string_mark_lines(const struct wonky_str str); /*returns a ga_array of marks*/
_Bool wonky_string_push_codepoint(struct wonky_str *str,uint32_t ch);
_Bool wonky_string_push_byte(struct wonky_str *str,unsigned char ch);
_Bool wonky_string_append(struct wonky_str *str,const char *right); /*right is \0 terminated*/
_Bool wonky_string_preppend(struct wonky_str *str,char *left); /*left is \0 terminated*/
_Bool wonky_string_insert(struct wonky_str *str,char *infix,size_t glyph_index);/*infix is \0 terminated*/
_Bool wonky_string_delete_chars(struct wonky_str *str,size_t starting_glyph_index,size_t number_of_glyphs);
_Bool wonky_string_eqal(const struct wonky_str a,const struct wonky_str b);
_Bool wonky_string_cequal(const struct wonky_str a,const char *b);
int wonky_string_printf(struct wonky_str *destination,const char *format,...);
int wonky_string_vprintf(struct wonky_str *destination,const char *format,va_list args);
short wonky__utf8_get_glyph_size_from_starting_codepoint(unsigned char leading_byte);
short wonky__utf8_glyph_size(struct wonky_str str,size_t byte_index);
uint32_t wonky__utf8_glyph_value(struct wonky_str str,size_t byte_index,short glyph_size);
short wonky__utf8_codepoint_size(uint32_t codepoint);
void wonky__utf8_encode_codepoint(unsigned char *where,uint32_t codepoint,short size);
struct wonky_stream wonky_string_stream(struct wonky_str *str);
void wonky_string_stream_delete(struct wonky_stream *stream);
ssize_t wonky_string__stream_read(void *state,void *dst,size_t num_bytes);
ssize_t wonky_string__stream_write(void *state,void *src,size_t num_bytes);
_Bool wonky_string__stream_fseek(void *state,size_t where,int whence);
_Bool wonky_string__stream_eof(void *state);
#endif