summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitri van Heesch <doxygen@gmail.com>2019-12-22 20:44:19 (GMT)
committerDimitri van Heesch <doxygen@gmail.com>2019-12-22 20:44:19 (GMT)
commit5c5d546a393e68203ab853a99575d643672655cc (patch)
tree9246800163035b525cc0ded606c0ce57a1dfdf23
parent0bf44109f64f7a6cec82d03a1f97779a51f0fdda (diff)
downloadDoxygen-5c5d546a393e68203ab853a99575d643672655cc.zip
Doxygen-5c5d546a393e68203ab853a99575d643672655cc.tar.gz
Doxygen-5c5d546a393e68203ab853a99575d643672655cc.tar.bz2
Optimize UTF-8 nbsp conversion in markdown
-rw-r--r--src/markdown.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/markdown.cpp b/src/markdown.cpp
index d63492e..0a71aae 100644
--- a/src/markdown.cpp
+++ b/src/markdown.cpp
@@ -108,8 +108,8 @@ static Entry *g_current;
static QCString g_fileName;
static int g_lineNr;
static int g_indentLevel=0; // 0 is outside markdown, -1=page level
-static char g_doxynbsputf8[3] = {'\xc2', '\xa0', '\0'}; // UTF-8 nbsp
-static char *g_doxynbsp = "&_doxy_nbsp;";
+static const char g_utf8_nbsp[3] = {'\xc2', '\xa0', '\0'}; // UTF-8 nbsp
+static const char *g_doxy_nsbp = "&_doxy_nbsp;"; // doxygen escape command for UTF-8 nbsp
//----------
const int codeBlockIndent = 4;
@@ -1029,6 +1029,17 @@ static int processCodeSpan(GrowBuf &out, const char *data, int /*offset*/, int s
return end;
}
+static void addStrEscapeUtf8Nbsp(GrowBuf &out,const char *s,int len)
+{
+ if (strnstr(s,g_doxy_nsbp,len)==0) // no escape needed -> fast
+ {
+ out.addStr(s,len);
+ }
+ else // escape needed -> slow
+ {
+ out.addStr(substitute(QCString(s).left(len),g_doxy_nsbp,g_utf8_nbsp));
+ }
+}
static int processSpecialCommand(GrowBuf &out, const char *data, int offset, int size)
{
@@ -1045,7 +1056,7 @@ static int processSpecialCommand(GrowBuf &out, const char *data, int offset, int
if (qstrncmp(&data[i+1],endBlockName,l)==0)
{
//printf("found end at %d\n",i);
- out.addStr(substitute(QCString(data).left(i+1+l),g_doxynbsp,g_doxynbsputf8));
+ addStrEscapeUtf8Nbsp(out,data,i+1+l);
return i+1+l;
}
}
@@ -2175,7 +2186,7 @@ static void writeFencedCodeBlock(GrowBuf &out,const char *data,const char *lng,
{
out.addStr("{"+lang+"}");
}
- out.addStr(substitute(QCString(data+blockStart).left(blockEnd-blockStart),g_doxynbsp,g_doxynbsputf8));
+ addStrEscapeUtf8Nbsp(out,data+blockStart,blockEnd-blockStart);
out.addStr("\n");
out.addStr("@endcode\n");
}
@@ -2485,7 +2496,7 @@ static QCString detab(const QCString &s,int &refIndent)
// special handling of the UTF-8 nbsp character 0xc2 0xa0
if (c == '\xc2' && data[i] == '\xa0')
{
- out.addStr(g_doxynbsp);
+ out.addStr(g_doxy_nsbp);
i++;
}
else
@@ -2562,7 +2573,7 @@ QCString processMarkdown(const QCString &fileName,const int lineNr,Entry *e,cons
processInline(out,s,s.length());
out.addChar(0);
Debug::print(Debug::Markdown,0,"======== Markdown =========\n---- input ------- \n%s\n---- output -----\n%s\n=========\n",qPrint(input),qPrint(out.get()));
- return substitute(out.get(),g_doxynbsp,"&nbsp;");
+ return substitute(out.get(),g_doxy_nsbp,"&nbsp;");
}
//---------------------------------------------------------------------------