summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/deck_io.adb4
-rw-r--r--src/fmd.adb64
-rw-r--r--src/fmd.ads13
3 files changed, 59 insertions, 22 deletions
diff --git a/src/deck_io.adb b/src/deck_io.adb
index 8a3637e..5207fe7 100644
--- a/src/deck_io.adb
+++ b/src/deck_io.adb
@@ -203,7 +203,9 @@ package body Deck_IO is
is
use type Pat.Match_Location;
Matches : Pat.Match_Array (0 .. 1);
- Regexp : Pat.Pattern_Matcher := Pat.Compile ("{{(?:\w+:)?(\w+)}}", Pat.Single_Line);
+ Regexp : Pat.Pattern_Matcher :=
+ -- My god I hate regular expressions, they're such unreadable nonsense
+ Pat.Compile ("{{(?:(?:\w|\s)+:)?((?:\w|\s)+)}}", Pat.Single_Line);
Marker : Positive := Raw_Data'First;
begin
loop
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;
diff --git a/src/fmd.ads b/src/fmd.ads
index fe720d5..1c64deb 100644
--- a/src/fmd.ads
+++ b/src/fmd.ads
@@ -118,15 +118,22 @@ private
- procedure Escape
+ procedure Replace_All
(Text : in out SU.Unbounded_String;
Char : in Character;
Sub : in String)
with Pre => Ada.Strings.Fixed.Count (Sub, Ada.Strings.Maps.To_Set (Char)) = 0;
- procedure Standard_Escapes
- (Text : in out SU.Unbounded_String);
+ procedure Replace_All
+ (Text : in out SU.Unbounded_String;
+ Item : in String;
+ Sub : in String);
+
+
+ function Prep
+ (Text : in SU.Unbounded_String)
+ return SU.Unbounded_String;
end FMD;