File:  [ELWIX - Embedded LightWeight unIX -] / libelwix / example / test_find2replace.c
Revision 1.1.2.1: download - view: text, annotated - select for diffs - revision graph
Sat Oct 26 14:24:07 2024 UTC (3 weeks, 6 days ago) by misho
Branches: elwix6_4
Adds new UT

#include <stdio.h>
#include <string.h>
#include <elwix.h>


int
main(int argc, char **argv)
{
	int mlen, hm;
	char *str;
	const char *cs = "ABCDEF123GHIJ321KL123MNOP123QRST122UWV123XYZ";
	const char *csb = "123ABCDEF123GHIJ321KL123MNOP123QRST122UWV123XYZ";
	const char *cse = "ABCDEF123GHIJ321KL123MNOP123QRST122UWV123XYZ123";
	const char *csn = "";
	const char *cso = "AB";

	hm = str_find2replace(cs, "123", NULL, NULL, NULL);
	printf("s&r howmany=%d only\n", hm);

	hm = str_find2replace(cs, "123", "*3245*", &str, &mlen);
	printf("s&r howmany=%d origin=%s new(%d)=%s\n", hm, cs, mlen, str);
	e_free(str);
	hm = str_find2replace(csb, "123", "*3245*", &str, &mlen);
	printf("s&r howmany=%d origin=%s new(%d)=%s\n", hm, csb, mlen, str);
	e_free(str);
	hm = str_find2replace(cse, "123", "*3245*", &str, &mlen);
	printf("s&r howmany=%d origin=%s new(%d)=%s\n", hm, cse, mlen, str);
	e_free(str);
	hm = str_find2replace(csn, "123", "*3245*", &str, &mlen);
	printf("s&r howmany=%d origin=%s new(%d)=%s\n", hm, csn, mlen, str);
	e_free(str);
	hm = str_find2replace(cso, "123", "*3245*", &str, &mlen);
	printf("s&r howmany=%d origin=%s new(%d)=%s\n", hm, cso, mlen, str);
	e_free(str);

	hm = str_find2replace(cs, "123", NULL, &str, &mlen);
	printf("s&e howmany=%d origin=%s new(%d)=%s\n", hm, cs, mlen, str);
	e_free(str);

	hm = str_find2replace(cs, "123", "*", &str, &mlen);
	printf("s&r howmany=%d origin=%s new(%d)=%s\n", hm, cs, mlen, str);
	e_free(str);
	return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>