Raw string literal changes in paper N3077 changes delimiters to use round brackets instead of square brackets

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12152 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-06-25 22:54:45 +00:00
commit adffcd60e1
4 changed files with 83 additions and 39 deletions

View file

@ -460,23 +460,22 @@ arguments defined in the original template&lt;&gt; block:</p>
<H3><a name="Cpp0x_New_string_literals"></a>7.2.18 New string literals</H3> <H3><a name="Cpp0x_New_string_literals"></a>7.2.18 New string literals</H3>
<p>SWIG fully supports custom delimiters and unicode string <p>SWIG fully supports unicode string constants and raw string literals.</p>
constants.</p>
<div class="code"><PRE> <div class="code"><PRE>
// New string literals // New string literals
char *a = "ABC"; wstring aa = L"Wide string";
wstring wide = L"ABC"; const char *bb = u8"UTF-8 string";
char *b = u8"ABC"; const char16_t *cc = u"UTF-16 string";
char16_t *c = u"ABC"; const char32_t *dd = U"UTF-32 string";
char32_t *d = U"ABC";
// Custom String delimiter // Raw string literals
char *e = R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; const char *xx = ")I'm an \"ascii\" \\ string.";
wstring wide2 = LR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; const char *ee = R"XXX()I'm an "ascii" \ string.)XXX"; // same as xx
char *f = u8R"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; wstring ff = LR"XXX(I'm a "raw wide" \ string.)XXX";
char16_t *g = uR"XXX[to be or "not" to be [these are parenthesis], this is the question!]XXX"; const char *gg = u8R"XXX(I'm a "raw UTF-8" \ string.)XXX";
char32_t *h = UR"XXX[to be or "not" to be [these are parenthesis], this is the question!]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> </PRE></div>
<p>Note: SWIG currently incorrectly parses the odd number of double quotes <p>Note: SWIG currently incorrectly parses the odd number of double quotes

View file

@ -8,14 +8,16 @@
This module also tests whether Swig correctly parses custom string delimiters. This module also tests whether Swig correctly parses custom string delimiters.
*/ */
%module cpp0x_raw_string_literals %module cpp0x_raw_string_literals
%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) aa;
%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) bb; %warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) bb;
%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) ee; %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) cc;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) dd; %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) dd;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) gg;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) hh; %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) hh;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ii;
%include <std_wstring.i>
%inline %{ %inline %{
#include <iostream> #include <iostream>
@ -38,27 +40,20 @@ struct URStruct {
static const int UR = 100; static const int UR = 100;
}; };
const char *aa = "ABC"; // New string literals
wstring wide = L"ABC"; wstring aa = L"Wide string";
const char *bb = u8"ABC"; const char *bb = u8"UTF-8 string";
const char16_t *cc = u"ABC"; const char16_t *cc = u"UTF-16 string";
const char32_t *dd = U"ABC"; const char32_t *dd = U"UTF-32 string";
%} %}
/* Raw string literals */ /* Raw string literals */
%inline %{
#warning TODO: change SWIG support from old R"[ ... ]" to new R"( ... )" const char *xx = ")I'm an \"ascii\" \\ string.";
const char *ee = R"XXX()I'm an "ascii" \ string.)XXX";
const char *ee = R"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; wstring ff = LR"XXX(I'm a "raw wide" \ string.)XXX";
wstring wide2 = LR"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; const char *gg = u8R"XXX(I'm a "raw UTF-8" \ string.)XXX";
const char *ff = u8R"XXX[to be or "not" to be [square parenthesis] (round parenthesis), that is the question!]XXX"; const char16_t *hh = uR"XXX(I'm a "raw UTF-16" \ string.)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 *ii = UR"XXX(I'm a "raw UTF-32" \ string.)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";
%} %}

View file

@ -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

View file

@ -673,7 +673,7 @@ static int look(Scanner * s) {
Swig_error(cparse_file, cparse_start_line, "Unterminated string\n"); Swig_error(cparse_file, cparse_start_line, "Unterminated string\n");
return SWIG_TOKEN_ERROR; return SWIG_TOKEN_ERROR;
} }
else if (c == '[') { else if (c == '(') {
state = 20; state = 20;
} }
else { else {
@ -698,8 +698,8 @@ static int look(Scanner * s) {
Delitem(s->text, DOH_END); Delitem(s->text, DOH_END);
get_escape(s); get_escape(s);
} }
} else { /* Custom delimiter string: R"XXXX[value]XXXX" */ } else { /* Custom delimiter string: R"XXXX(value)XXXX" */
if (c==']') { if (c==')') {
int i=0; int i=0;
String *end_delimiter = NewStringEmpty(); String *end_delimiter = NewStringEmpty();
while ((c = nextchar(s)) != 0 && c!='\"') { while ((c = nextchar(s)) != 0 && c!='\"') {
@ -710,7 +710,7 @@ static int look(Scanner * s) {
} }
if (Strcmp( str_delimiter, end_delimiter )==0) { 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 ); Delete( str_delimiter );
str_delimiter = 0; str_delimiter = 0;
return SWIG_TOKEN_STRING; return SWIG_TOKEN_STRING;