Skip to content

Commit 96d3328

Browse files
committed
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 swig#538
1 parent a4e48b1 commit 96d3328

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

CHANGES.current

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
77
Version 4.0.0 (in progress)
88
===========================
99

10+
2019-01-05: wsfulton
11+
[Ruby] #538. Fix Ruby support for %feature("docstring").
12+
1013
2019-01-03: wsfulton
1114
#1202 Fix overloading of non-pointer class types in scripting languages when overloaded
1215
with a pointer and a NULL scripting language equivalent is used, eg None in Python.

Source/Modules/ruby.cxx

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -255,32 +255,22 @@ class RUBY:public Language {
255255
autodoc = make_autodoc(n, ad_type);
256256
have_auto = (autodoc && Len(autodoc) > 0);
257257
}
258-
// If there is more than one line then make docstrings like this:
259-
//
260-
// This is line1
261-
// And here is line2 followed by the rest of them
262-
//
263-
// otherwise, put it all on a single line
264-
//
258+
259+
if (have_auto || have_ds)
260+
doc = NewString("/*");
261+
265262
if (have_auto && have_ds) { // Both autodoc and docstring are present
266-
doc = NewString("");
267-
Printv(doc, "\n", autodoc, "\n", str, NIL);
263+
Printv(doc, "\n", autodoc, "\n", str, "\n", NIL);
268264
} else if (!have_auto && have_ds) { // only docstring
269-
if (Strchr(str, '\n') == 0) {
270-
doc = NewString(str);
271-
} else {
272-
doc = NewString("");
273-
Printv(doc, str, NIL);
274-
}
265+
Printv(doc, str, NIL);
275266
} else if (have_auto && !have_ds) { // only autodoc
276-
if (Strchr(autodoc, '\n') == 0) {
277-
doc = NewStringf("%s", autodoc);
278-
} else {
279-
doc = NewString("");
280-
Printv(doc, "\n", autodoc, NIL);
281-
}
282-
} else
267+
Printv(doc, "\n", autodoc, "\n", NIL);
268+
} else {
283269
doc = NewString("");
270+
}
271+
272+
if (have_auto || have_ds)
273+
Append(doc, "*/\n");
284274

285275
// Save the generated strings in the parse tree in case they are used later
286276
// by post processing tools
@@ -520,7 +510,7 @@ class RUBY:public Language {
520510
last_mode = ad_type;
521511
last_autodoc = Copy(methodName);
522512

523-
String *doc = NewString("/*\n");
513+
String *doc = NewString("");
524514
int counter = 0;
525515
bool skipAuto = false;
526516
Node* on = n;
@@ -760,7 +750,6 @@ class RUBY:public Language {
760750
n = Getattr(n, "sym:nextSibling");
761751
}
762752

763-
Append(doc, "\n*/\n");
764753
Delete(full_name);
765754
Delete(class_name);
766755
Delete(super_names);

0 commit comments

Comments
 (0)