+ if (!motif || !preg || !subst) {
+ return false;
+ }
+ /* extract 1st part */
+ POOLMEM *dest = bstrdup(motif);
+ char sep = motif[0];
+ char *search = motif + 1;
+ char *replace;
+ bool ok = false;
+ bool found_motif = false;
+
+ while (*search && !ok) {
+ if (*search == sep && *dest == '\\') {
+ *dest++ = *++search; /* we skip separator */
+
+ } else if (*search == sep) {
+ *dest++ = '\0';
+ if (found_motif) { /* already have found motif */
+ ok = true;
+ } else {
+ replace = dest; /* get replaced string */
+ found_motif = true;
+ }
+ } else {
+ *dest++ = *search++;
+ }
+ }
+ *dest = '\0'; /* in case of */
+
+ if (!ok || !found_motif) {
+ /* bad regexp */
+ free(dest);
+ return false;
+ }
+
+
+
+