Skip to content

Commit

Permalink
Forbid empty strings in month and day-of-week names and AM/PM markers
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalanskyjb committed Apr 29, 2024
1 parent 5978487 commit 420a034
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/common/src/format/DateTimeFormatBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public sealed interface DateTimeFormatBuilder {
*
* [am] is used for the AM marker (0-11 hours), [pm] is used for the PM marker (12-23 hours).
*
* Empty strings can not be used as markers.
*
* @see [amPmHour]
*/
public fun amPmMarker(am: String, pm: String)
Expand Down
6 changes: 6 additions & 0 deletions core/common/src/format/LocalDateFormat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import kotlinx.datetime.internal.format.parser.Copyable

/**
* A description of how month names are formatted.
*
* An empty string can not be a month name.
*/
public class MonthNames(
/**
Expand All @@ -21,6 +23,7 @@ public class MonthNames(
) {
init {
require(names.size == 12) { "Month names must contain exactly 12 elements" }
names.forEach { require(it.isNotEmpty()) { "A month name can not be empty" } }
}

/**
Expand Down Expand Up @@ -63,6 +66,8 @@ internal fun MonthNames.toKotlinCode(): String = when (this.names) {

/**
* A description of how day of week names are formatted.
*
* An empty string can not be a day-of-week name.
*/
public class DayOfWeekNames(
/**
Expand All @@ -72,6 +77,7 @@ public class DayOfWeekNames(
) {
init {
require(names.size == 7) { "Day of week names must contain exactly 7 elements" }
names.forEach { require(it.isNotEmpty()) { "A month name can not be empty" } }
}

/**
Expand Down
1 change: 1 addition & 0 deletions core/common/src/internal/format/parser/ParserOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ internal class StringSetParserOperation<Output>(

init {
for (string in strings) {
require(string.isNotEmpty()) { "Found an empty string in $whatThisExpects" }
var node = trie
for (char in string) {
val searchResult = node.children.binarySearchBy(char.toString()) { it.first }
Expand Down

0 comments on commit 420a034

Please sign in to comment.