+ string = silc_strdup("foobar");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "s/foo/bar/"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch, "barbar", 6))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar foobar");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "s/foo/bar/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch, "barbar barbar", 13))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar foobar");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "s/foo/bar/"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch, "barbar foobar", 13))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar foobar\nfoobar");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "s/foo/BARBAR/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch, "BARBARbar\nBARBARbar BARBARbar\nBARBARbar",
+ 39))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar foobar\nfoobar");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "s/foo/BARBAR/"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch, "BARBARbar\nBARBARbar foobar\nBARBARbar",
+ 36))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar foobar\nfoobar");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "s/foo//"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch, "bar\nbar foobar\nbar",
+ 18))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar foobar\nfoobar");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "s/foo/B/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch, "Bbar\nBbar Bbar\nBbar",
+ 19))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar foobar\nfoobar");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "s/foo/B/"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch, "Bbar\nBbar foobar\nBbar",
+ 21))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nBfoobar foobar\nBfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "/^B/s/foo/B/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch, "foobar\nBBbar Bbar\nBBbar\nfoo",
+ 27))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar baz foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "/baz/s/foo/BARBAR/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "foobar\nBARBARbar baz BARBARbar\nbazBARBARbar\nfoo",
+ 47))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar baz foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "/baz/s/foo/BARBAR/"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "foobar\nBARBARbar baz foobar\nbazBARBARbar\nfoo",
+ 44))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar baz foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "/baz/!s/foo/BARBAR/"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "BARBARbar\nfoobar baz foobar\nbazfoobar\nBARBAR",
+ 44))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar baz foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "2s/foo/BARBAR/"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "foobar\nBARBARbar baz foobar\nbazfoobar\nfoo",
+ 41))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar baz foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "2s/foo/BARBAR/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "foobar\nBARBARbar baz BARBARbar\nbazfoobar\nfoo",
+ 44))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar baz foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "200s/foo/BARBAR/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "foobar\nfoobar baz foobar\nbazfoobar\nfoo",
+ 38))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar baz foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "2!s/foo/BARBAR/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "BARBARbar\nfoobar baz foobar\nbazBARBARbar\nBARBAR",
+ 47))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar baz foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "/xxx/s/foo/BARBAR/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "foobar\nfoobar baz foobar\nbazfoobar\nfoo",
+ 38))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar baz foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "!s/foo/BARBAR/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "foobar\nfoobar baz foobar\nbazfoobar\nfoo",
+ 38))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar baz foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "$s/foo/BARBAR/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "foobar\nfoobar baz foobar\nbazfoobar\nBARBAR",
+ 41))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar baz foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "$!s/foo/BARBAR/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "BARBARbar\nBARBARbar baz BARBARbar\nbazBARBARbar\nfoo",
+ 50))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar /baz/ foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "s/\\//BARBAR/g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "foobar\nfoobar BARBARbazBARBAR foobar\nbazfoobar\nfoo",
+ 50))
+ goto err;
+ silc_buffer_purge(&bmatch);
+
+ string = silc_strdup("foobar\nfoobar /baz/ foobar\nbazfoobar\nfoo");
+ SILC_LOG_DEBUG(("Replace %s", string));
+ silc_buffer_set(&bmatch, string, strlen(string));
+ if (!silc_subst(&bmatch, "s/\\//\\/\\//g"))
+ goto err;
+ silc_buffer_printf(&bmatch, TRUE);
+ if (!silc_buffer_memcmp(&bmatch,
+ "foobar\nfoobar //baz// foobar\nbazfoobar\nfoo",
+ 42))
+ goto err;
+ silc_buffer_purge(&bmatch);
+