submit the following for Gnu m4 documentation

Jack Woehr <[email protected]>
Newsgroups gmane.comp.gnu.m4.general
Message-ID <[email protected]>
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 <http://pigiron.sourceforge.net>
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')
    =>ABC
    javaize_lc(`a_b_c')
    =>aBC
    javaize(`imported_type_name_from_the_API')
    =>ImportedTypeNameFromTheAPI
    javaize_lc(`imported_member_name')
    =>importedMemberName

-- 
Jack J. Woehr            # "Self-delusion is
http://www.well.com/~jax #  half the battle!"
http://www.softwoehr.com #  - Zippy the Pinhead

_______________________________________________
m4-discuss mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/m4-discuss
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.