From 340e2c4c51d4b933269cff7d085c09ceb145631e Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Thu, 4 Nov 2021 18:15:08 +1300 Subject: Fixed HTML character encoding, question/answer format field parsing --- src/fmd.adb | 64 ++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 18 deletions(-) (limited to 'src/fmd.adb') diff --git a/src/fmd.adb b/src/fmd.adb index ae11660..8d8fcde 100644 --- a/src/fmd.adb +++ b/src/fmd.adb @@ -48,8 +48,7 @@ package body FMD is begin Put_Line (File_Handle, (4 * ' ') & ""); for FID of Field_IDs loop - Text := To_Unbounded_String (FID); - Standard_Escapes (Text); + Text := Prep (To_Unbounded_String (FID)); Put_Line (File_Handle, (8 * ' ') & "" & (-Text) & ""); end loop; Put_Line (File_Handle, (4 * ' ') & ""); @@ -73,18 +72,15 @@ package body FMD is Text : SU.Unbounded_String; begin Put_Line (File_Handle, (8 * ' ') & ""); - Text := To_Unbounded_String (Q_Data.First_Element); - Standard_Escapes (Text); + Text := Prep (To_Unbounded_String (Q_Data.First_Element)); Put_Line (File_Handle, (12 * ' ') & "" & (-Text) & ""); for I in Vector_Index range Vector_Index'Succ (Q_Data.First_Index) .. Q_Data.Last_Index loop - Text := To_Unbounded_String (Q_Data.Element (I)); - Standard_Escapes (Text); + Text := Prep (To_Unbounded_String (Q_Data.Element (I))); -- Fresh Memory unfortunately cannot cope with multiple question fields Put_Line (File_Handle, (12 * ' ') & ""); end loop; for FID of A_Data loop - Text := To_Unbounded_String (FID); - Standard_Escapes (Text); + Text := Prep (To_Unbounded_String (FID)); Put_Line (File_Handle, (12 * ' ') & "" & (-Text) & ""); end loop; Put_Line (File_Handle, (8 * ' ') & ""); @@ -119,8 +115,7 @@ package body FMD is Put_Line (File_Handle, (8 * ' ') & ""); while Counter <= Quantity loop if Position <= Data.Last_Index then - Text := To_Unbounded_String (Data.Element (Position)); - Standard_Escapes (Text); + Text := Prep (To_Unbounded_String (Data.Element (Position))); Put_Line (File_Handle, (12 * ' ') & "" & (-Text) & ""); else Put_Line (File_Handle, (12 * ' ') & ""); @@ -150,7 +145,7 @@ package body FMD is - procedure Escape + procedure Replace_All (Text : in out SU.Unbounded_String; Char : in Character; Sub : in String) @@ -162,16 +157,49 @@ package body FMD is exit when Position = 0; SU.Replace_Slice (Text, Position, Position, Sub); end loop; - end Escape; + end Replace_All; - procedure Standard_Escapes - (Text : in out SU.Unbounded_String) is + procedure Replace_All + (Text : in out SU.Unbounded_String; + Item : in String; + Sub : in String) + is + Position : Natural; + begin + loop + Position := SU.Index (Text, Item); + exit when Position = 0; + SU.Replace_Slice (Text, Position, Position + Sub'Length - 1, Sub); + end loop; + end Replace_All; + + + function Prep + (Text : in SU.Unbounded_String) + return SU.Unbounded_String + is + Result : SU.Unbounded_String := Text; begin - Escape (Text, '<', "<"); - Escape (Text, '>', ">"); - Escape (Text, '"', """); - end Standard_Escapes; + -- Fresh Memory needs these character codes + Replace_All (Result, '<', "<"); + Replace_All (Result, '>', ">"); + Replace_All (Result, '"', """); + + -- Not sure why these cause Fresh Memory to not load the dict + -- Replace_All (Result, Latin.CR & Latin.LF, "
"); + -- Replace_All (Result, Latin.LF, "
"); + + -- Fresh memory doesn't recognise these character codes so get rid of them + -- Note that this list may not be complete + Replace_All (Result, "–", "–"); + Replace_All (Result, "’", "’"); + Replace_All (Result, "‘", "‘"); + Replace_All (Result, "”", "”"); + Replace_All (Result, "“", "“"); + + return Result; + end Prep; end FMD; -- cgit