Changeset 233 for trunk/Forms/FormCheck.pas
- Timestamp:
- Jan 25, 2025, 9:19:23 PM (7 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/FormCheck.pas
r227 r233 151 151 Line.Clear; 152 152 for I := 0 to Count - 1 do 153 with TReportItem(Items[I])do begin153 with Items[I] do begin 154 154 Line.Clear; 155 155 if Position <> Point(0, 0) then … … 367 367 // These are usually first level chapter titles or first page text 368 368 Lines := TStringList.Create; 369 Lines.Assign(MemoDocument.Lines); 370 for I := 0 to Lines.Count - 1 do begin 371 HasLowerCase := False; 372 HasUpperCase := False; 373 Line := Lines[I]; 374 for J := 1 to Length(Line) do begin 375 if IsUppercaseAlpha(Line[J]) then HasUpperCase := True; 376 if IsLowercaseAlpha(Line[J]) then HasLowerCase := True; 377 end; 378 if HasUpperCase and not HasLowerCase then 379 Lines[I] := LowerCase(Lines[I]); 380 end; 381 382 // Find acronyms usage in text 383 Text := Lines.Text; 384 Text := StringReplace(Text, #9, ' ', [rfReplaceAll]); 385 Text := StringReplace(Text, LineEnding, ' ', [rfReplaceAll]); 386 Index := 1; 387 AcronymCharBefore := ' '; 388 AcronymCharAfter := ' '; 389 State := stNone; 390 StartIndex := 0; 391 Acronym := ''; 392 repeat 393 if State = stAcronymUsage then begin 394 if not IsUppercaseAlpha(Text[Index]) then begin 395 if Text[Index] = 's' then begin 369 try 370 Lines.Assign(MemoDocument.Lines); 371 for I := 0 to Lines.Count - 1 do begin 372 HasLowerCase := False; 373 HasUpperCase := False; 374 Line := Lines[I]; 375 for J := 1 to Length(Line) do begin 376 if IsUppercaseAlpha(Line[J]) then HasUpperCase := True; 377 if IsLowercaseAlpha(Line[J]) then HasLowerCase := True; 378 end; 379 if HasUpperCase and not HasLowerCase then 380 Lines[I] := LowerCase(Lines[I]); 381 end; 382 383 // Find acronyms usage in text 384 Text := Lines.Text; 385 Text := StringReplace(Text, #9, ' ', [rfReplaceAll]); 386 Text := StringReplace(Text, LineEnding, ' ', [rfReplaceAll]); 387 Index := 1; 388 AcronymCharBefore := ' '; 389 AcronymCharAfter := ' '; 390 State := stNone; 391 StartIndex := 0; 392 Acronym := ''; 393 if Length(Text) = 0 then Exit; 394 repeat 395 if State = stAcronymUsage then begin 396 if not IsUppercaseAlpha(Text[Index]) then begin 397 if Text[Index] = 's' then begin 398 Acronym := Acronym + Text[Index]; 399 Inc(Index); 400 end; 401 if (Index) < Length(Text) then AcronymCharAfter := Text[Index] 402 else AcronymCharAfter := ' '; 403 State := stNone; 404 405 // Allow plural acronyms with ending 's' character 406 if (Length(Acronym) >= 1) and (Acronym[Length(Acronym)] = 's') then begin 407 Acronym := Copy(Acronym, 1, Length(Acronym) - 1); 408 Plural := True; 409 end else Plural := False; 410 411 // Acronyms should not contain numbers 412 if (Length(Acronym) >= MinAcronymLength) and 413 AllowedSideChar(AcronymCharBefore, AcronymCharAfter) then begin 414 // If plural acronym then try to remove ending 's' character from the meaning 415 if Plural then ReportItems.AddNew(Format(SPluralAcronymUsed, [Acronym]), Point(0, 0), rtNote); 416 417 Acro := AcronymDbContent.Acronyms.SearchByName(Acronym); 418 if not Assigned(Acro) then begin 419 ReportItems.AddNew(Format(SAcronymUsedBeforeDefined, [Acronym]), Point(0, 0), rtNote); 420 AcronymDbContent.AddAcronym(Acronym, ''); 421 end; 422 end; 423 end else Acronym := Acronym + Text[Index]; 424 end else 425 if State = stAcronymDefinition then begin 426 if Text[Index] = ')' then begin 427 // Allow plural acronyms with ending 's' character 428 if (Length(Acronym) >= 1) and (Acronym[Length(Acronym)] = 's') then begin 429 Acronym := Copy(Acronym, 1, Length(Acronym) - 1); 430 Plural := True; 431 end else Plural := False; 432 if IsAcronym(Acronym) then begin 433 HasMeaning1 := ParseMeaning(Acronym, Text, StartIndex - 1, Meaning1); 434 if HasMeaning1 then Meaning := Meaning1; 435 HasMeaning2 := ParseMeaning(Acronym, Text, StartIndex - 1, Meaning2, True); 436 if HasMeaning2 then Meaning := Meaning2; 437 if HasMeaning1 and HasMeaning2 then begin 438 if Length(Meaning1) > Length(Meaning2) then Meaning := Meaning1 439 else Meaning := Meaning2; 440 end; 441 if HasMeaning1 or HasMeaning2 then begin 442 // If plural acronym then try to remove ending 's' character from the meaning 443 if Plural then ReportItems.AddNew(Format(SPluralAcronym, [Acronym]), Point(0, 0), rtNote); 444 if Plural and (Length(Meaning) >= 1) and (Meaning[Length(Meaning)] = 's') then begin 445 Meaning := Copy(Meaning, 1, Length(Meaning) - 1); 446 end; 447 if Assigned(AcronymDbContent.SearchAcronym(Acronym, Meaning)) then 448 ReportItems.AddNew(Format(SDuplicateAcronymContent, [Acronym, Meaning]), Point(0, 0), rtWarning) 449 else AcronymDbContent.AddAcronym(Acronym, Meaning); 450 end; 451 end else 452 // No acronym inside parenthesis, continue with parsing inside 453 Index := StartIndex + 1; 454 State := stNone; 455 end else begin 396 456 Acronym := Acronym + Text[Index]; 397 Inc(Index);398 457 end; 399 if (Index) < Length(Text) then AcronymCharAfter := Text[Index] 400 else AcronymCharAfter := ' '; 401 State := stNone; 402 403 // Allow plural acronyms with ending 's' character 404 if (Length(Acronym) >= 1) and (Acronym[Length(Acronym)] = 's') then begin 405 Acronym := Copy(Acronym, 1, Length(Acronym) - 1); 406 Plural := True; 407 end else Plural := False; 408 409 // Acronyms should not contain numbers 410 if (Length(Acronym) >= MinAcronymLength) and 411 AllowedSideChar(AcronymCharBefore, AcronymCharAfter) then begin 412 // If plural acronym then try to remove ending 's' character from the meaning 413 if Plural then ReportItems.AddNew(Format(SPluralAcronymUsed, [Acronym]), Point(0, 0), rtNote); 414 415 Acro := AcronymDbContent.Acronyms.SearchByName(Acronym); 416 if not Assigned(Acro) then begin 417 ReportItems.AddNew(Format(SAcronymUsedBeforeDefined, [Acronym]), Point(0, 0), rtNote); 418 AcronymDbContent.AddAcronym(Acronym, ''); 419 end; 458 end else begin 459 if Text[Index] = '(' then begin 460 State := stAcronymDefinition; 461 Acronym := ''; 462 StartIndex := Index; 463 end else 464 if IsUppercaseAlpha(Text[Index]) then begin 465 State := stAcronymUsage; 466 Acronym := Text[Index]; 467 if (Index - 1) >= 1 then AcronymCharBefore := Text[Index - 1] 468 else AcronymCharBefore := ' '; 420 469 end; 421 end else Acronym := Acronym + Text[Index];422 end else423 if State = stAcronymDefinition then begin424 if Text[Index] = ')' then begin425 // Allow plural acronyms with ending 's' character426 if (Length(Acronym) >= 1) and (Acronym[Length(Acronym)] = 's') then begin427 Acronym := Copy(Acronym, 1, Length(Acronym) - 1);428 Plural := True;429 end else Plural := False;430 if IsAcronym(Acronym) then begin431 HasMeaning1 := ParseMeaning(Acronym, Text, StartIndex - 1, Meaning1);432 if HasMeaning1 then Meaning := Meaning1;433 HasMeaning2 := ParseMeaning(Acronym, Text, StartIndex - 1, Meaning2, True);434 if HasMeaning2 then Meaning := Meaning2;435 if HasMeaning1 and HasMeaning2 then begin436 if Length(Meaning1) > Length(Meaning2) then Meaning := Meaning1437 else Meaning := Meaning2;438 end;439 if HasMeaning1 or HasMeaning2 then begin440 // If plural acronym then try to remove ending 's' character from the meaning441 if Plural then ReportItems.AddNew(Format(SPluralAcronym, [Acronym]), Point(0, 0), rtNote);442 if Plural and (Length(Meaning) >= 1) and (Meaning[Length(Meaning)] = 's') then begin443 Meaning := Copy(Meaning, 1, Length(Meaning) - 1);444 end;445 if Assigned(AcronymDbContent.SearchAcronym(Acronym, Meaning)) then446 ReportItems.AddNew(Format(SDuplicateAcronymContent, [Acronym, Meaning]), Point(0, 0), rtWarning)447 else AcronymDbContent.AddAcronym(Acronym, Meaning);448 end;449 end else450 // No acronym inside parenthesis, continue with parsing inside451 Index := StartIndex + 1;452 State := stNone;453 end else begin454 Acronym := Acronym + Text[Index];455 470 end; 456 end else begin 457 if Text[Index] = '(' then begin 458 State := stAcronymDefinition; 459 Acronym := ''; 460 StartIndex := Index; 461 end else 462 if IsUppercaseAlpha(Text[Index]) then begin 463 State := stAcronymUsage; 464 Acronym := Text[Index]; 465 if (Index - 1) >= 1 then AcronymCharBefore := Text[Index - 1] 466 else AcronymCharBefore := ' '; 467 end; 468 end; 469 Inc(Index); 470 until Index > Length(Text); 471 Lines.Free; 471 Inc(Index); 472 until Index > Length(Text); 473 finally 474 Lines.Free; 475 end; 472 476 end; 473 477 … … 625 629 // In content but not in summary 626 630 for I := 0 to AcronymDbContent.Acronyms.Count - 1 do begin 627 Acronym := TAcronym(AcronymDbContent.Acronyms[I]);631 Acronym := AcronymDbContent.Acronyms[I]; 628 632 if Acronym.Meanings.Count > 1 then 629 633 ReportItems.AddNew(Format(SAcronymContentMultipleMeanings, [Acronym.Name, … … 632 636 if not Assigned(Acronym2) then 633 637 for J := 0 to Acronym.Meanings.Count - 1 do begin 634 Meaning := TAcronymMeaning(Acronym.Meanings[J]);638 Meaning := Acronym.Meanings[J]; 635 639 if not Assigned(AcronymDbSummary.SearchAcronym(Acronym.Name, Meaning.Name, [sfCaseInsensitive])) then 636 640 ReportItems.AddNew(Format(SMissingAcronymContent, [Acronym.Name, Meaning.Name]), Point(0, 0), rtWarning); … … 640 644 // In summary but not in content 641 645 for I := 0 to AcronymDbSummary.Acronyms.Count - 1 do begin 642 Acronym := TAcronym(AcronymDbSummary.Acronyms[I]);646 Acronym := AcronymDbSummary.Acronyms[I]; 643 647 if Acronym.Meanings.Count > 1 then 644 648 ReportItems.AddNew(Format(SAcronymSummaryMultipleMeanings, [Acronym.Name, Acronym.Meanings.GetNames]), Point(0, 0), rtWarning); … … 646 650 if not Assigned(Acronym2) then 647 651 for J := 0 to Acronym.Meanings.Count - 1 do begin 648 Meaning := TAcronymMeaning(Acronym.Meanings[J]);652 Meaning := Acronym.Meanings[J]; 649 653 if not Assigned(AcronymDbContent.SearchAcronym(Acronym.Name, Meaning.Name, [sfCaseInsensitive])) then 650 654 ReportItems.AddNew(Format(SMissingAcronymSummary, [Acronym.Name, Meaning.Name]), Point(0, 0), rtWarning); … … 654 658 // With different meaning 655 659 for I := 0 to AcronymDbSummary.Acronyms.Count - 1 do begin 656 Acronym := TAcronym(AcronymDbSummary.Acronyms[I]);660 Acronym := AcronymDbSummary.Acronyms[I]; 657 661 Acronym2 := AcronymDbContent.Acronyms.SearchByName(Acronym.Name); 658 662 if Assigned(Acronym2) then begin 659 663 if (Acronym.Meanings.Count = 1) and (Acronym2.Meanings.Count = 1) then begin 660 Meaning := TAcronymMeaning(Acronym.Meanings[0]);661 Meaning2 := TAcronymMeaning(Acronym2.Meanings[0]);664 Meaning := Acronym.Meanings[0]; 665 Meaning2 := Acronym2.Meanings[0]; 662 666 if not StringEqual(Meaning.Name, Meaning2.Name) then 663 667 ReportItems.AddNew(Format(SAcronymWithDifferentMeaning, [Acronym.Name, Meaning2.Name, Meaning.Name]), Point(0, 0), rtWarning);
Note:
See TracChangeset
for help on using the changeset viewer.