File tree 1 file changed +4
-17
lines changed
shared/src/main/scala/scala/xml
1 file changed +4
-17
lines changed Original file line number Diff line number Diff line change @@ -113,25 +113,12 @@ object Utility extends AnyRef with parsing.TokenTests {
113
113
final def escape (text : String , s : StringBuilder ): StringBuilder = {
114
114
// Implemented per XML spec:
115
115
// http://www.w3.org/International/questions/qa-controls
116
- // imperative code 3x-4x faster than current implementation
117
- // dpp (David Pollak) 2010/02/03
118
- val len = text.length
119
- var pos = 0
120
- while (pos < len) {
121
- text.charAt(pos) match {
122
- case '<' => s.append(" <" )
123
- case '>' => s.append(" >" )
124
- case '&' => s.append(" &" )
125
- case '"' => s.append(" "" )
126
- case '\n ' => s.append('\n ' )
127
- case '\r ' => s.append('\r ' )
128
- case '\t ' => s.append('\t ' )
129
- case c => if (c >= ' ' ) s.append(c)
116
+ text.iterator.foldLeft(s) { (s, c) =>
117
+ escMap.get(c) match {
118
+ case Some (str) => s ++= str
119
+ case _ if c >= ' ' || " \n\r\t " .contains(c) => s += c
130
120
}
131
-
132
- pos += 1
133
121
}
134
- s
135
122
}
136
123
137
124
/**
You can’t perform that action at this time.
0 commit comments