Changeset 168 for trunk/Packages/Common/Table.pas
- Timestamp:
- Jul 1, 2023, 8:17:50 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Table.pas
r167 r168 281 281 282 282 procedure TTable.SetInputCsv(Text: string); 283 begin 284 283 var 284 Lines: TStringList; 285 I: Integer; 286 Row: TRow; 287 begin 288 Clear; 289 Lines := TStringList.Create; 290 try 291 Lines.Text := Text; 292 for I := 0 to Lines.Count - 1 do begin 293 if I = 0 then begin 294 Columns.StrictDelimiter := True; 295 Columns.DelimitedText := Trim(Lines[I]); 296 end else begin 297 Row := TRow.Create; 298 Row.Cells.StrictDelimiter := True; 299 Row.Cells.DelimitedText := Trim(Lines[I]); 300 Rows.Add(Row); 301 end; 302 end; 303 finally 304 FreeAndNil(Lines); 305 end; 285 306 end; 286 307 … … 296 317 297 318 procedure TTable.SetInputMediaWiki(Text: string); 298 begin 299 319 var 320 Lines: TStringList; 321 I: Integer; 322 Line: string; 323 InsideTable: Boolean; 324 Index: Integer; 325 Row: TRow; 326 begin 327 Clear; 328 Lines := TStringList.Create; 329 try 330 Lines.Text := Text; 331 Row := nil; 332 InsideTable := False; 333 for I := 0 to Lines.Count - 1 do begin 334 Line := Trim(Lines[I]); 335 if not InsideTable then begin 336 if Line.StartsWith('{|') then InsideTable := True; 337 end else begin 338 if Line.StartsWith('|}') then InsideTable := False 339 else 340 if Line.StartsWith('!') then begin 341 Delete(Line, 1, 1); 342 Line := Trim(Line); 343 repeat 344 Index := Pos('!!', Line); 345 if Index > 0 then begin 346 Columns.Add(Trim(Copy(Line, 1, Index - 1))); 347 Delete(Line, 1, Index + 1); 348 end else begin 349 Columns.Add(Trim(Line)); 350 Break; 351 end; 352 until False; 353 end else 354 if Line.StartsWith('|-') then begin 355 if Assigned(Row) then Rows.Add(Row); 356 Row := TRow.Create; 357 end else 358 if Line.StartsWith('|') then begin 359 if Assigned(Row) then begin 360 Delete(Line, 1, 1); 361 Line := Trim(Line); 362 repeat 363 Index := Pos('||', Line); 364 if Index > 0 then begin 365 Row.Cells.Add(Trim(Copy(Line, 1, Index - 1))); 366 Delete(Line, 1, Index + 1); 367 end else begin 368 Row.Cells.Add(Trim(Line)); 369 Break; 370 end; 371 until False; 372 373 while Row.Cells.Count < Columns.Count do 374 Row.Cells.Add(''); 375 end; 376 end; 377 end; 378 end; 379 if Assigned(Row) then 380 Rows.Add(Row); 381 finally 382 FreeAndNil(Lines); 383 end; 300 384 end; 301 385
Note:
See TracChangeset
for help on using the changeset viewer.