Skip to content

Instantly share code, notes, and snippets.

@yohhoy

yohhoy/utf8_util.hpp

Last active Sep 15, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.