Skip to content

Commit

Permalink
Now ParseFromFile can read UTF8-BOM files (#136)
Browse files Browse the repository at this point in the history
* ignore file add

* Issue #128

* reading from UTF8 with BOM files, no U-ecsaping unicode letters
  • Loading branch information
vkrapotkin authored Dec 9, 2020
1 parent 4e60eb8 commit 2d3ec01
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
48 changes: 48 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#delphi compiled modules
*.exe
*.dll
*.bpl
*.bpi
*.dcp
*.so
*.apk
*.drc
*.map
*.dres
*.rsm
*.tds
*.dcu
*.lib
*.a
*.ocx
*.o
*.stat
*.local
*.identcache
*.~*
__history/
__recovery/
Android/
iOSDevice32/
OSX32/
iOSSimulator/

#idea project
#/.idea
#/doc/.idea


# Delphi autogenerated files (duplicated info)
*.cfg
*.hpp
*Resource.rc

# Delphi local files (user-specific info)
*.local
*.identcache
*.projdata
*.tvsconfig
*.dsk

# Castalia statistics file (since XE7 Castalia is distributed with Delphi)
*.stat
10 changes: 5 additions & 5 deletions XSuperJSON.pas
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(*
* XSuperObject - Simple JSON Framework
*
* The MIT License (MIT)
* XSuperObject - Simple JSON Framework
*
* The MIT License (MIT)
* Copyright (c) 2015 Onur YILDIZ
*
*
Expand All @@ -23,7 +23,7 @@
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
* THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
*)

unit XSuperJSON;
Expand Down Expand Up @@ -646,7 +646,7 @@ implementation
end;
#34{"}: Result := Result + '\"';
#92{\}: Result := Result + '\\';
#127..#65535: Result := Result + ChrtoUTF16(Ord(Tmp^));
//#127..#65535: Result := Result + ChrtoUTF16(Ord(Tmp^));
else
Result := Result + Tmp^;
end;
Expand Down
18 changes: 14 additions & 4 deletions XSuperObject.pas
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(*
(*
* XSuperObject - Simple JSON Framework
*
* The MIT License (MIT)
Expand Down Expand Up @@ -1280,7 +1280,7 @@ procedure TSuperObject.Next;
Inc(FOffset);
end;

class function TSuperObject.ParseFile(FileName: String; CheckDate: Boolean): TSuperObject;
class function TSuperObject.ParseFile(FileName: String; CheckDate: Boolean = True): TSuperObject;
var
Strm: TFileStream;
begin
Expand All @@ -1295,11 +1295,21 @@ class function TSuperObject.ParseFile(FileName: String; CheckDate: Boolean): TSu
class function TSuperObject.ParseStream(Stream: TStream; CheckDate: Boolean): TSuperObject;
var
Strm: TStringStream;
preamble, tmp: TBytes;
preambleLength: integer;
enc: TEncoding;
begin
Strm := TStringStream.Create;
try
Strm.LoadFromStream(Stream);
Result := TSuperObject.Create(Strm.DataString, CheckDate);
SetLength(tmp,10);
strm.read(tmp, 10);
enc := nil;
preambleLength := TEncoding.GetBufferEncoding(tmp, enc);
if preambleLength <> 0 then
Result := TSuperObject.Create(enc.GetString(strm.Bytes, preambleLength, stream.Size - preambleLength), CheckDate)
else
Result := TSuperObject.Create(Strm.Datastring, CheckDate);
finally
Strm.Free;
end;
Expand Down Expand Up @@ -1551,7 +1561,7 @@ procedure TSuperArray.SaveTo(Stream: TStream; const Ident, UniversalTime: Boolea
begin
S := TStringStream.Create( AsJSON(Ident, UniversalTime) );
try
S.SaveToStream(S);
S.SaveToStream(Stream);
finally
S.Free;
end;
Expand Down

0 comments on commit 2d3ec01

Please sign in to comment.