Skip to content

Commit

Permalink
Add some helpers to UnicodeCharset
Browse files Browse the repository at this point in the history
  • Loading branch information
er1c committed Jul 9, 2020
1 parent c262c4f commit b7047b6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/src/main/scala/better/files/UnicodeCharset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ object UnicodeCharset {
}
.ensuring(_.nonEmpty, "No unicode charset detected")

def isUnicodeCharset(charset: Charset): Boolean = bomTable.contains(charset)

def isUnicodeCharset(charsetName: String): Boolean =
Charset.isSupported(charsetName) && bomTable.contains(Charset.forName(charsetName))

def apply(charset: Charset, writeByteOrderMarkers: Boolean = false): Charset =
if (bomTable.contains(charset)) new UnicodeCharset(charset, writeByteOrderMarkers) else charset
if (isUnicodeCharset(charset)) new UnicodeCharset(charset, writeByteOrderMarkers)
else charset
}

0 comments on commit b7047b6

Please sign in to comment.