diff options
-rw-r--r-- | src/library/scala/StringContext.scala | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/library/scala/StringContext.scala b/src/library/scala/StringContext.scala index 882451680a..06620a82a1 100644 --- a/src/library/scala/StringContext.scala +++ b/src/library/scala/StringContext.scala @@ -79,15 +79,13 @@ case class StringContext(parts: String*) { * start a format specifier), then the string format specifier `%s` is inserted. * * 2. Any `%` characters not in formatting positions are left in the resulting - * string literally. This is achieved by replacing each such occurrence by a string - * format specifier `%s` and adding a corresponding argument string `"%"`. + * string literally. This is achieved by replacing each such occurrence by the string + * format specifier `%%`. */ def f(args: Any*) = { checkLengths(args: _*) val pi = parts.iterator - val ai = args.iterator val bldr = new java.lang.StringBuilder - val args1 = new ArrayBuffer[Any] def copyString(first: Boolean): Unit = { val str = treatEscapes(pi.next()) val strIsEmpty = str.length == 0 @@ -98,23 +96,23 @@ case class StringContext(parts: String*) { bldr append "%s" idx = 1 } - val len = str.length - while (idx < len) { - if (str(idx) == '%') { - bldr append (str substring (start, idx)) append "%s" - args1 += "%" - start = idx + 1 + if (!strIsEmpty) { + val len = str.length + while (idx < len) { + if (str(idx) == '%') { + bldr append (str substring (start, idx)) append "%%" + start = idx + 1 + } + idx += 1 } - idx += 1 + bldr append (str substring (start, idx)) } - if (!strIsEmpty) bldr append (str substring (start, idx)) } copyString(first = true) while (pi.hasNext) { - args1 += ai.next() copyString(first = false) } - bldr.toString format (args1: _*) + bldr.toString format (args: _*) } } |