Changeset 63
- Timestamp:
- Jan 13, 2017, 10:50:31 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ScreenTools.pas
r62 r63 1558 1558 if FileExists(DataDir + 'Localization' + DirectorySeparator + 'Language.txt') then 1559 1559 begin 1560 Phrases.loadfromfile(DataDir + 'Localization' + DirectorySeparator + ' +Language.txt');1560 Phrases.loadfromfile(DataDir + 'Localization' + DirectorySeparator + 'Language.txt'); 1561 1561 if FileExists(DataDir + 'Localization' + DirectorySeparator + 'Language2.txt') then 1562 1562 Phrases2.loadfromfile(DataDir + 'Localization' + DirectorySeparator + 'Language2.txt') -
trunk/StringTables.pas
r38 r63 4 4 interface 5 5 6 const 7 MaxCount = 4000;6 uses 7 Classes; 8 8 9 9 type 10 TCharList = array [0 .. 9999999] of AnsiChar;10 { TStringTable } 11 11 12 12 TStringTable = class 13 private 14 Lines: TStringList; 15 function IsLabel(Text, Name: string): Boolean; 16 public 13 17 constructor Create; 14 18 destructor Destroy; override; … … 18 22 function Lookup(const Item: string; Index: integer = -1): string; 19 23 function Search(const Content: string; var Handle, Index: integer): boolean; 20 protected21 Count: integer;22 Data: ^TCharList;23 Lines: array [0 .. MaxCount - 1] of PAnsiChar;24 24 end; 25 25 … … 27 27 28 28 uses 29 Classes, SysUtils; 29 SysUtils; 30 31 function TStringTable.IsLabel(Text, Name: string): Boolean; 32 begin 33 Result := ((Copy(Text, 1, 1) = '#') and (Copy(Text, 2, Length(Name)) = Name)) 34 and ((Length(Text) = (Length(Name) + 1)) or (Copy(Text, Length(Name) + 2, 1) = ' ')); 35 end; 30 36 31 37 constructor TStringTable.Create; 32 38 begin 33 Data := nil;39 Lines := TStringList.Create; 34 40 end; 35 41 36 42 destructor TStringTable.Destroy; 37 43 begin 38 if Data <> nil then 39 FreeMem(Data); 44 FreeAndNil(Lines); 40 45 end; 41 46 42 function TStringTable.LoadFromFile(const FileName: string): boolean; 43 var 44 nData, i: integer; 45 f: TFileStream; 47 function TStringTable.LoadFromFile(const FileName: String): boolean; 46 48 begin 47 if Data <> nil then 48 FreeMem(Data); 49 try 50 f := TFileStream.Create(FileName, fmOpenRead or fmShareExclusive); 51 except 52 result := false; 53 exit; 54 end; 55 result := true; 56 nData := f.Size; 57 GetMem(Data, nData + 1); 58 f.read(Data^, nData); 59 f.Free; 60 i := 0; 61 Count := 0; 62 while (i < nData) and (Count < MaxCount) do 63 begin 64 Lines[Count] := @Data[i]; 65 while (i < nData) and (Data[i] <> #13) do 66 inc(i); 67 Data[i] := #0; 68 inc(i, 2); 69 inc(Count); 70 end; 49 Lines.LoadFromFile(FileName); 71 50 end; 72 51 73 52 function TStringTable.GetHandle(const Item: AnsiString): integer; 74 53 var 75 i, l: integer;54 I: Integer; 76 55 begin 77 l := Length(Item); 78 i := Count - 1; 79 while (i >= 0) and ((Lines[i][0] <> '#') or (StrLComp(Lines[i] + 1, @Item[1], 80 l) <> 0) or (Lines[i][l + 1] <> #0) and (Lines[i][l + 1] <> ' ')) do 81 dec(i); 82 result := i 56 I := 0; 57 while (I < Lines.Count) and not IsLabel(Lines[I], Item) do 58 Inc(I); 59 if I < Lines.Count then Result := I 60 else Result := -1; 83 61 end; 84 62 … … 88 66 begin 89 67 if Index < 0 then 90 if Handle < 0 then 91 begin 92 result := ''; 93 exit 94 end 95 else 96 begin 97 if pos(' ', Lines[Handle]) = 0 then 98 s := '' 99 else 100 s := copy(Lines[Handle], pos(' ', Lines[Handle]) + 1, MaxInt); 101 while (Handle + 1 < Count) and (Lines[Handle + 1][0] <> '#') do 102 begin 103 inc(Handle); 104 if (Lines[Handle][0] <> #0) and (Lines[Handle][0] <> '''') then 105 begin 68 if Handle < 0 then begin 69 Result := ''; 70 Exit; 71 end else begin 72 if Pos(' ', Lines[Handle]) = 0 then S := '' 73 else s := Copy(Lines[Handle], Pos(' ', Lines[Handle]) + 1, MaxInt); 74 while ((Handle + 1) < Lines.Count) and (Copy(Lines[Handle + 1], 1, 1) <> '#') do begin 75 Inc(Handle); 76 if (Length(Lines[Handle]) > 0) and (Lines[Handle][1] <> '''') then begin 106 77 if (s <> '') and (s[Length(s)] <> '\') then 107 78 s := s + ' '; 108 79 s := s + Lines[Handle]; 109 end 80 end; 110 81 end; 111 result := s 112 end 113 else if Handle + Index + 1 >= Count then 114 begin 115 result := ''; 116 exit 117 end 118 else 119 result := Lines[Handle + Index + 1]; 120 while (result <> '') and ((result[1] = ' ') or (result[1] = #9)) do 121 Delete(result, 1, 1); 122 while (result <> '') and ((result[Length(result)] = ' ') or 123 (result[Length(result)] = #9)) do 124 Delete(result, Length(result), 1); 125 if result = '' then 126 result := '*'; 82 Result := S; 83 end else 84 if (Handle + Index + 1) >= Lines.Count then begin 85 Result := ''; 86 Exit; 87 end else Result := Lines[Handle + Index + 1]; 88 while (Result <> '') and ((Result[1] = ' ') or (Result[1] = #9)) do 89 Delete(Result, 1, 1); 90 while (Result <> '') and ((Result[Length(Result)] = ' ') or 91 (Result[Length(Result)] = #9)) do 92 Delete(Result, Length(Result), 1); 93 if Result = '' then Result := '*'; 127 94 end; 128 95 … … 178 145 i := Index + 1; 179 146 repeat 180 if h + i + 1 >= Count then147 if h + i + 1 >= Lines.Count then 181 148 begin 182 149 result := false; 183 150 exit 184 151 end; 185 if Lines[h + i + 1][0]= '#' then152 if Copy(Lines[h + i + 1], 1, 1) = '#' then 186 153 begin 187 154 h := h + i + 1; 188 155 i := -1 189 156 end; 190 if (h >= 0) and not (Lines[h + i + 1][0] in ['#', ':', ';']) and191 ( pos(UContent, UpperCase(Lines[h + i + 1])) > 0) then157 if (h >= 0) and not ((Length(Lines[h + i + 1]) > 0) and (Lines[h + i + 1][1] in ['#', ':', ';'])) and 158 (Pos(UContent, UpperCase(Lines[h + i + 1])) > 0) then 192 159 begin 193 160 Index := i; 194 161 Handle := h; 195 result := true;196 exit162 Result := True; 163 Exit; 197 164 end; 198 inc(i);199 until false;165 Inc(I); 166 until False; 200 167 end; 201 168
Note:
See TracChangeset
for help on using the changeset viewer.