How do I chain multiple rename functions in SWIG?

Viewed 594

I have a number of classes that I'd like to rename in SWIG. Most of my classes look like this some_class, which I'd like to rename to SomeClass. This is easy:

%replace("%(camelcase)s", %$isclass) "";

However, I also have class names that end in "_t" which I'd like to strip, so my_class_t would become just MyClass. I can do just this operation with:

%rename("%(regex:/^(.*)(_t?)$/\\1/)s", %$isclass) "";

Is there a rename rule that will let me apply both of these actions?

1 Answers

I'm not sure if you can chain multiple renames, but you can send the found string to an external process and do whatever you want there.

Advanced renaming support

command:cmd

Output of an external command cmd with the string passed to it as input. Notice that this function is extremely slow compared to all the other ones as it involves spawning a separate process and using it for many declarations is not recommended. The cmd is not enclosed in square brackets but must be terminated with a triple '<' sign, e.g. %rename("command:tr -d aeiou <<<") (nonsensical example removing all vowels)

Related