Skip to content

Commit

Permalink
Merge pull request #241 from nafg/identifier-quotedifnecessary--cover…
Browse files Browse the repository at this point in the history
…-more-cases

Identifier.quotedIfNecessary: cover more cases
  • Loading branch information
nafg authored Dec 14, 2023
2 parents c6f6d51 + 2494650 commit 89c2ff6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion project/Identifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ case class Identifier(value: String) {
object Identifier {
val keywords = Set("type", "true", "false")
def quotedIfNecessary(value: String) =
if (keywords.contains(value) || value.contains('-') || value.headOption.forall(_.isDigit))
if (
keywords.contains(value) ||
value.headOption.exists(!Character.isJavaIdentifierStart(_)) ||
value.exists(!Character.isJavaIdentifierPart(_))
)
"`" + value + "`"
else
value
Expand Down

0 comments on commit 89c2ff6

Please sign in to comment.