diff --git a/CHANGES.current b/CHANGES.current index 333c5f871..89e817415 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,12 @@ 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 + #948 #1019 #1273 Fix for C++11 raw strings where the delimiters were mistakenly left + in the string contents in situations where the string was copied into generated code. + For example, %constant, the "docstring" feature and for C#/Java/D constants turned on + with %javaconst/%csconst/%dmanifestconst. + 2019-01-05: wsfulton [Ruby] #538. Fix Ruby support for %feature("docstring"). diff --git a/Examples/test-suite/cpp11_raw_string_literals.i b/Examples/test-suite/cpp11_raw_string_literals.i index 1dea90e0c..195d0551f 100644 --- a/Examples/test-suite/cpp11_raw_string_literals.i +++ b/Examples/test-suite/cpp11_raw_string_literals.i @@ -59,3 +59,43 @@ const char16_t *hh = uR"XXX(I'm a "raw UTF-16" \ string.)XXX"; const char32_t *ii = UR"XXX(I'm a "raw UTF-32" \ string.)XXX"; %} +// Constants +#if defined(SWIGJAVA) +%javaconst(1); +#elif SWIGCSHARP +%csconst(1); +#elif SWIGD +%dmanifestconst; +#endif + +%inline %{ +#define jj ")I'm an \"ascii\" \\ string constant." +#define kk R"XXX()I'm an "ascii" \ string constant.)XXX"; +%} + +%constant mm = R"XXX()I'm an "ascii" \ string constant with multiple + +lines.)XXX"; + +// docstring feature +%feature("docstring") RawStringDoc::WW "Single line documentation comment" +%feature("docstring") RawStringDoc::XX %{ +Multi-line +documentation +comment +%} +%feature("docstring") RawStringDoc::YY R"RRR(Single line "raw string" documentation comment)RRR" +%feature("docstring") RawStringDoc::ZZ R"FOO(Documentation comment + +as a "raw string" +on multiple lines including a \ backslash)FOO" + +%inline %{ +struct RawStringDoc { + void WW() {} + void XX() {} + void YY() {} + void ZZ() {} +}; +%} + diff --git a/Examples/test-suite/java/cpp11_raw_string_literals_runme.java b/Examples/test-suite/java/cpp11_raw_string_literals_runme.java new file mode 100644 index 000000000..396c0ba06 --- /dev/null +++ b/Examples/test-suite/java/cpp11_raw_string_literals_runme.java @@ -0,0 +1,67 @@ +import cpp11_raw_string_literals.*; + +public class cpp11_raw_string_literals_runme { + + static { + try { + System.loadLibrary("cpp11_raw_string_literals"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + if (cpp11_raw_string_literals.getL() != 100) + throw new RuntimeException("failed!"); + + if (cpp11_raw_string_literals.getU8() != 100) + throw new RuntimeException("failed!"); + + if (cpp11_raw_string_literals.getU() != 100) + throw new RuntimeException("failed!"); + + if (UStruct.U != 100) + throw new RuntimeException("failed!"); + + + if (cpp11_raw_string_literals.getR() != 100) + throw new RuntimeException("failed!"); + + if (cpp11_raw_string_literals.getLR() != 100) + throw new RuntimeException("failed!"); + + if (cpp11_raw_string_literals.getU8R() != 100) + throw new RuntimeException("failed!"); + + if (cpp11_raw_string_literals.getUR() != 100) + throw new RuntimeException("failed!"); + + if (URStruct.UR != 100) + throw new RuntimeException("failed!"); + + + if (!cpp11_raw_string_literals.getAa().equals("Wide string")) + throw new RuntimeException("failed!"); + + if (!cpp11_raw_string_literals.getBb().equals("UTF-8 string")) + throw new RuntimeException("failed!"); + + if (!cpp11_raw_string_literals.getXx().equals(")I'm an \"ascii\" \\ string.")) + throw new RuntimeException("failed!"); + + if (!cpp11_raw_string_literals.getEe().equals(")I'm an \"ascii\" \\ string.")) + throw new RuntimeException("failed!"); + + if (!cpp11_raw_string_literals.getFf().equals("I'm a \"raw wide\" \\ string.")) + throw new RuntimeException("failed!"); + + if (!cpp11_raw_string_literals.getGg().equals("I'm a \"raw UTF-8\" \\ string.")) + throw new RuntimeException("failed!"); + + + + if (!cpp11_raw_string_literalsConstants.mm.equals(")I'm an \"ascii\" \\ string constant with multiple\n\nlines.")) + throw new RuntimeException("failed!"); + } +} diff --git a/Examples/test-suite/python/cpp11_raw_string_literals_runme.py b/Examples/test-suite/python/cpp11_raw_string_literals_runme.py index 29e53c6a7..6a587b860 100644 --- a/Examples/test-suite/python/cpp11_raw_string_literals_runme.py +++ b/Examples/test-suite/python/cpp11_raw_string_literals_runme.py @@ -1,4 +1,5 @@ from cpp11_raw_string_literals import * +import inspect if cvar.L != 100: raise RuntimeError @@ -46,3 +47,29 @@ if cvar.ff != "I'm a \"raw wide\" \\ string.": if cvar.gg != "I'm a \"raw UTF-8\" \\ string.": raise RuntimeError, cvar.gg + + +def check(got, expected): + expected_list = expected.split("\n") + got_list = got.split("\n") + + if expected_list != got_list: + raise RuntimeError("\n" + "Expected: " + str(expected_list) + "\n" + "Got : " + str(got_list)) + +# When getting docstrings, use inspect.getdoc(x) instead of x.__doc__ otherwise the different options +# such as -O and -builtin may produce different initial indentation. +check(inspect.getdoc(RawStringDoc.WW), "Single line documentation comment") +check(inspect.getdoc(RawStringDoc.XX), +"""Multi-line +documentation +comment""") +check(inspect.getdoc(RawStringDoc.YY), """Single line "raw string" documentation comment""") +check(inspect.getdoc(RawStringDoc.ZZ), +"""Documentation comment + +as a "raw string" +on multiple lines including a \ backslash""") + +check(mm, """)I'm an "ascii" \ string constant with multiple + +lines.""")