Skip to content

Commit

Permalink
Removido o problema de Decrepted para Android
Browse files Browse the repository at this point in the history
  • Loading branch information
ricksolucoes committed Sep 30, 2021
1 parent 104a331 commit 33e88f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
17 changes: 14 additions & 3 deletions src/DataSet.Serialize.Import.pas
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface
{$IF DEFINED(FPC)}
DB, fpjson,
{$ELSE}
System.JSON, Data.DB, System.StrUtils, System.SysUtils, System.Rtti,
System.JSON, Data.DB, System.StrUtils, System.SysUtils, System.Rtti, System.Character,
{$ENDIF}
DataSet.Serialize.Language, DataSet.Serialize.Utils;

Expand Down Expand Up @@ -409,6 +409,9 @@ function TJSONSerialize.JSONPairToFieldName(const AValue: string): string;
var
I: Integer;
LFieldName: string;
LCharacter: Char;
LCharacterBefore: Char;

begin
Result := AValue;
if TDataSetSerializeConfig.GetInstance.CaseNameDefinition = cndLowerCamelCase then
Expand All @@ -419,10 +422,18 @@ function TJSONSerialize.JSONPairToFieldName(const AValue: string): string;
{$ELSE}
for I := 1 to Length(Result) do
{$ENDIF}
begin
{ begin
if CharInSet(Result[I], ['A'..'Z']) and CharInSet(Result[Pred(I)], ['a'..'z']) then
LFieldName := LFieldName + '_';
LFieldName := LFieldName + Result[I];
end;}
begin
LCharacter:= Result[I];
LCharacterBefore:= Result[Pred(I)];

if LCharacter.IsUpper and LCharacterBefore.IsLower then
LFieldName := LFieldName + '_';
LFieldName := LFieldName + Result[I];
end;
Result := LFieldName.ToUpper;
end;
Expand Down Expand Up @@ -759,4 +770,4 @@ function TJSONSerialize.GetKeyValuesDataSet(const ADataSet: TDataSet; const AJSO
end;
end;

end.
end.
15 changes: 11 additions & 4 deletions src/DataSet.Serialize.Utils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class function TDataSetSerializeUtils.CreateValidIdentifier(const AName: string)
SetLength(Result, Length(AName));
for LCharacter in AName do
begin
if CharInSet(LCharacter, ['A' .. 'Z', 'a' .. 'z', '0' .. '9', '_']) then
if LCharacter.IsLower or LCharacter.IsUpper or LCharacter.IsNumber
or LCharacter.IsInArray(['_']) then
begin
Inc(I);
Result[I] := LCharacter;
Expand All @@ -124,8 +125,14 @@ class function TDataSetSerializeUtils.CreateValidIdentifier(const AName: string)
SetLength(Result, I);
if I = 0 then
Result := '_'
else if CharInSet(Result[1], ['0' .. '9']) then
Result := '_' + Result;
// else if CharInSet(Result[1], ['0' .. '9']) then
// Result := '_' + Result;
else
begin
LCharacter:= Result[1];
if LCharacter.IsNumber then
Result := '_' + Result;
end;
end;

class function TDataSetSerializeUtils.FormatCaseNameDefinition(const AFieldName: string): string;
Expand Down Expand Up @@ -247,4 +254,4 @@ class function TDataSetSerializeUtils.BooleanToJSON(const AValue: Boolean): {$IF
Result := {$IF DEFINED(FPC)}TJSONBoolean.Create(False){$ELSE}TJSONFalse.Create{$ENDIF};
end;

end.
end.

0 comments on commit 33e88f8

Please sign in to comment.