Skip to content

Commit

Permalink
Correct conditions in equality check to prepare for YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
OptimumCode committed Aug 31, 2024
1 parent e57aaf2 commit f3339d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@ internal fun areEqualPrimitives(
if (first.isString != second.isString) {
return false
}
return if (first.isString) {
first.content == second.content
} else {
when {
first.isNull || second.isNull -> false
// probably content should be compared ignoring the case - YAML allows different values for boolean
first.isBoolean || second.isBoolean -> first.content == second.content
else -> compareAsNumbers(first, second)
}
return when {
first.isNumber && second.isNumber -> compareAsNumbers(first, second)
// probably content should be compared ignoring the case - YAML allows different values for boolean
first.isBoolean && second.isBoolean -> first.content == second.content
first.isString -> first.content == second.content
else -> false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ internal data class NumberParts(
val precision: Int,
)

internal fun parseNumberParts(element: PrimitiveElement): NumberParts? {
return if (element.isString || element.isNull || element.isBoolean) {
null
} else {
internal fun parseNumberParts(element: PrimitiveElement): NumberParts? =
if (element.isNumber) {
numberParts(element)
} else {
null
}
}

private const val E_SMALL_CHAR: Char = 'e'
private const val E_BIG_CHAR: Char = 'E'
Expand Down

0 comments on commit f3339d8

Please sign in to comment.