Add support for case conversion characters in regex substitutions.
Allow using Perl-like \l, \L, \u, \U and \E escape sequences in the
substitution string used with %rename("%(regex:/pattern/subst/)s").
This is useful for e.g. title casing all string after removing some prefix.
Closes #82
This commit is contained in:
parent
669a27bb7b
commit
72afb74f47
7 changed files with 108 additions and 21 deletions
|
|
@ -4,9 +4,12 @@ using rename_pcre_encoderNamespace;
|
|||
public class runme {
|
||||
static void Main() {
|
||||
SomeWidget w = new SomeWidget();
|
||||
w.putBorderWidth(17);
|
||||
if ( w.getBorderWidth() != 17 )
|
||||
w.put_borderWidth(17);
|
||||
if ( w.get_borderWidth() != 17 )
|
||||
throw new Exception(String.Format("Border with should be 17, not {0}",
|
||||
w.getBorderWidth()));
|
||||
w.get_borderWidth()));
|
||||
|
||||
if ( rename_pcre_encoder.StartINSAneAndUNSAvoryTraNSAtlanticRaNSAck() != 42 )
|
||||
throw new Exception("Unexpected result of renamed function call");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ public class rename_pcre_encoder_runme {
|
|||
public static void main(String argv[])
|
||||
{
|
||||
SomeWidget w = new SomeWidget();
|
||||
w.putBorderWidth(17);
|
||||
if ( w.getBorderWidth() != 17 )
|
||||
w.put_borderWidth(17);
|
||||
if ( w.get_borderWidth() != 17 )
|
||||
throw new RuntimeException(String.format("Border with should be 17, not %d",
|
||||
w.getBorderWidth()));
|
||||
w.get_borderWidth()));
|
||||
if ( rename_pcre_encoder.StartINSAneAndUNSAvoryTraNSAtlanticRaNSAck() != 42 )
|
||||
throw new RuntimeException("Unexpected result of renamed function call");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
from rename_pcre_encoder import *
|
||||
|
||||
s = SomeWidget()
|
||||
s.putBorderWidth(3)
|
||||
if s.getBorderWidth() != 3:
|
||||
raise RuntimeError("Border should be 3, not %d" % (s.getBorderWidth(),))
|
||||
s.put_borderWidth(3)
|
||||
if s.get_borderWidth() != 3:
|
||||
raise RuntimeError("Border should be 3, not %d" % (s.get_borderWidth(),))
|
||||
|
||||
s.putSize(4, 5)
|
||||
s.put_size(4, 5)
|
||||
a = AnotherWidget()
|
||||
a.DoSomething()
|
||||
|
||||
evt = wxEVTSomeEvent()
|
||||
t = xUnchangedName()
|
||||
|
||||
if StartINSAneAndUNSAvoryTraNSAtlanticRaNSAck() != 42:
|
||||
raise RuntimeError("Unexpected result of renamed function call")
|
||||
|
|
|
|||
|
|
@ -3,9 +3,14 @@
|
|||
// strip the wx prefix from all identifiers except those starting with wxEVT
|
||||
%rename("%(regex:/wx(?!EVT)(.*)/\\1/)s") "";
|
||||
|
||||
// Replace "Set" and "Get" prefixes with "put" and "get" respectively.
|
||||
%rename("%(regex:/^Set(.*)/put\\1/)s", %$isfunction) "";
|
||||
%rename("%(regex:/^Get(.*)/get\\1/)s", %$isfunction) "";
|
||||
// Change "{Set,Get}Foo" naming convention to "{put,get}_foo" one.
|
||||
%rename("%(regex:/^Set(.*)/put_\\l\\1/)s", %$isfunction) "";
|
||||
%rename("%(regex:/^Get(.*)/get_\\l\\1/)s", %$isfunction) "";
|
||||
|
||||
// Make some words stand out (unfortunately we don't have "global" flag): we
|
||||
// use \U to capitalize the second capture group and then \E to preserve the
|
||||
// case of the rest.
|
||||
%rename("%(regex:/(.*?)(nsa)(.*?)\\2(.*?)\\2(.*?)\\2(.*)/\\1\\U\\2\\E\\3\\U\\2\\E\\4\\U\\2\\E\\5\\U\\2\\E\\6/)s") "";
|
||||
|
||||
%inline %{
|
||||
|
||||
|
|
@ -28,4 +33,6 @@ class wxEVTSomeEvent {
|
|||
class xUnchangedName {
|
||||
};
|
||||
|
||||
inline int StartInsaneAndUnsavoryTransatlanticRansack() { return 42; }
|
||||
|
||||
%}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue