improved TextInputStream

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-07-13 21:11:33 +08:00
parent 8d829b9690
commit dd57965556
2 changed files with 19 additions and 6 deletions

View File

@ -59,6 +59,7 @@ namespace hgl
ByteOrderMask bom; ///<BOM头
ByteOrderMask default_bom; ///<缺省BOM在没有BOM头时使用
ParseCallback *callback; ///<回调函数
private:
@ -75,6 +76,8 @@ namespace hgl
SAFE_CLEAR_ARRAY(buffer);
}
void SetDefaultBOM(const ByteOrderMask &bo){default_bom=bo;} ///<设置缺省BOM头}
/**
*
* @param pc

View File

@ -15,6 +15,7 @@ namespace hgl
stream_size=input_stream->Available();
bom=ByteOrderMask::NONE;
default_bom=ByteOrderMask::UTF8;
callback=nullptr;
}
@ -37,14 +38,19 @@ namespace hgl
else
if(*p=='\r')
{
++p;
if(*p=='\n')
if(p[1]=='\n')
{
callback->OnLine(sp,p-sp-1,true);
++line_count;
++p;
sp=p;
callback->OnLine(sp,p-sp,true);
p+=2;
}
else
{
callback->OnLine(sp,p-sp,true);
++p;
}
++line_count;
sp=p;
}
else
++p;
@ -78,6 +84,10 @@ namespace hgl
p+=bfh->size;
}
else
{
bom=default_bom;
}
}
}