Add the strip encoder patch from Anatoly Techtonik #2130016
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10896 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
f2c11f74f9
commit
a604f46593
5 changed files with 69 additions and 0 deletions
|
|
@ -3,6 +3,20 @@
|
||||||
Version 1.3.37 (in progress)
|
Version 1.3.37 (in progress)
|
||||||
============================
|
============================
|
||||||
|
|
||||||
|
2008-11-01: wsfulton
|
||||||
|
Add the strip encoder patch from Anatoly Techtonik #2130016. This enables an
|
||||||
|
easy way to rename symbols by stripping a commonly used prefix in all the
|
||||||
|
function/struct names. It works in the same way as the other encoders, such as
|
||||||
|
title, lower, command etc outlined in CHANGES file dated 12/30/2005. Example
|
||||||
|
below will rename wxAnotherWidget to AnotherWidget and wxDoSomething to
|
||||||
|
DoSomething:
|
||||||
|
|
||||||
|
%rename("%(strip:[wx])s") "";
|
||||||
|
|
||||||
|
struct wxAnotherWidget {
|
||||||
|
void wxDoSomething();
|
||||||
|
};
|
||||||
|
|
||||||
2008-09-26: mutandiz
|
2008-09-26: mutandiz
|
||||||
[allegrocl]
|
[allegrocl]
|
||||||
Lots of test-suite work.
|
Lots of test-suite work.
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,7 @@ CPP_TEST_CASES += \
|
||||||
rename3 \
|
rename3 \
|
||||||
rename4 \
|
rename4 \
|
||||||
rename_scope \
|
rename_scope \
|
||||||
|
rename_strip_encoder \
|
||||||
restrict_cplusplus \
|
restrict_cplusplus \
|
||||||
return_const_value \
|
return_const_value \
|
||||||
return_value_scope \
|
return_value_scope \
|
||||||
|
|
|
||||||
6
Examples/test-suite/python/rename_strip_encoder_runme.py
Normal file
6
Examples/test-suite/python/rename_strip_encoder_runme.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
from rename_strip_encoder import *
|
||||||
|
|
||||||
|
s = SomeWidget()
|
||||||
|
a = AnotherWidget()
|
||||||
|
a.DoSomething()
|
||||||
|
|
||||||
16
Examples/test-suite/rename_strip_encoder.i
Normal file
16
Examples/test-suite/rename_strip_encoder.i
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
%module rename_strip_encoder
|
||||||
|
|
||||||
|
// strip the wx prefix from all identifiers
|
||||||
|
%rename("%(strip:[wx])s") "";
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
class wxSomeWidget {
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wxAnotherWidget {
|
||||||
|
void wxDoSomething() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
@ -926,6 +926,37 @@ String *Swig_string_command(String *s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* Swig_string_strip()
|
||||||
|
*
|
||||||
|
* Strip given prefix from identifiers
|
||||||
|
*
|
||||||
|
* Printf(stderr,"%(strip:[wx])s","wxHello") -> Hello
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
String *Swig_string_strip(String *s) {
|
||||||
|
String *ns;
|
||||||
|
if (!Len(s)) {
|
||||||
|
ns = NewString(s);
|
||||||
|
} else {
|
||||||
|
const char *cs = Char(s);
|
||||||
|
const char *ce = Strchr(cs, ']');
|
||||||
|
if (*cs != '[' || ce == NULL) {
|
||||||
|
ns = NewString(s);
|
||||||
|
} else {
|
||||||
|
String *fmt = NewStringf("%%.%ds", ce-cs-1);
|
||||||
|
String *prefix = NewStringf(fmt, cs+1);
|
||||||
|
if (0 == Strncmp(ce+1, prefix, Len(prefix))) {
|
||||||
|
ns = NewString(ce+1+Len(prefix));
|
||||||
|
} else {
|
||||||
|
ns = NewString(ce+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ns;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Swig_string_rxspencer()
|
* Swig_string_rxspencer()
|
||||||
*
|
*
|
||||||
|
|
@ -1053,6 +1084,7 @@ void Swig_init() {
|
||||||
DohEncoding("command", Swig_string_command);
|
DohEncoding("command", Swig_string_command);
|
||||||
DohEncoding("rxspencer", Swig_string_rxspencer);
|
DohEncoding("rxspencer", Swig_string_rxspencer);
|
||||||
DohEncoding("schemify", Swig_string_schemify);
|
DohEncoding("schemify", Swig_string_schemify);
|
||||||
|
DohEncoding("strip", Swig_string_strip);
|
||||||
|
|
||||||
/* aliases for the case encoders */
|
/* aliases for the case encoders */
|
||||||
DohEncoding("uppercase", Swig_string_upper);
|
DohEncoding("uppercase", Swig_string_upper);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue