summaryrefslogtreecommitdiff
path: root/src/fmd.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/fmd.adb')
-rw-r--r--src/fmd.adb64
1 files changed, 46 insertions, 18 deletions
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 * ' ') & "<fields>");
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 * ' ') & "<field>" & (-Text) & "</field>");
end loop;
Put_Line (File_Handle, (4 * ' ') & "</fields>");
@@ -73,18 +72,15 @@ package body FMD is
Text : SU.Unbounded_String;
begin
Put_Line (File_Handle, (8 * ' ') & "<pack>");
- 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 * ' ') & "<qst>" & (-Text) & "</qst>");
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 * ' ') & "<!--" & "<qst>" & (-Text) & "</qst>" & "-->");
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 * ' ') & "<ans>" & (-Text) & "</ans>");
end loop;
Put_Line (File_Handle, (8 * ' ') & "</pack>");
@@ -119,8 +115,7 @@ package body FMD is
Put_Line (File_Handle, (8 * ' ') & "<e>");
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 * ' ') & "<f>" & (-Text) & "</f>");
else
Put_Line (File_Handle, (12 * ' ') & "<f></f>");
@@ -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, '<', "&lt;");
- Escape (Text, '>', "&gt;");
- Escape (Text, '"', "&quot;");
- end Standard_Escapes;
+ -- Fresh Memory needs these character codes
+ Replace_All (Result, '<', "&lt;");
+ Replace_All (Result, '>', "&gt;");
+ Replace_All (Result, '"', "&quot;");
+
+ -- Not sure why these cause Fresh Memory to not load the dict
+ -- Replace_All (Result, Latin.CR & Latin.LF, "<br>");
+ -- Replace_All (Result, Latin.LF, "<br>");
+
+ -- Fresh memory doesn't recognise these character codes so get rid of them
+ -- Note that this list may not be complete
+ Replace_All (Result, "&ndash;", "–");
+ Replace_All (Result, "&rsquo;", "’");
+ Replace_All (Result, "&lsquo;", "‘");
+ Replace_All (Result, "&rdquo;", "”");
+ Replace_All (Result, "&ldquo;", "“");
+
+ return Result;
+ end Prep;
end FMD;