mirror of https://github.com/swig/swig
Add rstrip encoder for use in %rename.
This is like the strip encoder but strips the symbol's suffix instead of the prefix.
This commit is contained in:
parent
3000824c94
commit
4a3e1fd44c
|
@ -5,6 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release.
|
|||
Version 3.0.9 (in progress)
|
||||
===========================
|
||||
|
||||
2016-03-01: wsfulton
|
||||
Add rstrip encoder for use in %rename. This is like the strip encoder but
|
||||
strips the symbol's suffix instead of the prefix. The example below
|
||||
will rename SomeThingCls to SomeThing and AnotherThingCls to AnotherThing:
|
||||
|
||||
%rename("%(rstrip:[Cls])s") "";
|
||||
|
||||
class SomeThingCls {};
|
||||
struct AnotherThingCls {};
|
||||
|
||||
2016-02-07: kwwette
|
||||
[Octave] recognise various unary functions
|
||||
* Use __float__() for numeric conversions, e.g. when calling double()
|
||||
|
|
|
@ -1888,6 +1888,13 @@ and a more descriptive one, but the two functions are otherwise equivalent:
|
|||
literally, e.g. <tt>%rename("strip:[wx]")</tt></td>
|
||||
<td><tt>wxPrint</tt></td><td><tt>Print</tt></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><tt>rstrip:[suffix]</tt></td>
|
||||
<td>String without the given suffix or the original string if it doesn't
|
||||
end with this suffix. Note that square brackets should be used
|
||||
literally, e.g. <tt>%rename("rstrip:[Cls]")</tt></td>
|
||||
<td><tt>PrintCls</tt></td><td><tt>Print</tt></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><span style="white-space: nowrap;"><tt>regex:/pattern/subst/</tt></span></td>
|
||||
<td>String after (Perl-like) regex substitution operation. This function
|
||||
|
|
|
@ -344,6 +344,7 @@ CPP_TEST_CASES += \
|
|||
rename2 \
|
||||
rename3 \
|
||||
rename4 \
|
||||
rename_rstrip_encoder \
|
||||
rename_scope \
|
||||
rename_simple \
|
||||
rename_strip_encoder \
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
from rename_rstrip_encoder import *
|
||||
|
||||
s = SomeThing()
|
||||
a = AnotherThing()
|
||||
a.DoClsX()
|
|
@ -0,0 +1,15 @@
|
|||
%module rename_rstrip_encoder
|
||||
|
||||
// strip the Cls suffix from all identifiers
|
||||
%rename("%(rstrip:[Cls])s") "";
|
||||
|
||||
%inline %{
|
||||
|
||||
class SomeThingCls {
|
||||
};
|
||||
|
||||
struct AnotherThingCls {
|
||||
void DoClsXCls() {}
|
||||
};
|
||||
|
||||
%}
|
|
@ -1147,6 +1147,39 @@ String *Swig_string_strip(String *s) {
|
|||
return ns;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_string_rstrip()
|
||||
*
|
||||
* Strip given suffix from identifiers
|
||||
*
|
||||
* Printf(stderr,"%(rstrip:[Cls])s","HelloCls") -> Hello
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *Swig_string_rstrip(String *s) {
|
||||
String *ns;
|
||||
int len = Len(s);
|
||||
if (!len) {
|
||||
ns = NewString(s);
|
||||
} else {
|
||||
const char *cs = Char(s);
|
||||
const char *ce = Strchr(cs, ']');
|
||||
if (*cs != '[' || !ce) {
|
||||
ns = NewString(s);
|
||||
} else {
|
||||
String *fmt = NewStringf("%%.%ds", ce-cs-1);
|
||||
String *suffix = NewStringf(fmt, cs+1);
|
||||
int suffix_len = Len(suffix);
|
||||
if (0 == Strncmp(cs+len-suffix_len, suffix, suffix_len)) {
|
||||
int copy_len = len-suffix_len-(ce+1-cs);
|
||||
ns = NewStringWithSize(ce+1, copy_len);
|
||||
} else {
|
||||
ns = NewString(ce+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ns;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_offset_string()
|
||||
*
|
||||
|
@ -1403,6 +1436,7 @@ void Swig_init() {
|
|||
DohEncoding("command", Swig_string_command);
|
||||
DohEncoding("schemify", Swig_string_schemify);
|
||||
DohEncoding("strip", Swig_string_strip);
|
||||
DohEncoding("rstrip", Swig_string_rstrip);
|
||||
DohEncoding("regex", Swig_string_regex);
|
||||
|
||||
/* aliases for the case encoders */
|
||||
|
|
Loading…
Reference in New Issue