From 9d7c962ee8e4a8ee9a443f4385cb8dfa80a49296 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 6 Feb 2022 09:54:21 +1300 Subject: [PATCH] Clean up uses of Replace() We were passing flags of DOH_REPLACE_ANY|DOH_REPLACE_FIRST in three places, which doesn't make sense as those are mutually exclusive concepts. In the current implementation DOH_REPLACE_FIRST wins in this situation, so replace with that and clarify the docs. --- Doc/Manual/Extending.html | 5 +++++ Source/CParse/templ.c | 2 +- Source/Modules/main.cxx | 2 +- Source/Modules/ocaml.cxx | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index 5749f37ce..8e5dfb18b 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -1132,6 +1132,11 @@ DOH_REPLACE_FIRST - Replace first occurrence only. Returns the number of replacements made (if any).

+

+At most one of DOH_REPLACE_ANY and DOH_REPLACE_FIRST should be specified. +DOH_REPLACE_ANY is the default if neither is specified. +

+

40.5.2 Hashes

diff --git a/Source/CParse/templ.c b/Source/CParse/templ.c index 2f38cc2c2..9bd5a084c 100644 --- a/Source/CParse/templ.c +++ b/Source/CParse/templ.c @@ -249,7 +249,7 @@ String *partial_arg(String *s, String *p) { } prefix = NewStringWithSize(cp, (int)(c - cp)); newarg = Copy(s); - Replace(newarg, prefix, "", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); + Replace(newarg, prefix, "", DOH_REPLACE_FIRST); Delete(prefix); return newarg; } diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 1476ddba5..ca5ec8c3c 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -477,7 +477,7 @@ static void getoptions(int argc, char *argv[]) { Swig_mark_arg(i); } else if (strncmp(argv[i], "-D", 2) == 0) { String *d = NewString(argv[i] + 2); - Replace(d, "=", " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); + Replace(d, "=", " ", DOH_REPLACE_FIRST); Preprocessor_define((DOH *) d, 0); Delete(d); // Create a symbol diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index caa9725c0..a36912ab7 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -407,7 +407,7 @@ public: printf("Fatal error. SwigType_del_pointer applied to non-pointer.\n"); abort(); } - Replace(t, "r.", "", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); + Replace(t, "r.", "", DOH_REPLACE_FIRST); } void oc_SwigType_del_array(SwigType *t) {