We have a use-case where we have to check if a given string/content is valid ShiftJIS, currently we use this:
function isShiftJISConvertible(s) {
return Encoding.convert(Encoding.convert(s, "SJIS", "UNICODE"), "UNICODE", "SJIS") === s;
}
but that is wasteful since we encode twice. It would be nice if there was an option so we could do
function isShiftJISConvertible(s) {
try {
Encoding.convert(s, {from: "UNICODE", to: "SJIS", fallback: "error"})
return true
} catch {
return false
}
}
Would you accept a pull request to implement such a feature?
We have a use-case where we have to check if a given string/content is valid ShiftJIS, currently we use this:
but that is wasteful since we encode twice. It would be nice if there was an option so we could do
Would you accept a pull request to implement such a feature?