texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Patrice Dumas
Date: Wed, 15 Nov 2023 03:37:20 -0500 (EST)

branch: master
commit 2f3d653e295562dc75de9654bee0feda2e497308
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Nov 15 09:34:18 2023 +0100

    * tp/Texinfo/XS/convert/converter.h (OTXI_PROTECT_XML_CASES),
    tp/Texinfo/XS/convert/converter.c
    (xml_format_text_with_numeric_entities, xml_protect_text):
    add code that can be inlined for the protection of XML special
    characters as OTXI_PROTECT_XML_CASES.  Use in converter.c and base
    code more on misc.c code with memcmp and case.
    
    * tp/Texinfo/XS/convert/convert_html.c
    (OTXI_PROTECT_XML_FORM_FEED_CASES, html_default_format_protect_text)
    (protect_text_use_iso_entities, protect_text_no_iso_entities):
    setup OTXI_PROTECT_XML_FORM_FEED_CASES to be inlined for the
    protection of XML special charcters and form feeds.  Implement
    protect_text_use_iso_entities and html_default_format_protect_text.
---
 ChangeLog                            |  30 +++++--
 tp/Texinfo/XS/convert/convert_html.c | 149 +++++++++++++++++++++++++++++++----
 tp/Texinfo/XS/convert/converter.c    |  93 +++++++++++-----------
 tp/Texinfo/XS/convert/converter.h    |  14 ++++
 4 files changed, 218 insertions(+), 68 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0a7210931f..059d8491e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,18 @@
-2023-11-14  Gavin Smith <gavinsmith0123@gmail.com>
+2023-11-15  Patrice Dumas  <pertusus@free.fr>
 
-       * tp/Texinfo/command_data.txt
-       (item_LINE, itemx, defblock, defline, deftypeline):
-       Remove contain_basic_inline flag.  There is no reason an @anchor
-       should not occur inside @item, inside @table, or the other
-       commands, as no index entry is being created with the @anchor.
+       * tp/Texinfo/XS/convert/converter.h (OTXI_PROTECT_XML_CASES),
+       tp/Texinfo/XS/convert/converter.c
+       (xml_format_text_with_numeric_entities, xml_protect_text):
+       add code that can be inlined for the protection of XML special
+       characters as OTXI_PROTECT_XML_CASES.  Use in converter.c and base
+       code more on misc.c code with memcmp and case.
 
-       Report from Ihor Radchenko <yantar92@posteo.net> for Org mode manual.
+       * tp/Texinfo/XS/convert/convert_html.c
+       (OTXI_PROTECT_XML_FORM_FEED_CASES, html_default_format_protect_text)
+       (protect_text_use_iso_entities, protect_text_no_iso_entities):
+       setup OTXI_PROTECT_XML_FORM_FEED_CASES to be inlined for the
+       protection of XML special charcters and form feeds.  Implement
+       protect_text_use_iso_entities and html_default_format_protect_text.
 
 2023-11-14  Patrice Dumas  <pertusus@free.fr>
 
@@ -31,6 +37,16 @@
        * tp/Texinfo/XS/convert/converter.c
        (xml_format_text_with_numeric_entities, xml_protect_text): implement.
 
+2023-11-14  Gavin Smith <gavinsmith0123@gmail.com>
+
+       * tp/Texinfo/command_data.txt
+       (item_LINE, itemx, defblock, defline, deftypeline):
+       Remove contain_basic_inline flag.  There is no reason an @anchor
+       should not occur inside @item, inside @table, or the other
+       commands, as no index entry is being created with the @anchor.
+
+       Report from Ihor Radchenko <yantar92@posteo.net> for Org mode manual.
+
 2023-11-14  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Translations.pm (import), tp/Texinfo/XS/Makefile.am,
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 3f750f7881..958ee64405 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -2220,7 +2220,12 @@ html_prepare_units_directions_files (CONVERTER *self,
 }
 
 
-#define ADDN(str,nr) text_append_n (result, str, nr)
+#define OTXI_PROTECT_XML_FORM_FEED_CASES(var) \
+        OTXI_PROTECT_XML_CASES(var) \
+        case '\f':          \
+          text_append_n (result, "&#12;", 5); var++; \
+          break;
+
 void
 html_default_format_protect_text (const char *text, TEXT *result)
 {
@@ -2238,26 +2243,13 @@ html_default_format_protect_text (const char *text, 
TEXT *result)
         break;
       switch (*p)
         {
-        case '<':
-          ADDN("&lt;", 4);
-          break;
-        case '>':
-          ADDN("&gt;", 4);
-          break;
-        case '&':
-          ADDN("&amp;", 5);
-          break;
-        case '"':
-          ADDN("&quot;", 6);
-          break;
-        case '\f':
-          ADDN("&#12;", 5);
-          break;
+        OTXI_PROTECT_XML_FORM_FEED_CASES(p)
         }
-      p++;
     }
 }
 
+#define ADDN(str,nr) text_append_n (result, str, nr)
+
 void
 default_css_string_format_protect_text (const char *text, TEXT *result)
 {
@@ -2286,6 +2278,129 @@ default_css_string_format_protect_text (const char 
*text, TEXT *result)
     }
 }
 
+void
+protect_text_use_iso_entities (const char *text, TEXT *result)
+{
+  const char *p = text;
+
+  while (*p)
+    {
+      int before_sep_nr = strcspn (p, "<>&\"\f" "-`'");
+      if (before_sep_nr)
+        {
+          text_append_n (result, p, before_sep_nr);
+          p += before_sep_nr;
+        }
+      if (!*p)
+        break;
+      switch (*p)
+        {
+        OTXI_PROTECT_XML_FORM_FEED_CASES(p)
+        case '-':
+          if (*(p+1) && !memcmp (p, "---", 3))
+            {
+              ADDN("&mdash;", 7);
+              p += 3;
+            }
+          else if (!memcmp (p, "--", 2))
+            {
+              ADDN("&ndash;", 7);
+              p += 2;
+            }
+          else
+            {
+              ADDN("-", 1);
+              p++;
+            }
+          break;
+        case '`':
+          if (!memcmp (p, "``", 2))
+            {
+              ADDN("&ldquo;", 7);
+              p += 2;
+            }
+          else
+            {
+              ADDN("&lsquo;", 7);
+              p++;
+            }
+          break;
+        case '\'':
+          if (!memcmp (p, "''", 2))
+            {
+              ADDN("&rdquo;", 7);
+              p += 2;
+            }
+          else
+            {
+              ADDN("&rsquo;", 7);
+              p++;
+            }
+          break;
+        }
+    }
+}
+
+void
+protect_text_no_iso_entities (const char *text, TEXT *result)
+{
+  const char *p = text;
+
+  while (*p)
+    {
+      int before_sep_nr = strcspn (p, "<>&\"\f" "-`'");
+      if (before_sep_nr)
+        {
+          text_append_n (result, p, before_sep_nr);
+          p += before_sep_nr;
+        }
+      if (!*p)
+        break;
+      switch (*p)
+        {
+        OTXI_PROTECT_XML_FORM_FEED_CASES(p)
+        case '-':
+          if (*(p+1) && !memcmp (p, "---", 3))
+            {
+              ADDN("--", 2);
+              p += 3;
+            }
+          else
+            {
+              if (!memcmp (p, "--", 2))
+                p += 2;
+              else
+                p++;
+              ADDN("-", 1);
+            }
+          break;
+        case '`':
+          if (!memcmp (p, "``", 2))
+            {
+              ADDN("&quot;", 6);
+              p += 2;
+            }
+          else
+            {
+              ADDN(p, 1);
+              p++;
+            }
+          break;
+        case '\'':
+          if (!memcmp (p, "''", 2))
+            {
+              ADDN("&quot;", 6);
+              p += 2;
+            }
+          else
+            {
+              ADDN(p, 1);
+              p++;
+            }
+          break;
+        }
+    }
+}
 #undef ADDN
 
 static char *
diff --git a/tp/Texinfo/XS/convert/converter.c 
b/tp/Texinfo/XS/convert/converter.c
index dfe58b34f8..13d9246935 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -589,7 +589,6 @@ void
 xml_format_text_with_numeric_entities (const char *text, TEXT *result)
 {
   const char *p;
-  int str_len;
 
   p = text;
   while (*p)
@@ -602,40 +601,56 @@ xml_format_text_with_numeric_entities (const char *text, 
TEXT *result)
         }
       if (!*p)
         break;
-      str_len = strlen (p);
-      if ((str_len > 1) && (!strncmp (p, "``", 2)))
-        {
-          ADD(8220);
-          p += 2;
-        }
-      else if ((str_len > 1) && (!strncmp (p, "''", 2)))
-        {
-          ADD(8221);
-          p += 2;
-        }
-      else if ((str_len > 2) && !strncmp (p, "---", 3))
-        {
-          ADD(8212);
-          p += 3;
-        }
-      else if ((str_len > 1) && !strncmp (p, "--", 2))
-        {
-          ADD(8211);
-          p += 2;
-        }
-      else
+      switch (*p)
         {
-          if (*p == '\'')
-            ADD(8217);
-          else if (*p == '`')
-            ADD(8216);
-          p++;
+        case '-':
+          if (*(p+1) && !memcmp (p, "---", 3))
+            {
+              ADD(8212);
+              p += 3;
+            }
+          else if (!memcmp (p, "--", 2))
+            {
+              ADD(8211);
+              p += 2;
+            }
+          else
+            {
+              text_append_n (result, "-", 1);
+              p++;
+            }
+          break;
+        case '`':
+          if (!memcmp (p, "``", 2))
+            {
+              ADD(8220);
+              p += 2;
+            }
+          else
+            {
+              ADD(8216);
+              p++;
+            }
+          break;
+        case '\'':
+          if (!memcmp (p, "''", 2))
+            {
+              ADD(8221);
+              p += 2;
+            }
+          else
+            {
+              ADD(8217);
+              p++;
+            }
+          break;
         }
     }
 }
 #undef ADD
 
-#define ADDN(str,nr) text_append_n (result, str, nr)
+
+
 void
 xml_protect_text (const char *text, TEXT *result)
 {
@@ -645,7 +660,7 @@ xml_protect_text (const char *text, TEXT *result)
 
   while (*p)
     {
-      int before_sep_nr = strcspn (p, "<>&\"\f");
+      int before_sep_nr = strcspn (p, "<>&\"");
       if (before_sep_nr)
         {
           text_append_n (result, p, before_sep_nr);
@@ -655,20 +670,10 @@ xml_protect_text (const char *text, TEXT *result)
         break;
       switch (*p)
         {
-        case '<':
-          ADDN("&lt;", 4);
-          break;
-        case '>':
-          ADDN("&gt;", 4);
-          break;
-        case '&':
-          ADDN("&amp;", 5);
-          break;
-        case '"':
-          ADDN("&quot;", 6);
-          break;
+        OTXI_PROTECT_XML_CASES(p);
+        /* should never happen */
+        default:
+         p++;
         }
-      p++;
     }
 }
-#undef ADDN
diff --git a/tp/Texinfo/XS/convert/converter.h 
b/tp/Texinfo/XS/convert/converter.h
index c864784f47..fd878f6fa5 100644
--- a/tp/Texinfo/XS/convert/converter.h
+++ b/tp/Texinfo/XS/convert/converter.h
@@ -10,6 +10,20 @@
 /* for TARGET_FILENAME */
 #include "utils.h"
 
+#define OTXI_PROTECT_XML_CASES(var) \
+        case '<':           \
+          text_append_n(result, "&lt;", 4); var++; \
+          break;            \
+        case '>':           \
+          text_append_n (result, "&gt;", 4); var++; \
+          break;            \
+        case '&':           \
+          text_append_n (result, "&amp;", 5); var++; \
+          break;            \
+        case '"':           \
+          text_append_n (result, "&quot;", 6); var++; \
+          break;
+
 CONVERTER *retrieve_converter (int converter_descriptor);
 size_t register_converter (CONVERTER *converter);
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]