X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d3c7fc996a73e9f6a83067bc28a3c5581a3fee65..2ada746fb47bf68c9f2dab6399a6cd5510320984:/utils/tex2rtf/src/htmlutil.cpp diff --git a/utils/tex2rtf/src/htmlutil.cpp b/utils/tex2rtf/src/htmlutil.cpp index de0409e8ce..553a563c87 100644 --- a/utils/tex2rtf/src/htmlutil.cpp +++ b/utils/tex2rtf/src/htmlutil.cpp @@ -28,10 +28,8 @@ #include #define HTML_FILENAME_PATTERN _T("%s_%s.html") -#if !WXWIN_COMPATIBILITY_2_4 static inline wxChar* copystring(const wxChar* s) { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); } -#endif extern wxHashTable TexReferences; @@ -248,6 +246,30 @@ void ReopenSectionContentsFile(void) } + + +struct textreplace +{ + wxChar *text; + size_t text_length; + wxChar *replace; + size_t replace_length; +}; + +#define tr(x,y) {x, sizeof(x)-1, y, sizeof(y)-1} + +static textreplace notverb_array[] = +{ + tr(_T("``"), _T("“")), + tr(_T("''"), _T("”")), + tr(_T("`"), _T("‘")), + tr(_T("'"), _T("’")), + tr(_T("---"), _T("—")), + tr(_T("--"), _T("–")), +}; + +#undef tr + /* * Given a TexChunk with a string value, scans through the string * converting Latex-isms into HTML-isms, such as 2 newlines ->

. @@ -260,38 +282,18 @@ void ProcessText2HTML(TexChunk *chunk) int ptr = 0; int i = 0; wxChar ch = 1; - int len = wxStrlen(chunk->value); + size_t len = wxStrlen(chunk->value); while (ch != 0) { ch = chunk->value[i]; - // 2 newlines means \par - if (!inVerbatim && chunk->value[i] == 10 && ((len > i+1 && chunk->value[i+1] == 10) || - ((len > i+1 && chunk->value[i+1] == 13) && - (len > i+2 && chunk->value[i+2] == 10)))) - { - BigBuffer[ptr] = 0; wxStrcat(BigBuffer, _T("

\n\n")); ptr += 5; - i += 2; - changed = true; - } - else if (!inVerbatim && ch == _T('`') && (len >= i+1 && chunk->value[i+1] == '`')) - { - BigBuffer[ptr] = '"'; ptr ++; - i += 2; - changed = true; - } - else if (!inVerbatim && ch == _T('`')) // Change ` to ' - { - BigBuffer[ptr] = 39; ptr ++; - i += 1; - changed = true; - } - else if (ch == _T('<')) // Change < to < + if (ch == _T('<')) // Change < to < { BigBuffer[ptr] = 0; wxStrcat(BigBuffer, _T("<")); ptr += 4; i += 1; + len--; changed = true; } else if (ch == _T('>')) // Change > to > @@ -300,13 +302,53 @@ void ProcessText2HTML(TexChunk *chunk) wxStrcat(BigBuffer, _T(">")); ptr += 4; i += 1; + len--; changed = true; } else { - BigBuffer[ptr] = ch; - i ++; - ptr ++; + bool replaced = false; + if (!inVerbatim) + { + for (size_t x = 0; x < WXSIZEOF(notverb_array); x++) + { + textreplace& tr = notverb_array[x]; + if (ch != tr.text[0]) + continue; + if (len < tr.text_length) + continue; + + size_t y; + for (y = 1; y < tr.text_length; y++) + { + if (chunk->value[y] != tr.text[y]) + break; + } + + if (y != tr.text_length) + continue; + + // can now copy it over. + for (y = 0; y < tr.replace_length; y++) + { + BigBuffer[ptr++] = tr.replace[y]; + } + + len -= tr.text_length; + i += tr.text_length; + replaced = true; + changed = true; + break; + } + } + + if (!replaced) + { + BigBuffer[ptr] = ch; + i ++; + ptr ++; + len--; + } } } BigBuffer[ptr] = 0; @@ -1835,7 +1877,7 @@ static bool CheckTypeRef() label.Trim(true); label.Trim(false); wxString typeName = label; label.MakeLower(); - TexRef *texRef = FindReference((wxChar*)label.c_str()); + TexRef *texRef = FindReference(label); if (texRef && texRef->refFile && wxStrcmp(texRef->refFile, _T("??")) != 0) { int a = typeDecl.Find(typeName); @@ -2111,7 +2153,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) { wxString errBuf; errBuf.Printf(_T("Warning: unresolved reference '%s'"), refName); - OnInform((wxChar *)errBuf.c_str()); + OnInform(errBuf); } } } @@ -2263,7 +2305,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (f != _T("")) { // The default HTML file to go to is THIS file (so a no-op) - SHGToMap((wxChar *)f.c_str(), currentFileName); + SHGToMap(f, currentFileName); } wxChar *mapName = GetArgData();