File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,19 @@ object StringExtensions:
8
8
def spaceSplit : Array [String ] = s.split(" " ).map(_.trim).filter(_.nonEmpty)
9
9
def words : Array [String ] = s.split(" ([^a-zA-Z']+)'*\\ 1*" ).filter(_.nonEmpty)
10
10
11
+ /**
12
+ * Indent and trim each line with spaces and add trailing newline if missing.
13
+ * From Java 17 there is indent on String; this is here to run on Java 8, 11.
14
+ */
15
+ def trimIndent (nbrSpaces : Int ): String =
16
+ s.trim.toLines.map(line => (" " * nbrSpaces) + line.trim).mkString(" " , " \n " , " \n " )
17
+
18
+ /**
19
+ * Strip leading whitespace.
20
+ * From Java 17 there is stripLeading on String; this is here to run on Java 8, 11.
21
+ */
22
+ def stripLeadingWhitespace : String = s.dropWhile(_.isWhitespace)
23
+
11
24
def firstWord : String = s.takeWhile(_.isLetter)
12
25
13
26
def deCapitalize : String = s.take(1 ).toLowerCase ++ s.drop(1 )
@@ -57,9 +70,6 @@ object StringExtensions:
57
70
58
71
def hasNewline : Boolean = s.contains(" \n " )
59
72
60
- def trimIndent (nbrSpaces : Int ): String =
61
- s.trim.toLines.map(line => line.trim).mkString(" \n " ).indent(nbrSpaces)
62
-
63
73
def wrapLongLineAtWords (n : Int ): String =
64
74
val words = s.split(" " ).iterator
65
75
val sb = StringBuilder ()
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ object MarkdownParser:
106
106
107
107
val afterNumOnThisLine =
108
108
restOfLine
109
- .stripLeading
109
+ .stripLeadingWhitespace
110
110
.drop(if numOpt.isDefined && thirdOpt.isDefined then thirdOpt.get.length else 0 )
111
111
.trim
112
112
You can’t perform that action at this time.
0 commit comments