From: <wsf...@us...> - 2010-06-25 22:54:51
|
Revision: 12152 http://swig.svn.sourceforge.net/swig/?rev=12152&view=rev Author: wsfulton Date: 2010-06-25 22:54:45 +0000 (Fri, 25 Jun 2010) Log Message: ----------- Raw string literal changes in paper N3077 changes delimiters to use round brackets instead of square brackets Modified Paths: -------------- branches/gsoc2009-matevz/Doc/Manual/Cpp0x.html branches/gsoc2009-matevz/Examples/test-suite/cpp0x_raw_string_literals.i branches/gsoc2009-matevz/Source/Swig/scanner.c Added Paths: ----------- branches/gsoc2009-matevz/Examples/test-suite/python/cpp0x_raw_string_literals_runme.py Modified: branches/gsoc2009-matevz/Doc/Manual/Cpp0x.html =================================================================== --- branches/gsoc2009-matevz/Doc/Manual/Cpp0x.html 2010-06-25 21:48:07 UTC (rev 12151) +++ branches/gsoc2009-matevz/Doc/Manual/Cpp0x.html 2010-06-25 22:54:45 UTC (rev 12152) @@ -460,23 +460,22 @@ <H3><a name="Cpp0x_New_string_literals"></a>7.2.18 New string literals</H3> -<p>SWIG fully supports custom delimiters and unicode string -constants.</p> +<p>SWIG fully supports unicode string constants and raw string literals.</p> <div class="code"><PRE> // New string literals -char *a = "ABC"; -wstring wide = L"ABC"; -char *b = u8"ABC"; -char16_t *c = u"ABC"; -char32_t *d = U"ABC"; +wstring aa = L"Wide string"; +const char *bb = u8"UTF-8 string"; +const char16_t *cc = u"UTF-16 string"; +const char32_t *dd = U"UTF-32 string"; -// Custom String delimiter -char *e = R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -wstring wide2 = LR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -char *f = u8R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -char16_t *g = uR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; -char32_t *h = UR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; +// Raw string literals +const char *xx = ")I'm an \"ascii\" \\ string."; +const char *ee = R"XXX()I'm an "ascii" \ string.)XXX"; // same as xx +wstring ff = LR"XXX(I'm a "raw wide" \ string.)XXX"; +const char *gg = u8R"XXX(I'm a "raw UTF-8" \ string.)XXX"; +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"; </PRE></div> <p>Note: SWIG currently incorrectly parses the odd number of double quotes Modified: branches/gsoc2009-matevz/Examples/test-suite/cpp0x_raw_string_literals.i =================================================================== --- branches/gsoc2009-matevz/Examples/test-suite/cpp0x_raw_string_literals.i 2010-06-25 21:48:07 UTC (rev 12151) +++ branches/gsoc2009-matevz/Examples/test-suite/cpp0x_raw_string_literals.i 2010-06-25 22:54:45 UTC (rev 12152) @@ -8,15 +8,17 @@ This module also tests whether Swig correctly parses custom string delimiters. */ %module cpp0x_raw_string_literals -%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) aa; %warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) bb; %warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) ee; -%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) ff; +%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) gg; +%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) xx; %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc; %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) dd; -%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) gg; %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) hh; +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ii; +%include <std_wstring.i> + %inline %{ #include <iostream> #include <string> @@ -38,27 +40,20 @@ static const int UR = 100; }; -const char *aa = "ABC"; -wstring wide = L"ABC"; -const char *bb = u8"ABC"; -const char16_t *cc = u"ABC"; -const char32_t *dd = U"ABC"; +// New string literals +wstring aa = L"Wide string"; +const char *bb = u8"UTF-8 string"; +const char16_t *cc = u"UTF-16 string"; +const char32_t *dd = U"UTF-32 string"; %} /* Raw string literals */ - -#warning TODO: change SWIG support from old R"[ ... ]" to new R"( ... )" - -const char *ee = R"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; -wstring wide2 = LR"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; -const char *ff = u8R"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; -const char16_t *gg = uR"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; -const char32_t *hh = UR"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; -%{ -const char *ee = R"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; -wstring wide2 = LR"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; -const char *ff = u8R"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; -const char16_t *gg = uR"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; -const char32_t *hh = UR"XXX(to be or "not" to be [square parenthesis] (round parenthesis), that is the question!)XXX"; +%inline %{ +const char *xx = ")I'm an \"ascii\" \\ string."; +const char *ee = R"XXX()I'm an "ascii" \ string.)XXX"; +wstring ff = LR"XXX(I'm a "raw wide" \ string.)XXX"; +const char *gg = u8R"XXX(I'm a "raw UTF-8" \ string.)XXX"; +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"; %} Added: branches/gsoc2009-matevz/Examples/test-suite/python/cpp0x_raw_string_literals_runme.py =================================================================== --- branches/gsoc2009-matevz/Examples/test-suite/python/cpp0x_raw_string_literals_runme.py (rev 0) +++ branches/gsoc2009-matevz/Examples/test-suite/python/cpp0x_raw_string_literals_runme.py 2010-06-25 22:54:45 UTC (rev 12152) @@ -0,0 +1,50 @@ +from cpp0x_raw_string_literals import * + +if cvar.L != 100: + raise RuntimeError + +if cvar.u8 != 100: + raise RuntimeError + +if cvar.u != 100: + raise RuntimeError + +if UStruct.U != 100: + raise RuntimeError + + +if cvar.R != 100: + raise RuntimeError + +if cvar.LR != 100: + raise RuntimeError + +if cvar.u8R != 100: + raise RuntimeError + +if cvar.uR != 100: + raise RuntimeError + +if URStruct.UR != 100: + raise RuntimeError + + +if cvar.aa != "Wide string": + raise RuntimeError + +if cvar.bb != "UTF-8 string": + raise RuntimeError, cvar.wide + +if cvar.xx != ")I'm an \"ascii\" \\ string.": + raise RuntimeError, cvar.xx + +if cvar.ee != ")I'm an \"ascii\" \\ string.": + raise RuntimeError, cvar.ee + +if cvar.ff != "I'm a \"raw wide\" \\ string.": + raise RuntimeError, cvar.ff + +if cvar.gg != "I'm a \"raw UTF-8\" \\ string.": + raise RuntimeError, cvar.gg + + Modified: branches/gsoc2009-matevz/Source/Swig/scanner.c =================================================================== --- branches/gsoc2009-matevz/Source/Swig/scanner.c 2010-06-25 21:48:07 UTC (rev 12151) +++ branches/gsoc2009-matevz/Source/Swig/scanner.c 2010-06-25 22:54:45 UTC (rev 12152) @@ -673,7 +673,7 @@ Swig_error(cparse_file, cparse_start_line, "Unterminated string\n"); return SWIG_TOKEN_ERROR; } - else if (c == '[') { + else if (c == '(') { state = 20; } else { @@ -698,8 +698,8 @@ Delitem(s->text, DOH_END); get_escape(s); } - } else { /* Custom delimiter string: R"XXXX[value]XXXX" */ - if (c==']') { + } else { /* Custom delimiter string: R"XXXX(value)XXXX" */ + if (c==')') { int i=0; String *end_delimiter = NewStringEmpty(); while ((c = nextchar(s)) != 0 && c!='\"') { @@ -710,7 +710,7 @@ } if (Strcmp( str_delimiter, end_delimiter )==0) { - Delete( end_delimiter ); /* Correct end delimiter ]XXXX" occured */ + Delete( end_delimiter ); /* Correct end delimiter )XXXX" occured */ Delete( str_delimiter ); str_delimiter = 0; return SWIG_TOKEN_STRING; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |