File tree 1 file changed +14
-10
lines changed
1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -19,16 +19,20 @@ object Show {
19
19
//
20
20
// charEscapeSeq ::= ‘\‘ (‘b‘ | ‘t‘ | ‘n‘ | ‘f‘ | ‘r‘ | ‘"‘ | ‘'‘ | ‘\‘)
21
21
def show (str : String ) =
22
- " \" " +
23
- str
24
- .replaceAll(" \b " , " \\\\ b" )
25
- .replaceAll(" \t " , " \\\\ t" )
26
- .replaceAll(" \n " , " \\\\ n" )
27
- .replaceAll(" \f " , " \\\\ f" )
28
- .replaceAll(" \r " , " \\\\ r" )
29
- .replaceAll(" \' " , " \\\\ '" )
30
- .replaceAll(" \" " , " \\\\\" " ) +
31
- " \" "
22
+ " \" " + {
23
+ val sb = new StringBuilder
24
+ str.foreach {
25
+ case '\b ' => sb.append(" \\ b" )
26
+ case '\t ' => sb.append(" \\ t" )
27
+ case '\n ' => sb.append(" \\ n" )
28
+ case '\f ' => sb.append(" \\ f" )
29
+ case '\r ' => sb.append(" \\ r" )
30
+ case '\' ' => sb.append(" \\ '" )
31
+ case '\" ' => sb.append(" \\\" " )
32
+ case c => sb.append(c)
33
+ }
34
+ sb.toString
35
+ } + " \" "
32
36
}
33
37
34
38
implicit val intShow = new Show [Int ] {
You can’t perform that action at this time.
0 commit comments