@@ -5,28 +5,25 @@ package kotlin.text
5
5
6
6
/* *
7
7
* Trims leading whitespace characters followed by [marginPrefix] from every line of a source string and removes
8
- * first and last lines if they are blank (notice difference blank vs empty).
8
+ * the first and the last lines if they are blank (notice difference blank vs empty).
9
9
*
10
- * Doesn't affect line if it doesn't contain [marginPrefix] except first and last blank lines.
10
+ * Doesn't affect a line if it doesn't contain [marginPrefix] except the first and the last blank lines.
11
11
*
12
- * Doesn't preserve original line endings.
12
+ * Doesn't preserve the original line endings.
13
13
*
14
- * Example
15
- * ```kotlin
16
- * assertEquals("ABC\n123\n456", """ABC
17
- * |123
18
- * |456""".trimMargin())
19
- * ```
14
+ * @param marginPrefix non-blank string, which is used as a margin delimiter. Default is `|` (pipe character).
20
15
*
21
- * @param marginPrefix non-blank string, characters to be used as a margin delimiter. Default is `|` (pipe character).
22
- * @return deindented String
16
+ * @sample samples.text.Strings.trimMargin
17
+ * @see trimIndent
23
18
* @see kotlin.text.isWhitespace
24
19
*/
25
20
public fun String.trimMargin (marginPrefix : String = "|"): String =
26
21
replaceIndentByMargin(" " , marginPrefix)
27
22
28
23
/* *
29
24
* Detects indent by [marginPrefix] as it does [trimMargin] and replace it with [newIndent].
25
+ *
26
+ * @param marginPrefix non-blank string, which is used as a margin delimiter. Default is `|` (pipe character).
30
27
*/
31
28
public fun String.replaceIndentByMargin (newIndent : String = "", marginPrefix : String = "|"): String {
32
29
require(marginPrefix.isNotBlank()) { " marginPrefix must be non-blank string." }
@@ -44,25 +41,18 @@ public fun String.replaceIndentByMargin(newIndent: String = "", marginPrefix: St
44
41
}
45
42
46
43
/* *
47
- * Detects a common minimal indent of all the input lines, removes it from every line and also removes first and last
44
+ * Detects a common minimal indent of all the input lines, removes it from every line and also removes the first and the last
48
45
* lines if they are blank (notice difference blank vs empty).
49
46
*
50
- * Note that blank lines do not affect detected indent level.
51
- *
52
- * Please keep in mind that if there are non-blank lines with no leading whitespace characters (no indent at all) then the
53
- * common indent is 0 so this function may do nothing so it is recommended to keep first line empty (will be dropped).
47
+ * Note that blank lines do not affect the detected indent level.
54
48
*
55
- * Doesn't preserve original line endings.
49
+ * In case if there are non-blank lines with no leading whitespace characters (no indent at all) then the
50
+ * common indent is 0, and therefore this function doesn't change the indentation.
56
51
*
57
- * Example
58
- * ```kotlin
59
- * assertEquals("ABC\n123\n456", """
60
- * ABC
61
- * 123
62
- * 456""".trimIndent())
63
- * ```
52
+ * Doesn't preserve the original line endings.
64
53
*
65
- * @return deindented String
54
+ * @sample samples.text.Strings.trimIndent
55
+ * @see trimMargin
66
56
* @see kotlin.text.isBlank
67
57
*/
68
58
public fun String.trimIndent (): String = replaceIndent(" " )
@@ -84,7 +74,7 @@ public fun String.replaceIndent(newIndent: String = ""): String {
84
74
/* *
85
75
* Prepends [indent] to every line of the original string.
86
76
*
87
- * Doesn't preserve original line endings.
77
+ * Doesn't preserve the original line endings.
88
78
*/
89
79
public fun String.prependIndent (indent : String = " "): String =
90
80
lineSequence()
0 commit comments