Core: Utf8BOM (skips UTF8 file header)

This commit is contained in:
Mirek Fidler 2021-08-24 18:05:56 +02:00
parent 1932ae3b9e
commit 9d34bf831e
3 changed files with 18 additions and 0 deletions

View file

@ -2,6 +2,15 @@
namespace Upp {
bool Utf8BOM(Stream& in)
{
int64 pos = in.GetPos();
if(in.Get() == 0xef && in.Get() == 0xbb && in.Get() == 0xbf)
return true;
in.Seek(pos);
return false;
}
static void sLoadBom(Stream& in, String *t, WString *wt, byte def_charset)
{
if(in.IsOpen()) {

View file

@ -251,6 +251,9 @@ bool SaveFileBOM(const char *path, const WString& data);
bool SaveStreamBOMUtf8(Stream& out, const String& data);
bool SaveFileBOMUtf8(const char *path, const String& data);
bool Utf8BOM(Stream& in);
// Deprecated
word UnicodeCombine(word chr, word combine);

View file

@ -705,6 +705,12 @@ true on success.&]
true on success.&]
[s3; &]
[s4; &]
[s5;:Upp`:`:Utf8BOM`(Upp`:`:Stream`&`): [@(0.0.255) bool]_[* Utf8BOM]([_^Upp`:`:Stream^ Str
eam][@(0.0.255) `&]_[*@3 in])&]
[s2;%% Tests for and skips UTF`-8 BOM mark in the seekable Stream
[%-*@3 in].&]
[s3;%% &]
[s4; &]
[s5;:FromUtf8`(const char`*`,int`): [_^WString^ WString]_[* FromUtf8]([@(0.0.255) const]_[@(0.0.255) c
har]_`*[*@3 `_s], [@(0.0.255) int]_[*@3 len])&]
[s2;%% Converts UTF`-8 to UNICODE string. Any wrong bytes and sequences