Skip to content

Instantly share code, notes, and snippets.

@fancellu
Last active December 23, 2015 07:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fancellu/6601111 to your computer and use it in GitHub Desktop.
Save fancellu/6601111 to your computer and use it in GitHub Desktop.
Quick app to postprocess source files. Created because Scalaxb was converting '-' to u45 in class names.
package com.felstar.playpen.scalaxb
import java.io.File
object PostProcessScalaxb {
def allFiles(path:File):List[File]= {
val (dirs,files)=path.listFiles.toList.partition(_.isDirectory)
files ::: dirs.flatMap(allFiles)
}
def writeToFile(file: File, s: String) {
val pw = new java.io.PrintWriter(file)
try {
pw.write(s)
} finally {
pw.close()
}
}
def main(args: Array[String]): Unit = {
val src=new File(".","target/generated-sources")
val getChar="""u45(.)""".r
for (f<-allFiles(src).filter(_.getName().endsWith(".scala"))) {
println(f)
val fileLines = io.Source.fromFile(f).getLines.toList
.map(line=>getChar.replaceAllIn(line, _.group(1).toUpperCase))
writeToFile(f,fileLines.mkString("\n"))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment