File:  [ELWIX - Embedded LightWeight unIX -] / libelwix / example / test_find2replace.c
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Mon Oct 28 09:58:51 2024 UTC (3 weeks, 4 days ago) by misho
Branches: MAIN
CVS tags: elwix6_6, elwix6_5, HEAD, ELWIX6_5, ELWIX6_4
Version 6.4

#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>