From 743b78ff031a08844861a7ad1c15f9541cb124ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BE=D0=BA=D1=80=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=20=D0=98=D0=B2=D0=B0=D0=BD?= Date: Thu, 24 Jan 2019 22:10:29 +0300 Subject: [PATCH] encoder support --- common.tc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ common.th | 0 2 files changed, 46 insertions(+) create mode 100644 common.tc create mode 100644 common.th diff --git a/common.tc b/common.tc new file mode 100644 index 0000000..f6f9481 --- /dev/null +++ b/common.tc @@ -0,0 +1,46 @@ +//// You must free the result if result is non-NULL. +//char *str_replace(char *orig, char *rep, char *with) { +// char *result; // the return string +// char *ins; // the next insert point +// char *tmp; // varies +// int len_rep; // length of rep (the string to remove) +// int len_with; // length of with (the string to replace rep with) +// int len_front; // distance between rep and end of last rep +// int count; // number of replacements + +// // sanity checks and initialization +// if (!orig || !rep) +// return null; +// len_rep = len(rep); +// if (len_rep == 0) +// return null; // empty rep causes infinite loop during count +// if (!with) +// with = ""; +// len_with = len(with); + +// // count the number of replacements needed +// ins = orig; +// for (count = 0; tmp = instr(ins, rep); ++count) { +// ins = tmp + len_rep; +// } + +// tmp = result = malloc(len(orig) + (len_with - len_rep) * count + 1); + +// if (!result) +// return null; + +// // first time through the loop, all the variable are set correctly +// // from here on, +// // tmp points to the end of the result string +// // ins points to the next occurrence of rep in orig +// // orig points to the remainder of orig after "end of rep" +// while (count--) { +// ins = instr(orig, rep); +// len_front = ins - orig; +// tmp = mid(tmp, orig, len_front) + len_front; +// tmp = strcpy(tmp, with) + len_with; +// orig += len_front + len_rep; // move to next "end of rep" +// } +// strcpy(tmp, orig); +// return result; +//} \ No newline at end of file diff --git a/common.th b/common.th new file mode 100644 index 0000000..e69de29