From 96d33287b4ef2183a2a786513598752b2e355b97 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 5 Jan 2019 19:21:04 +0000 Subject: [PATCH] Fix Ruby docstring feature. The docstring was not encapsulated within /* */ comments. The implementation had code for autodoc strings being either single or multi-line and then adding extra newlines. However, in practice only multi-line autodoc string are ever generated, so this bit of code handling was removed. The docstring feature does not attempt to add newlines depending on the existence of newlines in the docstring. Closes #538 --- CHANGES.current | 3 +++ Source/Modules/ruby.cxx | 37 +++++++++++++------------------------ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index c5347143c..333c5f871 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.0.0 (in progress) =========================== +2019-01-05: wsfulton + [Ruby] #538. Fix Ruby support for %feature("docstring"). + 2019-01-03: wsfulton #1202 Fix overloading of non-pointer class types in scripting languages when overloaded with a pointer and a NULL scripting language equivalent is used, eg None in Python. diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 306570d96..08ba4e2b3 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -255,32 +255,22 @@ private: autodoc = make_autodoc(n, ad_type); have_auto = (autodoc && Len(autodoc) > 0); } - // If there is more than one line then make docstrings like this: - // - // This is line1 - // And here is line2 followed by the rest of them - // - // otherwise, put it all on a single line - // + + if (have_auto || have_ds) + doc = NewString("/*"); + if (have_auto && have_ds) { // Both autodoc and docstring are present - doc = NewString(""); - Printv(doc, "\n", autodoc, "\n", str, NIL); + Printv(doc, "\n", autodoc, "\n", str, "\n", NIL); } else if (!have_auto && have_ds) { // only docstring - if (Strchr(str, '\n') == 0) { - doc = NewString(str); - } else { - doc = NewString(""); - Printv(doc, str, NIL); - } + Printv(doc, str, NIL); } else if (have_auto && !have_ds) { // only autodoc - if (Strchr(autodoc, '\n') == 0) { - doc = NewStringf("%s", autodoc); - } else { - doc = NewString(""); - Printv(doc, "\n", autodoc, NIL); - } - } else + Printv(doc, "\n", autodoc, "\n", NIL); + } else { doc = NewString(""); + } + + if (have_auto || have_ds) + Append(doc, "*/\n"); // Save the generated strings in the parse tree in case they are used later // by post processing tools @@ -520,7 +510,7 @@ private: last_mode = ad_type; last_autodoc = Copy(methodName); - String *doc = NewString("/*\n"); + String *doc = NewString(""); int counter = 0; bool skipAuto = false; Node* on = n; @@ -760,7 +750,6 @@ private: n = Getattr(n, "sym:nextSibling"); } - Append(doc, "\n*/\n"); Delete(full_name); Delete(class_name); Delete(super_names);