From ec1ab4fe8b25fdc6462dcf07727233b80563285a Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Fri, 17 Mar 2017 03:36:49 -0400 Subject: Add string quoting helpers --- stage1/cbt.scala | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'stage1') diff --git a/stage1/cbt.scala b/stage1/cbt.scala index cb6cb10..5f8f2b5 100644 --- a/stage1/cbt.scala +++ b/stage1/cbt.scala @@ -20,6 +20,10 @@ object `package`{ private val lib = new BaseLib + implicit class CbtStringExtensions(string: String){ + def escape = string.replace("\\","\\\\").replace("\"","\\\"") + def quote = s""""$escape"""" + } implicit class PathExtensionMethods( path: Path ){ def /(s: String): Path = path.resolve(s) def ++( s: String ): Path = { @@ -64,6 +68,7 @@ object `package`{ def lastModifiedRecursive = listRecursive.map(_.lastModified).max def readAsString = new String( readAllBytes( file.toPath ) ) + def quote = s"new _root_.java.io.File(${string.quote})" } implicit class URLExtensionMethods( url: URL ){ def ++( s: String ): URL = new URL( url.toString ++ s ) -- cgit v1.2.3