Created
September 20, 2016 18:05
-
-
Save jdbrice/2f12cd9bd7cb6789e1362767fa82f132 to your computer and use it in GitHub Desktop.
Python script for sanitizing Clang / ClDoc documentation XML output. Great for improving the readability of ClDoc documentation webpages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# for command line args | |
import sys | |
# for regex | |
import re | |
#for JSON parsing | |
import json | |
# for dir searching | |
import glob | |
import xml.etree.ElementTree as ET | |
ET.register_namespace('', "http://jessevdk.github.com/cldoc/1.0") | |
stdns = "" | |
if len( sys.argv ) < 2 : | |
print "Usage:" | |
print "sanitize_std path/to/xml/" | |
exit() | |
files = glob.glob( sys.argv[1] + "*.xml" ) | |
def sanitize_file( filename ): | |
e = ET.parse( filename ) | |
rn = e.getroot() | |
for t in rn.findall( ".//{http://jessevdk.github.com/cldoc/1.0}type" ) : | |
rawType = t.get( "name" ) | |
fType = re.sub( r'std::__1::', stdns, rawType, 1000 ); | |
fType = re.sub( r'basic_string<char>', "string", fType, 1000 ); | |
fType = re.sub( r'\n', "", fType, 1000 ); | |
mIndex = fType.find( "map" ) | |
vIndex = fType.find( "vector" ) | |
if mIndex <= 5 and mIndex >= 0: | |
pl1 = fType.find( "," ) | |
pl2 = fType.find( ",", pl1+1 ) | |
fType = fType[ :pl2 ] + ">" | |
if vIndex <= 5 and vIndex >= 0: | |
pl1 = fType.find( "," ) | |
fType = fType[ :pl1 ] + ">" | |
t.set( 'name', fType ) | |
e.write( filename ) | |
for f in files : | |
print "Sanitizing ", f | |
sanitize_file( f ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment