Skip to content

Commit 2a8b4a5

Browse files
committed
appendOptional -> optional
1 parent 40475a5 commit 2a8b4a5

File tree

11 files changed

+38
-38
lines changed

11 files changed

+38
-38
lines changed

core/common/src/LocalDateTime.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public expect class LocalDateTime : Comparable<LocalDateTime> {
5555
* appendMonthNumber(); char('/'); appendDayOfMonth()
5656
* char(' ')
5757
* appendHour(); char(':'); appendMinute()
58-
* appendOptional { char(':'); appendSecond() }
58+
* optional { char(':'); appendSecond() }
5959
* }
6060
* ```
6161
*

core/common/src/LocalTime.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public expect class LocalTime : Comparable<LocalTime> {
9292
* appendMinute()
9393
* char(':')
9494
* appendSecond()
95-
* appendOptional {
95+
* optional {
9696
* char('.')
9797
* appendSecondFraction()
9898
* }

core/common/src/UtcOffset.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public expect class UtcOffset {
5656
* ```
5757
* // `GMT` on zero, `+4:30:15`, using a custom format:
5858
* UtcOffset.Format {
59-
* appendOptional("GMT") {
59+
* optional("GMT") {
6060
* appendOffsetTotalHours(Padding.NONE)
6161
* char(':')
6262
* appendOffsetMinutesOfHour()
63-
* appendOptional {
63+
* optional {
6464
* char(':')
6565
* appendOffsetSecondsOfMinute()
6666
* }

core/common/src/format/FormatBuilder.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,26 @@ public fun <T: FormatBuilder> T.alternativeParsing(
4545
* When parsing, the section is parsed if it is present in the input.
4646
*
4747
* When formatting, the section is formatted if the value of any field in the block is not equal to the default value.
48-
* Only [appendOptional] calls where all the fields have default values are permitted when formatting.
48+
* Only [optional] calls where all the fields have default values are permitted when formatting.
4949
*
5050
* Example:
5151
* ```
5252
* appendHours()
5353
* char(':')
5454
* appendMinutes()
55-
* appendOptional {
55+
* optional {
5656
* char(':')
5757
* appendSeconds()
5858
* }
5959
* ```
6060
*
6161
* Here, because seconds have the default value of zero, they are formatted only if they are not equal to zero.
6262
*
63-
* [onZero] defines the string that is used if values are the default ones.
63+
* [ifZero] defines the string that is used if values are the default ones.
6464
*/
6565
@Suppress("UNCHECKED_CAST")
66-
public fun <T: FormatBuilder> T.appendOptional(onZero: String = "", block: T.() -> Unit): Unit = when (this) {
67-
is AbstractFormatBuilder<*, *> -> appendOptionalImpl(onZero = onZero, block as (AbstractFormatBuilder<*, *>.() -> Unit))
66+
public fun <T: FormatBuilder> T.optional(ifZero: String = "", format: T.() -> Unit): Unit = when (this) {
67+
is AbstractFormatBuilder<*, *> -> appendOptionalImpl(onZero = ifZero, format as (AbstractFormatBuilder<*, *>.() -> Unit))
6868
else -> throw IllegalStateException("impossible")
6969
}
7070

@@ -136,9 +136,9 @@ private fun<T> FormatStructure<T>.builderString(): String = when (this) {
136136
}
137137
is OptionalFormatStructure -> buildString {
138138
if (onZero == "") {
139-
appendLine("appendOptional {")
139+
appendLine("optional {")
140140
} else {
141-
appendLine("appendOptional(${onZero.toKotlinCode()}) {")
141+
appendLine("optional(${onZero.toKotlinCode()}) {")
142142
}
143143
appendLine(format.builderString().prependIndent(CODE_INDENT))
144144
append("}")

core/common/src/format/LocalTimeFormat.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public sealed interface TimeFormatBuilderFields : FormatBuilder {
4747
*
4848
* By default, it's zero-padded to two digits, but this can be changed with [padding].
4949
*
50-
* This field has the default value of 0. If you want to omit it, use [appendOptional].
50+
* This field has the default value of 0. If you want to omit it, use [optional].
5151
*/
5252
public fun appendSecond(padding: Padding = Padding.ZERO)
5353

@@ -59,7 +59,7 @@ public sealed interface TimeFormatBuilderFields : FormatBuilder {
5959
* enough trailing zeros to make the number of digits displayed a multiple of three (e.g. `123.450`) for
6060
* readability. Explicitly set [minLength] to `1` to disable this behavior.
6161
*
62-
* This field has the default value of 0. If you want to omit it, use [appendOptional].
62+
* This field has the default value of 0. If you want to omit it, use [optional].
6363
*
6464
* @throws IllegalArgumentException if [minLength] is greater than [maxLength] or if either is not in the range 1..9.
6565
*/
@@ -282,10 +282,10 @@ internal val ISO_TIME by lazy {
282282
appendHour()
283283
char(':')
284284
appendMinute()
285-
appendOptional {
285+
optional {
286286
char(':')
287287
appendSecond()
288-
appendOptional {
288+
optional {
289289
char('.')
290290
appendSecondFraction()
291291
}
@@ -297,9 +297,9 @@ internal val ISO_TIME_BASIC by lazy {
297297
LocalTimeFormat.build {
298298
alternativeParsing({ char('t') }) { char('T') }
299299
appendHour(); appendMinute()
300-
appendOptional {
300+
optional {
301301
appendSecond()
302-
appendOptional {
302+
optional {
303303
char('.')
304304
appendSecondFraction()
305305
}

core/common/src/format/UtcOffsetFormat.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public sealed interface UtcOffsetFormatBuilderFields : FormatBuilder {
1919
*
2020
* By default, it's zero-padded to two digits, but this can be changed with [padding].
2121
*
22-
* This field has the default value of 0. If you want to omit it, use [appendOptional].
22+
* This field has the default value of 0. If you want to omit it, use [optional].
2323
*/
2424
public fun appendOffsetTotalHours(padding: Padding = Padding.ZERO)
2525

@@ -28,7 +28,7 @@ public sealed interface UtcOffsetFormatBuilderFields : FormatBuilder {
2828
*
2929
* By default, it's zero-padded to two digits, but this can be changed with [padding].
3030
*
31-
* This field has the default value of 0. If you want to omit it, use [appendOptional].
31+
* This field has the default value of 0. If you want to omit it, use [optional].
3232
*/
3333
public fun appendOffsetMinutesOfHour(padding: Padding = Padding.ZERO)
3434

@@ -37,7 +37,7 @@ public sealed interface UtcOffsetFormatBuilderFields : FormatBuilder {
3737
*
3838
* By default, it's zero-padded to two digits, but this can be changed with [padding].
3939
*
40-
* This field has the default value of 0. If you want to omit it, use [appendOptional].
40+
* This field has the default value of 0. If you want to omit it, use [optional].
4141
*/
4242
public fun appendOffsetSecondsOfMinute(padding: Padding = Padding.ZERO)
4343

@@ -120,15 +120,15 @@ internal fun UtcOffsetFormatBuilderFields.appendIsoOffset(
120120
when (outputMinute) {
121121
WhenToOutput.NEVER -> {}
122122
WhenToOutput.IF_NONZERO -> {
123-
appendOptional {
123+
optional {
124124
if (useSeparator) {
125125
char(':')
126126
}
127127
appendOffsetMinutesOfHour()
128128
when (outputSecond) {
129129
WhenToOutput.NEVER -> {}
130130
WhenToOutput.IF_NONZERO -> {
131-
appendOptional {
131+
optional {
132132
if (useSeparator) {
133133
char(':')
134134
}
@@ -154,7 +154,7 @@ internal fun UtcOffsetFormatBuilderFields.appendIsoOffset(
154154
when (outputSecond) {
155155
WhenToOutput.NEVER -> {}
156156
WhenToOutput.IF_NONZERO -> {
157-
appendOptional {
157+
optional {
158158
if (useSeparator) {
159159
char(':')
160160
}
@@ -173,7 +173,7 @@ internal fun UtcOffsetFormatBuilderFields.appendIsoOffset(
173173
}
174174
}
175175
if (zOnZero) {
176-
appendOptional("Z") {
176+
optional("Z") {
177177
alternativeParsing({
178178
char('z')
179179
}) {
@@ -290,11 +290,11 @@ internal class UtcOffsetSecondOfMinuteDirective(padding: Padding) :
290290
internal val ISO_OFFSET by lazy {
291291
UtcOffsetFormat.build {
292292
alternativeParsing({ chars("z") }) {
293-
appendOptional("Z") {
293+
optional("Z") {
294294
appendOffsetTotalHours()
295295
char(':')
296296
appendOffsetMinutesOfHour()
297-
appendOptional {
297+
optional {
298298
char(':')
299299
appendOffsetSecondsOfMinute()
300300
}
@@ -306,11 +306,11 @@ internal val ISO_OFFSET by lazy {
306306
internal val ISO_OFFSET_BASIC by lazy {
307307
UtcOffsetFormat.build {
308308
alternativeParsing({ chars("z") }) {
309-
appendOptional("Z") {
309+
optional("Z") {
310310
appendOffsetTotalHours()
311-
appendOptional {
311+
optional {
312312
appendOffsetMinutesOfHour()
313-
appendOptional {
313+
optional {
314314
appendOffsetSecondsOfMinute()
315315
}
316316
}

core/common/src/format/ValueBagFormat.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public class ValueBag internal constructor(internal val contents: ValueBagConten
110110
appendMinute()
111111
char(':')
112112
appendSecond()
113-
appendOptional {
113+
optional {
114114
char('.')
115115
appendSecondFraction()
116116
}
@@ -148,7 +148,7 @@ public class ValueBag internal constructor(internal val contents: ValueBagConten
148148
appendHour()
149149
char(':')
150150
appendMinute()
151-
appendOptional {
151+
optional {
152152
char(':')
153153
appendSecond()
154154
}
@@ -158,7 +158,7 @@ public class ValueBag internal constructor(internal val contents: ValueBagConten
158158
}, {
159159
chars("Z")
160160
}) {
161-
appendOptional("GMT") {
161+
optional("GMT") {
162162
appendOffset(UtcOffset.Formats.FOUR_DIGITS)
163163
}
164164
}

core/common/src/format/migration/Unicode.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public annotation class FormatStringsInDatetimeFormats
4242
* * `[]` denote optional sections. For example, `hh:mm[:ss]` will allow parsing seconds optionally.
4343
* This is similar to what is supported by the Java Time's `DateTimeFormatter` class, but with the difference that,
4444
* for formatting, the optional sections have a different meaning: they are not included in the output if all the
45-
* fields they contain have their default values. See [FormatBuilder.appendOptional] for more details.
45+
* fields they contain have their default values. See [FormatBuilder.optional] for more details.
4646
* * One or more `p` characters before a field specifies that the field should be padded with zeroes to the length
4747
* equal to the number of `p` characters. This is also supported by the Java Time's `DateTimeFormatter` class.
4848
*
@@ -58,7 +58,7 @@ public fun FormatBuilder.appendUnicodeFormatString(pattern: String) {
5858
when (format) {
5959
is UnicodeStringLiteral -> builder.chars(format.literal)
6060
is UnicodeFormatSequence -> format.formats.forEach { rec(it) }
61-
is UnicodeOptionalGroup -> builder.appendOptional { rec(format.format) }
61+
is UnicodeOptionalGroup -> builder.optional { rec(format.format) }
6262
is UnicodeDirective -> {
6363
when (format) {
6464
is TimeBasedUnicodeDirective -> {

core/common/test/format/DateTimeFormatTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class DateTimeFormatTest {
270270
appendMonthNumber(); char('/'); appendDayOfMonth()
271271
char(' ')
272272
appendHour(); char(':'); appendMinute()
273-
appendOptional { char(':'); appendSecond() }
273+
optional { char(':'); appendSecond() }
274274
}
275275
assertEquals("08/30 18:43:13", dateTime.format(format2))
276276
}

core/common/test/format/TimeFormatTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class TimeFormatTest {
216216
appendMinute()
217217
char(':')
218218
appendSecond()
219-
appendOptional {
219+
optional {
220220
char('.')
221221
appendSecondFraction()
222222
}

core/common/test/format/UtcOffsetFormatTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ class UtcOffsetFormatTest {
165165
@Test
166166
fun testDoc() {
167167
val format = UtcOffset.Format {
168-
appendOptional("GMT") {
168+
optional("GMT") {
169169
appendOffsetTotalHours(Padding.NONE)
170170
char(':')
171171
appendOffsetMinutesOfHour()
172-
appendOptional {
172+
optional {
173173
char(':')
174174
appendOffsetSecondsOfMinute()
175175
}

0 commit comments

Comments
 (0)