+
+/* Find the first occurrence of the substring "-->" in [BEG, END) and
+ return the pointer to the character after the substring. If the
+ substring is not found, return NULL. */
+
+static const char *
+find_comment_end (const char *beg, const char *end)
+{
+ /* Open-coded Boyer-Moore search for "-->". Examine the third char;
+ if it's not '>' or '-', advance by three characters. Otherwise,
+ look at the preceding characters and try to find a match. */
+
+ const char *p = beg - 1;
+
+ while ((p += 3) < end)
+ switch (p[0])
+ {
+ case '>':
+ if (p[-1] == '-' && p[-2] == '-')
+ return p + 1;
+ break;
+ case '-':
+ at_dash:
+ if (p[-1] == '-')
+ {
+ at_dash_dash:
+ if (++p == end) return NULL;
+ switch (p[0])
+ {
+ case '>': return p + 1;
+ case '-': goto at_dash_dash;
+ }
+ }
+ else
+ {
+ if ((p += 2) >= end) return NULL;
+ switch (p[0])
+ {
+ case '>':
+ if (p[-1] == '-')
+ return p + 1;
+ break;
+ case '-':
+ goto at_dash;
+ }
+ }
+ }
+ return NULL;
+}