Skip to content

Commit

Permalink
Fixed an issue with comment marker
Browse files Browse the repository at this point in the history
Fixed an issue with comment caracter and now coments should begin with # and a space like:

Co-Authored-By: thanasis bratsas <[email protected]>
# this is a comment
  • Loading branch information
rafael-figueiredo-alves committed Nov 27, 2024
1 parent b389181 commit e2821a1
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 13 deletions.
137 changes: 136 additions & 1 deletion Demo/Delphi/Demo.dproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{96F15591-1663-42C2-A827-5500EA134A38}</ProjectGuid>
<ProjectVersion>19.5</ProjectVersion>
<ProjectVersion>20.1</ProjectVersion>
<FrameworkType>VCL</FrameworkType>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1</TargetedPlatforms>
<AppType>Application</AppType>
<MainSource>Demo.dpr</MainSource>
<ProjectName Condition="'$(ProjectName)'==''">Demo</ProjectName>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
Expand Down Expand Up @@ -216,6 +217,16 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidSplashImageDefV21">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidSplashStyles">
<Platform Name="Android">
<RemoteDir>res\values</RemoteDir>
Expand All @@ -236,6 +247,66 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidSplashStylesV31">
<Platform Name="Android">
<RemoteDir>res\values-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\values-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIcon">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v26</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v26</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIconBackground">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIconForeground">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIconMonochrome">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIconV33">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v33</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v33</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_Colors">
<Platform Name="Android">
<RemoteDir>res\values</RemoteDir>
Expand All @@ -246,6 +317,16 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_ColorsDark">
<Platform Name="Android">
<RemoteDir>res\values-night-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\values-night-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_DefaultAppIcon">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
Expand Down Expand Up @@ -416,6 +497,56 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedNotificationIcon">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v24</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v24</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedSplash">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedSplashDark">
<Platform Name="Android">
<RemoteDir>res\drawable-night-anydpi-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-night-anydpi-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedSplashV31">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedSplashV31Dark">
<Platform Name="Android">
<RemoteDir>res\drawable-night-anydpi-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-night-anydpi-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="DebugSymbols">
<Platform Name="iOSSimulator">
<Operation>1</Operation>
Expand Down Expand Up @@ -656,6 +787,9 @@
<Platform Name="Win64">
<Operation>1</Operation>
</Platform>
<Platform Name="Win64x">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectiOSDeviceDebug">
<Platform Name="iOSDevice32">
Expand Down Expand Up @@ -949,6 +1083,7 @@
<ProjectRoot Platform="OSXARM64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win64x" Name="$(PROJECTNAME)"/>
</Deployment>
<Platforms>
<Platform value="Win32">True</Platform>
Expand Down
Binary file modified Demo/Delphi/Demo.res
Binary file not shown.
4 changes: 3 additions & 1 deletion Demo/Delphi/Win32/Debug/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ MeuNome=Rafael Alves
DB_USERNAME=${MeuNome}\Developer # teste
Nome3=${MeuNome} - ${DB_USERNAME} - ${APPDATA} OK # teste poderoso
Development=True
Port=3001
Port=3001
DBPASSWORD=E#6vK7z
DBPASSWORD2=E#6vK7zXa # comentario
3 changes: 3 additions & 0 deletions Demo/Delphi/uDemo.pas
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ procedure TForm2.Button2Click(Sender: TObject);
Memo1.Lines.Add(DotEnv.Env('MeuNome')); //Usando o nome da variável
Memo1.Lines.Add(DotEnv.Env(DB_USERNAME)); //Usando o enumerado default (procura dentro do arquivo se há uma variável com o nome
Memo1.Lines.Add(DotEnv.Env('Nome3'));
Memo1.Lines.Add(DotEnv.Env('DBPASSWORD2'));
Memo1.Lines.Add(DotEnv.DBPassword);
Memo1.Lines.Add(DotEnv.Env('Teste'));

//Forma de Definir caminho do arquivo
//DotEnv.Config('D:\Meus Projetos\DotEnv4Delphi\Demo\Win32\Debug\.env');
Expand Down
25 changes: 14 additions & 11 deletions src/DotEnv4Delphi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ TDotEnv4Delphi = class(TInterfacedObject, iDotEnv4Delphi)
DotEnv: iDotEnv4Delphi;

const
fVersion = '1.4.0'; //Const to manage versioning
fVersion = '1.5.0'; //Const to manage versioning
SingleQuote = #39; //Caracter '
//--------------------------------------------------------------------------------------------------------------------------

implementation
Expand Down Expand Up @@ -193,22 +194,24 @@ procedure TDotEnv4Delphi.ReadEnvFile;
var
positionOfLastQuote: integer;
begin
if (valor.StartsWith('"')) or (valor.StartsWith(#39)) then
if (valor.StartsWith('"')) or (valor.StartsWith(SingleQuote)) then
begin
positionOfLastQuote := Pos('"', Copy(valor, 2, length(valor) - 1));
if positionOfLastQuote = 0 then
positionOfLastQuote := Pos(#39, Copy(valor, 2, length(valor) - 1));
positionOfLastQuote := Pos(SingleQuote, Copy(valor, 2, length(valor) - 1));

if positionOfLastQuote > 0 then
begin
if Pos('#', valor) > positionOfLastQuote then
Result := Copy(valor, 1, Pos('#', valor) - 1);
if Pos('# ', valor) > positionOfLastQuote then
Result := Copy(valor, 1, Pos('# ', valor) - 2)
else
Result := valor;
end;
end
else
begin
if Pos('#', valor) > 0 then
Result := Copy(valor, 1, Pos('#', valor) - 1)
if Pos('# ', valor) > 0 then
Result := Copy(valor, 1, Pos('# ', valor) - 2)
else
Result := valor;
end;
Expand All @@ -220,7 +223,7 @@ procedure TDotEnv4Delphi.ReadEnvFile;
chave, ValorChave: string;
begin
Result := valor;
if (not valor.StartsWith('"')) and (not valor.StartsWith(#39)) then
if (not valor.StartsWith('"')) and (not valor.StartsWith(SingleQuote)) then
begin
while Pos('${', Result) > 0 do
begin
Expand All @@ -237,16 +240,16 @@ procedure TDotEnv4Delphi.ReadEnvFile;
var
positionOfLastQuote: integer;
begin
if (valor.StartsWith('"')) or (valor.StartsWith(#39)) then
if (valor.StartsWith('"')) or (valor.StartsWith(SingleQuote)) then
begin
positionOfLastQuote := Pos('"', Copy(valor, 2, length(valor) - 1));
if positionOfLastQuote = 0 then
positionOfLastQuote := Pos(#39, Copy(valor, 2, length(valor) - 1));
positionOfLastQuote := Pos(SingleQuote, Copy(valor, 2, length(valor) - 1));

if positionOfLastQuote > 0 then
begin
Result := StringReplace(valor, '"', '', [rfReplaceAll]);
Result := StringReplace(valor, #39, '', [rfReplaceAll]);
Result := StringReplace(valor, SingleQuote, '', [rfReplaceAll]);
end;
end
else
Expand Down

0 comments on commit e2821a1

Please sign in to comment.