root/gaphor/tags/gaphor-0.12.1/utils/format.py

Revision 1274, 408 bytes (checked in by arj..@yirdis.nl, 2 years ago)

Added preliminary code

Line 
1
2 import re
3
4 pattern = r'([A-Z])'
5 sub = r'_\1'
6
7 def camelCase_to_underscore(str):
8     """
9     >>> camelCase_to_underscore('camelcase')
10     'camelcase'
11     >>> camelCase_to_underscore('camelCase')
12     'camel_case'
13     >>> camelCase_to_underscore('camelCamelCase')
14     'camel_camel_case'
15     """
16     return re.sub(pattern, sub, str).lower()
17
18
19 if __name__ == '__main__':
20     import doctest
21     doctest.testmod()
Note: See TracBrowser for help on using the browser.