|
From: | Jack Woehr |
Subject: | submit the following for Gnu m4 documentation |
Date: | Sat, 30 Aug 2008 12:41:52 -0600 |
User-agent: | Thunderbird 1.5.0.5 (X11/20060925) |
I'd like to submit the following for Gnu m4 documentation since it uses
regexp(), ifelse(), and substr() recursively in an instructive fashion. This came up in the PigIron Project in autogenerating Java source code from strings cut-and-pasted from API documentation. --- The following example converts a string representing a programming construct such as a function from another programming language's conventional member_name class_name etc. representation and makes it Java-conventional, e.g., ClassName or memberName. Recursion handles the "how many underscore-separated components?" problem. # Uppercase a character define(`upcase', `translit(`$*', `a-z', `A-Z')') # lowercase a character define(`lowcase', `translit(`$*', `A-Z', `a-z')') # upcase first char define(`upcase_initial',`upcase(substr(`$1',0,1))`'substr(`$1',1)') # lowcase first char define(`lowcase_initial',`lowcase(substr(`$1',0,1))`'substr(`$1',1)') # Convert an xcc_xcc.. (etc.) to XccXcc... define(`javaize_regexp',`^\(\w*\)_\(.*\)') define(`javaize',`ifelse(regexp(`$1', javaize_regexp), `-1', upcase_initial(`$1'), `regexp($1, javaize_regexp, `javaize(`\1')`'upcase_initial(`\2')')')') # Convert an xcc_xcc.. (etc.) to xccXcc... define(`javaize_lc',`lowcase_initial(javaize(`$1'))') javaize(`a_b_c') -- Jack J. Woehr # "Self-delusion is http://www.well.com/~jax # half the battle!" http://www.softwoehr.com # - Zippy the Pinhead |
[Prev in Thread] | Current Thread | [Next in Thread] |