/* Example: wchar_t * dynamic strings (wgds_t), standard dynamic string type */
/* Part of genvector examples (http://repo.hu/projects/genvector) */
#include <stdio.h>
#include <genvector/gds_wchar.h>

/* print the string with a prefix */
static void dump(const char *prefix, wgds_t *s)
{
	if (s->array == NULL)
		printf("%-16s<NULL>\n", prefix);
	else
		printf("%-16s'%ls'\n", prefix, s->array);
}

int main()
{
	int n;
	wgds_t s, s2;

	/* Initialize the string (to empty, which means the array is not allocated) */
	wgds_init(&s);
	dump("empty: ", &s);


	/* append a..j, char by char */
	for(n = 0; n < 10; n++)
		wgds_append(&s, 'a'+n);
	dump("append: ", &s);

	/* append a char * static string */
	wgds_append_str(&s, L", hah, ");
	dump("append_str: ", &s);

	/* truncate after 8 characters */
	wgds_truncate(&s, 8);
	dump("truncate: ", &s);

	/* Concat two strings: sort of "s += s2" */
	wgds_init(&s2);
	wgds_append_str(&s2, L", hello");
	wgds_concat(&s, &s2);
	dump("concat: ", &s);

	/* Array is still just a char * string */
	printf("wcschr:         '%ls'\n", wcschr(s.array, 'e'));

	/* It can be read or written as a char * array, within bounds */
	s.array[5] = L'!';
	dump("array asg: ", &s);

	/* Remove a mid-section of the string, 3 characters starting from [9] */
	wgds_remove(&s, 9, 3);
	dump("remove: ", &s);

	/* Free memory */
	wgds_uninit(&s);
	wgds_uninit(&s2);

	return 0;
}
