Skip to content

Instantly share code, notes, and snippets.

@yohhoy
Last active September 15, 2020 04:58
Show Gist options
  • Save yohhoy/fca5a2f40dd87cea4f3c40490591ec3c to your computer and use it in GitHub Desktop.
Save yohhoy/fca5a2f40dd87cea4f3c40490591ec3c to your computer and use it in GitHub Desktop.
UTF-8 util
bool starts_with_utf8bom(std::string_view s)
{
constexpr char utf8_bom[3] = { 0xEF, 0xBB, 0xBF };
return s.length() >= 3 && std::equal(utf8_bom, utf8_bom + 3, s.begin());
}
std::string& erase_utf8bom(std::string& text)
{
if (starts_with_utf8bom(text)) {
text.erase(0, 3);
}
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment