summaryrefslogtreecommitdiff
path: root/src/scaladoc/scala/tools/nsc/doc/base
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-09-16 11:36:51 +1000
committerJason Zaugg <jzaugg@gmail.com>2014-09-16 11:36:51 +1000
commit2724a1ce206eee03d984472b19ac908fc62e9ccc (patch)
treeba39a0e0ba6d6d896e898526316d567ea080ff5f /src/scaladoc/scala/tools/nsc/doc/base
parentc154d343348218d1008e4217713246c3e23acd1d (diff)
parentabd595db299024b76f75da0728ae7ec4fca4bcae (diff)
downloadscala-2724a1ce206eee03d984472b19ac908fc62e9ccc.tar.gz
scala-2724a1ce206eee03d984472b19ac908fc62e9ccc.tar.bz2
scala-2724a1ce206eee03d984472b19ac908fc62e9ccc.zip
Merge commit 'abd595d' into merge/2.11.x-to-2.12.x-20140915
Diffstat (limited to 'src/scaladoc/scala/tools/nsc/doc/base')
-rwxr-xr-xsrc/scaladoc/scala/tools/nsc/doc/base/CommentFactoryBase.scala58
1 files changed, 14 insertions, 44 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/base/CommentFactoryBase.scala b/src/scaladoc/scala/tools/nsc/doc/base/CommentFactoryBase.scala
index d5e2f9a2c4..7cd8fa8e51 100755
--- a/src/scaladoc/scala/tools/nsc/doc/base/CommentFactoryBase.scala
+++ b/src/scaladoc/scala/tools/nsc/doc/base/CommentFactoryBase.scala
@@ -681,10 +681,10 @@ trait CommentFactoryBase { this: MemberLookupBase =>
jump("[[")
val parens = 2 + repeatJump('[')
val stop = "]" * parens
- val target = readUntil { check(stop) || check(" ") }
+ val target = readUntil { check(stop) || isWhitespaceOrNewLine(char) }
val title =
if (!check(stop)) Some({
- jump(" ")
+ jumpWhitespaceOrNewLine()
inline(check(stop))
})
else None
@@ -723,49 +723,15 @@ trait CommentFactoryBase { this: MemberLookupBase =>
*/
def normalizeIndentation(_code: String): String = {
- val code = _code.trim
- var maxSkip = Integer.MAX_VALUE
- var crtSkip = 0
- var wsArea = true
- var index = 0
- var firstLine = true
- var emptyLine = true
-
- while (index < code.length) {
- code(index) match {
- case ' ' =>
- if (wsArea)
- crtSkip += 1
- case c =>
- wsArea = (c == '\n')
- maxSkip = if (firstLine || emptyLine) maxSkip else if (maxSkip <= crtSkip) maxSkip else crtSkip
- crtSkip = if (c == '\n') 0 else crtSkip
- firstLine = if (c == '\n') false else firstLine
- emptyLine = if (c == '\n') true else false
- }
- index += 1
- }
+ val code = _code.replaceAll("\\s+$", "").dropWhile(_ == '\n') // right-trim + remove all leading '\n'
+ val lines = code.split("\n")
- if (maxSkip == 0)
- code
- else {
- index = 0
- val builder = new StringBuilder
- while (index < code.length) {
- builder.append(code(index))
- if (code(index) == '\n') {
- // we want to skip as many spaces are available, if there are less spaces (like on empty lines, do not
- // over-consume them)
- index += 1
- val limit = index + maxSkip
- while ((index < code.length) && (code(index) == ' ') && index < limit)
- index += 1
- }
- else
- index += 1
- }
- builder.toString
- }
+ // maxSkip - size of the longest common whitespace prefix of non-empty lines
+ val nonEmptyLines = lines.filter(_.trim.nonEmpty)
+ val maxSkip = if (nonEmptyLines.isEmpty) 0 else nonEmptyLines.map(line => line.prefixLength(_ == ' ')).min
+
+ // remove common whitespace prefix
+ lines.map(line => if (line.trim.nonEmpty) line.substring(maxSkip) else line).mkString("\n")
}
def checkParaEnded(): Boolean = {
@@ -899,6 +865,8 @@ trait CommentFactoryBase { this: MemberLookupBase =>
def jumpWhitespace() = jumpUntil(!isWhitespace(char))
+ def jumpWhitespaceOrNewLine() = jumpUntil(!isWhitespaceOrNewLine(char))
+
/* READERS */
final def readUntil(c: Char): String = {
@@ -938,5 +906,7 @@ trait CommentFactoryBase { this: MemberLookupBase =>
/* CHARS CLASSES */
def isWhitespace(c: Char) = c == ' ' || c == '\t'
+
+ def isWhitespaceOrNewLine(c: Char) = isWhitespace(c) || c == '\n'
}
}