File tree Expand file tree Collapse file tree 5 files changed +41
-2
lines changed
main/kotlin/com/javiersc/kotlin/stdlib
test/kotlin/com/javiersc/kotlin/stdlib Expand file tree Collapse file tree 5 files changed +41
-2
lines changed Original file line number Diff line number Diff line change 4
4
5
5
### Added
6
6
7
+ - ` String::capitalize `
8
+ - ` String::decapitalize `
9
+
7
10
### Changed
8
11
9
12
### Deprecated
Original file line number Diff line number Diff line change @@ -142,6 +142,8 @@ public final class com/javiersc/kotlin/stdlib/AnsiColorsKt {
142
142
}
143
143
144
144
public final class com/javiersc/kotlin/stdlib/CollectionsKt {
145
+ public static final fun capitalize (Ljava/lang/String;)Ljava/lang/String;
146
+ public static final fun decapitalize (Ljava/lang/String;)Ljava/lang/String;
145
147
public static final fun fifth (Ljava/lang/Iterable;)Ljava/lang/Object;
146
148
public static final fun fifthOrNull (Ljava/lang/Iterable;)Ljava/lang/Object;
147
149
public static final fun forth (Ljava/lang/Iterable;)Ljava/lang/Object;
Original file line number Diff line number Diff line change @@ -142,6 +142,8 @@ public final class com/javiersc/kotlin/stdlib/AnsiColorsKt {
142
142
}
143
143
144
144
public final class com/javiersc/kotlin/stdlib/CollectionsKt {
145
+ public static final fun capitalize (Ljava/lang/String;)Ljava/lang/String;
146
+ public static final fun decapitalize (Ljava/lang/String;)Ljava/lang/String;
145
147
public static final fun fifth (Ljava/lang/Iterable;)Ljava/lang/Object;
146
148
public static final fun fifthOrNull (Ljava/lang/Iterable;)Ljava/lang/Object;
147
149
public static final fun forth (Ljava/lang/Iterable;)Ljava/lang/Object;
Original file line number Diff line number Diff line change 2
2
3
3
package com.javiersc.kotlin.stdlib
4
4
5
+ /* *
6
+ * Returns a copy of this string having its first letter title-cased using the rules of the default
7
+ * locale, or the original string if it's empty or already starts with a title case letter.
8
+ *
9
+ * The title case of a character is usually the same as its upper case with several exceptions. The
10
+ * particular list of characters with the special title case form depends on the underlying
11
+ * platform.
12
+ */
13
+ public inline fun String.capitalize (): String = replaceFirstChar {
14
+ if (it.isLowerCase()) it.titlecase() else it.toString()
15
+ }
16
+
17
+ /* *
18
+ * Returns a copy of this string having its first letter lowercased using the rules of the default
19
+ * locale, or the original string if it's empty or already starts with a lower case letter.
20
+ */
21
+ public inline fun String.decapitalize (): String = replaceFirstChar { it.lowercase() }
22
+
5
23
/* *
6
24
* Returns second element.
7
25
*
Original file line number Diff line number Diff line change @@ -6,6 +6,20 @@ import kotlin.test.assertTrue
6
6
7
7
class StringsTest {
8
8
9
+ @Test
10
+ fun string_capitalize () {
11
+ assertTrue { " hello" .capitalize() == " Hello" }
12
+ assertTrue { " Hello" .capitalize() == " Hello" }
13
+ assertTrue { " hElLo" .capitalize() == " HElLo" }
14
+ }
15
+
16
+ @Test
17
+ fun string_decapitalize () {
18
+ assertTrue { " hello" .decapitalize() == " hello" }
19
+ assertTrue { " Hello" .decapitalize() == " hello" }
20
+ assertTrue { " HElLo" .decapitalize() == " hElLo" }
21
+ }
22
+
9
23
@Test
10
24
fun string_remove () {
11
25
assertTrue { " Hello, World" .remove(" Hello, " ) == " World" }
@@ -41,15 +55,15 @@ class StringsTest {
41
55
}
42
56
43
57
@Test
44
- fun remove_duplicate_empty_lines () {
58
+ fun string_remove_duplicate_empty_lines () {
45
59
assertTrue { " a\n b\n\n\n c\n " .removeDuplicateEmptyLines() == " a\n b\n\n c\n " }
46
60
assertTrue { " a\n\n b\n\n\n c\n " .removeDuplicateEmptyLines() == " a\n\n b\n\n c\n " }
47
61
assertTrue { " a\n\n b\n\n\n c\n\n " .removeDuplicateEmptyLines() == " a\n\n b\n\n c\n " }
48
62
assertTrue { " a\n\n\n\n\n b\n\n " .removeDuplicateEmptyLines() == " a\n\n b\n " }
49
63
}
50
64
51
65
@Test
52
- fun end_with_new_line () {
66
+ fun string_end_with_new_line () {
53
67
assertTrue { " a" .endWithNewLine() == " a\n " }
54
68
assertTrue { " a\n " .endWithNewLine() == " a\n " }
55
69
assertTrue { " " .endWithNewLine() == " " }
You can’t perform that action at this time.
0 commit comments