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