mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 18:29:18 +02:00
* Add possibility to specify JSON options
git-svn-id: trunk@33124 -
This commit is contained in:
parent
5576caada6
commit
532bf25233
@ -30,6 +30,8 @@ interface
|
|||||||
uses
|
uses
|
||||||
SysUtils, Classes, fpjson, jsonscanner, jsonparser;
|
SysUtils, Classes, fpjson, jsonscanner, jsonparser;
|
||||||
|
|
||||||
|
Const
|
||||||
|
DefaultJSONOptions = [joUTF8,joComments];
|
||||||
|
|
||||||
type
|
type
|
||||||
EJSONConfigError = class(Exception);
|
EJSONConfigError = class(Exception);
|
||||||
@ -57,9 +59,11 @@ type
|
|||||||
FFormatIndentSize: Integer;
|
FFormatIndentSize: Integer;
|
||||||
FFormatoptions: TFormatOptions;
|
FFormatoptions: TFormatOptions;
|
||||||
FFormatted: Boolean;
|
FFormatted: Boolean;
|
||||||
|
FJSONOptions: TJSONOptions;
|
||||||
FKey: TJSONObject;
|
FKey: TJSONObject;
|
||||||
procedure DoSetFilename(const AFilename: String; ForceReload: Boolean);
|
procedure DoSetFilename(const AFilename: String; ForceReload: Boolean);
|
||||||
procedure SetFilename(const AFilename: String);
|
procedure SetFilename(const AFilename: String);
|
||||||
|
procedure SetJSONOptions(AValue: TJSONOptions);
|
||||||
Function StripSlash(Const P : UnicodeString) : UnicodeString;
|
Function StripSlash(Const P : UnicodeString) : UnicodeString;
|
||||||
protected
|
protected
|
||||||
FJSON: TJSONObject;
|
FJSON: TJSONObject;
|
||||||
@ -109,6 +113,7 @@ type
|
|||||||
Property Formatted : Boolean Read FFormatted Write FFormatted;
|
Property Formatted : Boolean Read FFormatted Write FFormatted;
|
||||||
Property FormatOptions : TFormatOptions Read FFormatoptions Write FFormatOptions Default DefaultFormat;
|
Property FormatOptions : TFormatOptions Read FFormatoptions Write FFormatOptions Default DefaultFormat;
|
||||||
Property FormatIndentsize : Integer Read FFormatIndentSize Write FFormatIndentSize Default DefaultIndentSize;
|
Property FormatIndentsize : Integer Read FFormatIndentSize Write FFormatIndentSize Default DefaultIndentSize;
|
||||||
|
Property JSONOptions : TJSONOptions Read FJSONOptions Write SetJSONOptions Default DefaultJSONOptions;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -127,6 +132,7 @@ begin
|
|||||||
FKey:=FJSON;
|
FKey:=FJSON;
|
||||||
FFormatOptions:=DefaultFormat;
|
FFormatOptions:=DefaultFormat;
|
||||||
FFormatIndentsize:=DefaultIndentSize;
|
FFormatIndentsize:=DefaultIndentSize;
|
||||||
|
FJSONOptions:=DefaultJSONOptions;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TJSONConfig.Destroy;
|
destructor TJSONConfig.Destroy;
|
||||||
@ -687,7 +693,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
F:=TFileStream.Create(AFileName,fmopenRead);
|
F:=TFileStream.Create(AFileName,fmopenRead);
|
||||||
try
|
try
|
||||||
P:=TJSONParser.Create(F,[joUTF8,joComments]);
|
P:=TJSONParser.Create(F,FJSONOptions);
|
||||||
try
|
try
|
||||||
J:=P.Parse;
|
J:=P.Parse;
|
||||||
If (J is TJSONObject) then
|
If (J is TJSONObject) then
|
||||||
@ -712,6 +718,16 @@ begin
|
|||||||
DoSetFilename(AFilename, False);
|
DoSetFilename(AFilename, False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TJSONConfig.SetJSONOptions(AValue: TJSONOptions);
|
||||||
|
begin
|
||||||
|
if FJSONOptions=AValue then Exit;
|
||||||
|
FJSONOptions:=AValue;
|
||||||
|
if csLoading in ComponentState then
|
||||||
|
exit;
|
||||||
|
if (FFileName<>'') then
|
||||||
|
Reload;
|
||||||
|
end;
|
||||||
|
|
||||||
function TJSONConfig.StripSlash(const P: UnicodeString): UnicodeString;
|
function TJSONConfig.StripSlash(const P: UnicodeString): UnicodeString;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
|
Loading…
Reference in New Issue
Block a user