Browse Source

* Implemented CaseSensitive property for TCustomIniFile

git-svn-id: trunk@4419 -
michael 19 years ago
parent
commit
43d73cca57
1 changed files with 51 additions and 28 deletions
  1. 51 28
      fcl/inc/inifiles.pp

+ 51 - 28
fcl/inc/inifiles.pp

@@ -68,7 +68,7 @@ type
   TIniFileKeyList = class(TList)
   TIniFileKeyList = class(TList)
   private
   private
     function GetItem(Index: integer): TIniFileKey;
     function GetItem(Index: integer): TIniFileKey;
-    function KeyByName(AName: string): TIniFileKey;
+    function KeyByName(AName: string; CaseSensitive : Boolean): TIniFileKey;
   public
   public
     destructor Destroy; override;
     destructor Destroy; override;
     procedure Clear;
     procedure Clear;
@@ -89,7 +89,7 @@ override;
   TIniFileSectionList = class(TList)
   TIniFileSectionList = class(TList)
   private
   private
     function GetItem(Index: integer): TIniFileSection;
     function GetItem(Index: integer): TIniFileSection;
-    function SectionByName(AName: string): TIniFileSection;
+    function SectionByName(AName: string; CaseSensitive : Boolean): TIniFileSection;
   public
   public
     destructor Destroy; override;
     destructor Destroy; override;
     procedure Clear;override;
     procedure Clear;override;
@@ -100,6 +100,7 @@ override;
     FFileName: string;
     FFileName: string;
     FSectionList: TIniFileSectionList;
     FSectionList: TIniFileSectionList;
     FEscapeLineFeeds: boolean;
     FEscapeLineFeeds: boolean;
+    FCaseSensitive : Boolean; 
   public
   public
     constructor Create(const AFileName: string);
     constructor Create(const AFileName: string);
     destructor Destroy; override;
     destructor Destroy; override;
@@ -127,6 +128,7 @@ override;
     function ValueExists(const Section, Ident: string): Boolean; virtual;
     function ValueExists(const Section, Ident: string): Boolean; virtual;
     property FileName: string read FFileName;
     property FileName: string read FFileName;
     property EscapeLineFeeds: boolean read FEscapeLineFeeds write FEscapeLineFeeds;
     property EscapeLineFeeds: boolean read FEscapeLineFeeds write FEscapeLineFeeds;
+    Property CaseSensitive : Boolean Read FCaseSensitive Write FCaseSensitive;
   end;
   end;
 
 
   TIniFile = class(TCustomIniFile)
   TIniFile = class(TCustomIniFile)
@@ -204,17 +206,27 @@ begin
     Result := TIniFileKey(inherited Items[Index]);
     Result := TIniFileKey(inherited Items[Index]);
 end;
 end;
 
 
-function TIniFileKeyList.KeyByName(AName: string): TIniFileKey;
+function TIniFileKeyList.KeyByName(AName: string; CaseSensitive : Boolean): TIniFileKey;
 var
 var
   i: integer;
   i: integer;
 begin
 begin
   Result := nil;
   Result := nil;
   if (AName > '') and not IsComment(AName) then
   if (AName > '') and not IsComment(AName) then
-    for i := 0 to Count-1 do
-      if CompareText(Items[i].Ident, AName) = 0 then begin
-        Result := Items[i];
-        Break;
-      end;
+    If CaseSensitive then
+      begin
+      for i := 0 to Count-1 do
+        if Items[i].Ident=AName then 
+          begin
+          Result := Items[i];
+          Break;
+          end;
+      end
+    else  
+      for i := 0 to Count-1 do
+        if CompareText(Items[i].Ident, AName) = 0 then begin
+          Result := Items[i];
+          Break;
+        end;
 end;
 end;
 
 
 destructor TIniFileKeyList.Destroy;
 destructor TIniFileKeyList.Destroy;
@@ -254,17 +266,28 @@ begin
     Result := TIniFileSection(inherited Items[Index]);
     Result := TIniFileSection(inherited Items[Index]);
 end;
 end;
 
 
-function TIniFileSectionList.SectionByName(AName: string): TIniFileSection;
+function TIniFileSectionList.SectionByName(AName: string; CaseSensitive : Boolean): TIniFileSection;
 var
 var
   i: integer;
   i: integer;
 begin
 begin
   Result := nil;
   Result := nil;
   if (AName > '') and not IsComment(AName) then
   if (AName > '') and not IsComment(AName) then
-    for i := 0 to Count-1 do
-      if CompareText(Items[i].Name, AName) = 0 then begin
-        Result := Items[i];
-        Break;
-      end;
+    If CaseSensitive then
+      begin
+      for i:=0 to Count-1 do
+        if (Items[i].Name=AName) then 
+          begin
+          Result := Items[i];
+          Break;
+          end;
+      end
+    else
+      for i := 0 to Count-1 do
+        if CompareText(Items[i].Name, AName) = 0 then 
+          begin
+          Result := Items[i];
+          Break;
+          end;
 end;
 end;
 
 
 destructor TIniFileSectionList.Destroy;
 destructor TIniFileSectionList.Destroy;
@@ -299,7 +322,7 @@ end;
 
 
 function TCustomIniFile.SectionExists(const Section: string): Boolean;
 function TCustomIniFile.SectionExists(const Section: string): Boolean;
 begin
 begin
-  Result := (FSectionList.SectionByName(Section) <> nil);
+  Result := (FSectionList.SectionByName(Section,CaseSensitive) <> nil);
 end;
 end;
 
 
 function TCustomIniFile.ReadInteger(const Section, Ident: string; Default: Longint): Longint;
 function TCustomIniFile.ReadInteger(const Section, Ident: string; Default: Longint): Longint;
@@ -420,9 +443,9 @@ var
   oSection: TIniFileSection;
   oSection: TIniFileSection;
 begin
 begin
   Result := False;
   Result := False;
-  oSection := FSectionList.SectionByName(Section);
+  oSection := FSectionList.SectionByName(Section,CaseSensitive);
   if oSection <> nil then
   if oSection <> nil then
-    Result := (oSection.KeyList.KeyByName(Ident) <> nil);
+    Result := (oSection.KeyList.KeyByName(Ident,CaseSensitive) <> nil);
 end;
 end;
 
 
 { TIniFile }
 { TIniFile }
@@ -554,9 +577,9 @@ var
   oKey: TIniFileKey;
   oKey: TIniFileKey;
 begin
 begin
   Result := Default;
   Result := Default;
-  oSection := FSectionList.SectionByName(Section);
+  oSection := FSectionList.SectionByName(Section,CaseSensitive);
   if oSection <> nil then begin
   if oSection <> nil then begin
-    oKey := oSection.KeyList.KeyByName(Ident);
+    oKey := oSection.KeyList.KeyByName(Ident,CaseSensitive);
     if oKey <> nil then
     if oKey <> nil then
       Result := oKey.Value;
       Result := oKey.Value;
   end;
   end;
@@ -569,14 +592,14 @@ var
 begin
 begin
   if (Section > '') and (Ident > '') then begin
   if (Section > '') and (Ident > '') then begin
     // update or add key
     // update or add key
-    oSection := FSectionList.SectionByName(Section);
+    oSection := FSectionList.SectionByName(Section,CaseSensitive);
     if (Value > '') then begin
     if (Value > '') then begin
       if oSection = nil then begin
       if oSection = nil then begin
         oSection := TIniFileSection.Create(Section);
         oSection := TIniFileSection.Create(Section);
         FSectionList.Add(oSection);
         FSectionList.Add(oSection);
       end;
       end;
       with oSection.KeyList do begin
       with oSection.KeyList do begin
-        oKey := KeyByName(Ident);
+        oKey := KeyByName(Ident,CaseSensitive);
         if oKey <> nil then
         if oKey <> nil then
           oKey.Value := Value
           oKey.Value := Value
         else
         else
@@ -584,7 +607,7 @@ begin
       end;
       end;
     end else if oSection <> nil then begin
     end else if oSection <> nil then begin
       // remove key
       // remove key
-      oKey := oSection.KeyList.KeyByName(Ident);
+      oKey := oSection.KeyList.KeyByName(Ident,CaseSensitive);
       if oKey <> nil then begin
       if oKey <> nil then begin
         oSection.KeyList.Remove(oKey);
         oSection.KeyList.Remove(oKey);
       end;
       end;
@@ -608,7 +631,7 @@ begin
   Strings.BeginUpdate;
   Strings.BeginUpdate;
   try
   try
     Strings.Clear;
     Strings.Clear;
-    oSection := FSectionList.SectionByName(Section);
+    oSection := FSectionList.SectionByName(Section,CaseSensitive);
     if oSection <> nil then with oSection.KeyList do
     if oSection <> nil then with oSection.KeyList do
       for i := 0 to Count-1 do
       for i := 0 to Count-1 do
         if not IsComment(Items[i].Ident) then
         if not IsComment(Items[i].Ident) then
@@ -626,7 +649,7 @@ begin
   Strings.BeginUpdate;
   Strings.BeginUpdate;
   try
   try
     Strings.Clear;
     Strings.Clear;
-    oSection := FSectionList.SectionByName(Section);
+    oSection := FSectionList.SectionByName(Section,CaseSensitive);
     if oSection <> nil then with oSection.KeyList do
     if oSection <> nil then with oSection.KeyList do
       for i := 0 to Count-1 do
       for i := 0 to Count-1 do
         if not IsComment(Items[i].Ident) then
         if not IsComment(Items[i].Ident) then
@@ -665,7 +688,7 @@ begin
   Strings.BeginUpdate;
   Strings.BeginUpdate;
   try
   try
     Strings.Clear;
     Strings.Clear;
-    oSection := FSectionList.SectionByName(Section);
+    oSection := FSectionList.SectionByName(Section,CaseSensitive);
     if oSection <> nil then with oSection.KeyList do
     if oSection <> nil then with oSection.KeyList do
       for i := 0 to Count-1 do begin
       for i := 0 to Count-1 do begin
         s := Items[i].Ident+Separator+Items[i].Value;
         s := Items[i].Ident+Separator+Items[i].Value;
@@ -680,7 +703,7 @@ procedure TIniFile.EraseSection(const Section: string);
 var
 var
   oSection: TIniFileSection;
   oSection: TIniFileSection;
 begin
 begin
-  oSection := FSectionList.SectionByName(Section);
+  oSection := FSectionList.SectionByName(Section,CaseSensitive);
   if oSection <> nil then begin
   if oSection <> nil then begin
     { It is needed so UpdateFile doesn't find a defunct section }
     { It is needed so UpdateFile doesn't find a defunct section }
     { and cause the program to crash }
     { and cause the program to crash }
@@ -695,9 +718,9 @@ var
  oSection: TIniFileSection;
  oSection: TIniFileSection;
  oKey: TIniFileKey;
  oKey: TIniFileKey;
 begin
 begin
- oSection := FSectionList.SectionByName(Section);
+ oSection := FSectionList.SectionByName(Section,CaseSensitive);
  if oSection <> nil then begin
  if oSection <> nil then begin
-   oKey := oSection.KeyList.KeyByName(Ident);
+   oKey := oSection.KeyList.KeyByName(Ident,CaseSensitive);
    if oKey <> nil then begin
    if oKey <> nil then begin
      oSection.KeyList.Delete(oSection.KeyList.IndexOf(oKey));
      oSection.KeyList.Delete(oSection.KeyList.IndexOf(oKey));
      oKey.Free;
      oKey.Free;