Skip to content

Commit 9db61ba

Browse files
authored
Merge pull request scala#6774 from lrytz/si
Make methods in StringContext private
2 parents cee723e + 12c0d27 commit 9db61ba

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

src/library/scala/StringContext.scala

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,6 @@ case class StringContext(parts: String*) {
5555

5656
import StringContext._
5757

58-
/** Checks that the length of the given argument `args` is one less than the number
59-
* of `parts` supplied to the enclosing `StringContext`.
60-
* @param `args` The arguments to be checked.
61-
* @throws IllegalArgumentException if this is not the case.
62-
*/
63-
def checkLengths(args: scala.collection.Seq[Any]): Unit =
64-
if (parts.length != args.length + 1)
65-
throw new IllegalArgumentException("wrong number of arguments ("+ args.length
66-
+") for interpolated string with "+ parts.length +" parts")
67-
68-
6958
/** The simple string interpolator.
7059
*
7160
* It inserts its arguments between corresponding parts of the string context.
@@ -94,7 +83,7 @@ case class StringContext(parts: String*) {
9483
* @note The Scala compiler may replace a call to this method with an equivalent, but more efficient,
9584
* use of a StringBuilder.
9685
*/
97-
def s(args: Any*): String = standardInterpolator(processEscapes, args)
86+
def s(args: Any*): String = standardInterpolator(processEscapes, args, parts)
9887

9988
/** The raw string interpolator.
10089
*
@@ -118,19 +107,7 @@ case class StringContext(parts: String*) {
118107
* @note The Scala compiler may replace a call to this method with an equivalent, but more efficient,
119108
* use of a StringBuilder.
120109
*/
121-
def raw(args: Any*): String = standardInterpolator(identity, args)
122-
123-
def standardInterpolator(process: String => String, args: scala.collection.Seq[Any]): String = {
124-
checkLengths(args)
125-
val pi = parts.iterator
126-
val ai = args.iterator
127-
val bldr = new JLSBuilder(process(pi.next()))
128-
while (ai.hasNext) {
129-
bldr append ai.next
130-
bldr append process(pi.next())
131-
}
132-
bldr.toString
133-
}
110+
def raw(args: Any*): String = standardInterpolator(identity, args, parts)
134111

135112
/** The formatted string interpolator.
136113
*
@@ -244,4 +221,27 @@ object StringContext {
244221
case i => replace(i)
245222
}
246223
}
224+
225+
private def standardInterpolator(process: String => String, args: scala.collection.Seq[Any], parts: Seq[String]): String = {
226+
checkLengths(args, parts)
227+
val pi = parts.iterator
228+
val ai = args.iterator
229+
val bldr = new JLSBuilder(process(pi.next()))
230+
while (ai.hasNext) {
231+
bldr append ai.next
232+
bldr append process(pi.next())
233+
}
234+
bldr.toString
235+
}
236+
237+
/** Checks that the length of the given argument `args` is one less than the number
238+
* of `parts` supplied to the `StringContext`.
239+
*
240+
* @throws IllegalArgumentException if this is not the case.
241+
*/
242+
private def checkLengths(args: scala.collection.Seq[Any], parts: Seq[String]): Unit =
243+
if (parts.length != args.length + 1)
244+
throw new IllegalArgumentException("wrong number of arguments ("+ args.length
245+
+") for interpolated string with "+ parts.length +" parts")
246+
247247
}

test/files/presentation/t8941/src/Source.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object Foo {
22
implicit class MatCreator(val ctx: StringContext) extends AnyVal {
33
def m(args: Any*): Unit = {
4-
ctx.checkLengths(args)
4+
ctx.s(args: _*)
55
}
66
???/*?*/
77
}

0 commit comments

Comments
 (0)