Comments (6)
Hi,
Nice hint! That was in my plans.
I think it is simple to implement BOM support and LoadFromStream()
is indeed the right place to filter the enconding.
Stay tuned.
Regards,
from mcjson.
Thank you!
from mcjson.
Hi, about UTF-8 BOM, please test the latest update.
from mcjson.
Hi, I saw the BOM bypass code, thank you! I would add a tip to be faster (we need the speed), because this solution will completely copy the string, even if it is very big, and this is an unnecessary operation. I think we should detect Bom as a stream, and then:
if utf8bomheaderdetect (stream) THEN
Stream.seek (Length (Cutf8bomheader), Sofromcurrent);
Because stream.read will read from Position(!).
So you just have to slip the position. Or simply set the PostionAfterBOM to TRUE in UTF8BOMHeaderDetect, my quick code for this:
type
TUTF8BOMHeader = array [0..2] of byte;
const
//https://en.wikipedia.org/wiki/Byte_order_mark
cUTF8BOMHeader: TUTF8BOMHeader = ($EF, $BB, $BF);
function UTF8BOMHeaderDetect(const Stream: TStream;
const PostionAfterBOM: boolean = False): boolean;
var
UTF8BOMHeader: TUTF8BOMHeader;
StreamPositionBuf: int64;
begin
Result := False;
Initialize(UTF8BOMHeader, Length(UTF8BOMHeader));
if Stream.Size < Length(cUTF8BOMHeader) then
exit;
StreamPositionBuf := Stream.Position;
Stream.Read(UTF8BOMHeader, Length(UTF8BOMHeader));
if CompareMem(@UTF8BOMHeader, @cUTF8BOMHeader, Length(cUTF8BOMHeader)) then
begin
if not (PostionAfterBOM) then Stream.Position := StreamPositionBuf;
Result := True;
end
else
Stream.Position := StreamPositionBuf;
end;
from mcjson.
But by the way, your code also loads the UTF8 BOM encoded file, thanks!
from mcjson.
Nice hint about performance. I'll give it a try.
Thanks.
from mcjson.
Related Issues (20)
- Improve test case HOT 2
- Excepted got "/" (Comment support) HOT 11
- Unknown escape at pos (escpaing support) HOT 15
- McJsonEscapeString (overzealous) HOT 17
- Slow json generation speed HOT 5
- MCJsonUnEscapeString "/" and "\" missing after unescape HOT 3
- HasKey exception HOT 11
- New empty key destroys the json structure HOT 10
- Check function does not return the wrong position HOT 7
- Check function speed problem HOT 10
- ToString using string buffer instead concatenation HOT 4
- Slower shortener operation (but I realized this is normal because of the AddOrSet search) HOT 7
- McJSONEscapeString TAB problem HOT 3
- how to get int64 value ? HOT 2
- When value is a json string, tostring does not handle escaping HOT 5
- Range check error HOT 9
- PrjTestMcJSON - many exception HOT 5
- Shorteners self-test result HOT 7
- Test #13 failed in Main branch (trunk rev. #94) HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mcjson.