Last active
September 15, 2020 04:58
-
-
Save yohhoy/fca5a2f40dd87cea4f3c40490591ec3c to your computer and use it in GitHub Desktop.
UTF-8 util
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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