Skip to content

Commit

Permalink
fix escape
Browse files Browse the repository at this point in the history
  • Loading branch information
edadma committed Jun 19, 2018
1 parent a148168 commit eebde1f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/Command.scala
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ object Command {
) map (c => c.name -> c) toMap

def escape( s: String ) =
escapeRegex.replaceAllIn( s, { m => s"&${Entity( m group 1 head )};" } )
escapeRegex.replaceSomeIn( s, { m => Entity( m group 1 head ) map (e => s"&$e;") } )

def escapeFull( s: String ) =
escapeRegex.replaceAllIn( s, { m => s"&${Entity.full( m group 1 head )};" } )
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/Entity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ object Entity {

def apply( c: Char ) =
c match {
case '&' => "amp"
case '<' => "lt"
case '>' => "gt"
case _ if c > '\u007F' => s"#${c.toInt}"
case _ => c.toString
case '&' => Some( "amp" )
case '<' => Some( "lt" )
case '>' => Some( "gt" )
case _ if c > '\u007F' => Some( s"#${c.toInt}" )
case _ => None
}

def full( c: Char ) =
Expand Down
4 changes: 1 addition & 3 deletions src/test/scala/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ object Main extends App {
)
val input =
"""
|\def m a b {asdf \a\ zxvc \b}
|\set v 123
|\m qwer\v
|\escape "a < b &&\n b < c"
""".trim.stripMargin
val assigns =
Map(
Expand Down

0 comments on commit eebde1f

Please sign in to comment.