2000-01-11 04:56:25 +03:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
1999-12-05 19:56:04 +03:00
|
|
|
*
|
|
|
|
* The "License" shall be the Mozilla Public License Version 1.1, except
|
|
|
|
* Sections 6.2 and 11, but with the addition of the below defined Section 14.
|
|
|
|
* You may obtain a copy of the Mozilla Public License Version 1.1 at
|
|
|
|
* <http://www.mozilla.org/MPL/>. The contents of this file are subject to the
|
|
|
|
* License; you may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* Section 14: MISCELLANEOUS.
|
|
|
|
* This License represents the complete agreement concerning subject matter
|
|
|
|
* hereof. If any provision of this License is held to be unenforceable, such
|
|
|
|
* provision shall be reformed only to the extent necessary to make it
|
|
|
|
* enforceable. This License shall be governed by German law provisions. Any
|
|
|
|
* litigation relating to this License shall be subject to German jurisdiction.
|
|
|
|
*
|
|
|
|
* Once Covered Code has been published under a particular version of the
|
|
|
|
* License, You may always continue to use it under the terms of that version.
|
|
|
|
+ The Initial Developer and no one else has the right to modify the terms
|
|
|
|
* applicable to Covered Code created under this License.
|
|
|
|
* (End of Section 14)
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS"
|
|
|
|
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing rights and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
2001-02-05 13:25:00 +03:00
|
|
|
* The Original Code is the Mozilla Text to HTML converter code.
|
1999-12-05 19:56:04 +03:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Ben Bucksch
|
|
|
|
* <http://www.bucksch.org>. Portions created by Ben Bucksch are Copyright
|
2000-03-03 09:49:23 +03:00
|
|
|
* (C) 1999, 2000 Ben Bucksch. All Rights Reserved.
|
1999-12-05 19:56:04 +03:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mozTXTToHTMLConv.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
|
|
|
|
|
|
|
#ifdef DEBUG_BenB_Perf
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "prinrval.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const PRFloat64 growthRate = 1.2;
|
|
|
|
|
|
|
|
// Escape Char will take ch, escape it and append the result to
|
|
|
|
// aStringToAppendTo
|
|
|
|
void
|
|
|
|
mozTXTToHTMLConv::EscapeChar(const PRUnichar ch, nsString& aStringToAppendTo)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case '<':
|
2000-04-02 13:10:15 +04:00
|
|
|
aStringToAppendTo.AppendWithConversion("<");
|
2000-03-03 09:49:23 +03:00
|
|
|
break;
|
1999-12-05 19:56:04 +03:00
|
|
|
case '>':
|
2000-04-02 13:10:15 +04:00
|
|
|
aStringToAppendTo.AppendWithConversion(">");
|
2000-03-03 09:49:23 +03:00
|
|
|
break;
|
1999-12-05 19:56:04 +03:00
|
|
|
case '&':
|
2000-04-02 13:10:15 +04:00
|
|
|
aStringToAppendTo.AppendWithConversion("&");
|
2000-03-03 09:49:23 +03:00
|
|
|
break;
|
1999-12-05 19:56:04 +03:00
|
|
|
default:
|
2000-03-03 09:49:23 +03:00
|
|
|
aStringToAppendTo += ch;
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
2000-03-03 09:49:23 +03:00
|
|
|
|
|
|
|
return;
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
// EscapeStr takes the passed in string and
|
|
|
|
// escapes it IN PLACE.
|
|
|
|
void
|
|
|
|
mozTXTToHTMLConv::EscapeStr(nsString& aInString)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
// the replace substring routines
|
|
|
|
// don't seem to work if you have a character
|
|
|
|
// in the in string that is also in the replacement
|
|
|
|
// string! =(
|
|
|
|
//aInString.ReplaceSubstring("&", "&");
|
|
|
|
//aInString.ReplaceSubstring("<", "<");
|
|
|
|
//aInString.ReplaceSubstring(">", ">");
|
2000-05-17 08:22:49 +04:00
|
|
|
for (PRUint32 i = 0; i < aInString.Length();)
|
2000-03-03 09:49:23 +03:00
|
|
|
{
|
|
|
|
switch (aInString[i])
|
|
|
|
{
|
|
|
|
case '<':
|
|
|
|
aInString.Cut(i, 1);
|
2000-04-02 13:10:15 +04:00
|
|
|
aInString.InsertWithConversion("<", i, 4);
|
2000-03-03 09:49:23 +03:00
|
|
|
i += 4; // skip past the integers we just added
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
aInString.Cut(i, 1);
|
2000-04-02 13:10:15 +04:00
|
|
|
aInString.InsertWithConversion(">", i, 4);
|
2000-03-03 09:49:23 +03:00
|
|
|
i += 4; // skip past the integers we just added
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
aInString.Cut(i, 1);
|
2000-04-02 13:10:15 +04:00
|
|
|
aInString.InsertWithConversion("&", i, 5);
|
2000-03-03 09:49:23 +03:00
|
|
|
i += 5; // skip past the integers we just added
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
void
|
|
|
|
mozTXTToHTMLConv::UnescapeStr(const PRUnichar * aInString, PRInt32 aStartPos, PRInt32 aLength, nsString& aOutString)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
const PRUnichar * subString = nsnull;
|
2000-03-03 23:38:59 +03:00
|
|
|
for (PRUint32 i = aStartPos; PRInt32(i) - aStartPos < aLength;)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 23:38:59 +03:00
|
|
|
PRInt32 remainingChars = i - aStartPos;
|
2000-03-03 09:49:23 +03:00
|
|
|
if (aInString[i] == '&')
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
subString = &aInString[i];
|
2000-03-03 23:38:59 +03:00
|
|
|
if (!nsCRT::strncmp(subString, "<", MinInt(4, aLength - remainingChars)))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-04-15 13:16:58 +04:00
|
|
|
aOutString.AppendWithConversion('<');
|
1999-12-05 19:56:04 +03:00
|
|
|
i += 4;
|
|
|
|
}
|
2000-03-03 23:38:59 +03:00
|
|
|
else if (!nsCRT::strncmp(subString, ">", MinInt(4, aLength - remainingChars)))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-04-15 13:16:58 +04:00
|
|
|
aOutString.AppendWithConversion('>');
|
1999-12-05 19:56:04 +03:00
|
|
|
i += 4;
|
|
|
|
}
|
2000-03-03 23:38:59 +03:00
|
|
|
else if (!nsCRT::strncmp(subString, "&", MinInt(5, aLength - remainingChars)))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-04-15 13:16:58 +04:00
|
|
|
aOutString.AppendWithConversion('&');
|
1999-12-05 19:56:04 +03:00
|
|
|
i += 5;
|
|
|
|
}
|
1999-12-21 18:23:24 +03:00
|
|
|
else
|
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
aOutString += aInString[i];
|
1999-12-21 18:23:24 +03:00
|
|
|
i++;
|
|
|
|
}
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
aOutString += aInString[i];
|
1999-12-05 19:56:04 +03:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
void
|
|
|
|
mozTXTToHTMLConv::CompleteAbbreviatedURL(const PRUnichar * aInString, PRInt32 aInLength,
|
|
|
|
const PRUint32 pos, nsString& aOutString)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
if (aInString[pos] == '@')
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-04-02 13:10:15 +04:00
|
|
|
aOutString.AssignWithConversion("mailto:");
|
2000-03-03 09:49:23 +03:00
|
|
|
aOutString += aInString;
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
2000-03-03 09:49:23 +03:00
|
|
|
else if (aInString[pos] == '.')
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
if (ItMatchesDelimited(aInString, aInLength, "www.", 4, LT_IGNORE, LT_IGNORE))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-04-02 13:10:15 +04:00
|
|
|
aOutString.AssignWithConversion("http://");
|
2000-03-03 09:49:23 +03:00
|
|
|
aOutString += aInString;
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
2000-03-03 09:49:23 +03:00
|
|
|
else if (ItMatchesDelimited(aInString,aInLength, "ftp.", 4, LT_IGNORE, LT_IGNORE))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-04-02 13:10:15 +04:00
|
|
|
aOutString.AssignWithConversion("ftp://");
|
2000-03-03 09:49:23 +03:00
|
|
|
aOutString += aInString;
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2000-06-17 01:20:13 +04:00
|
|
|
mozTXTToHTMLConv::FindURLStart(const PRUnichar * aInString, PRInt32 aInLength,
|
|
|
|
const PRUint32 pos, const modetype check,
|
|
|
|
PRUint32& start)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
switch(check)
|
|
|
|
{ // no breaks, because end of blocks is never reached
|
|
|
|
case RFC1738:
|
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
if (!nsCRT::strncmp(&aInString[MaxInt(pos - 4, 0)], "<URL:", 5))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
start = pos + 1;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
case RFC2396E:
|
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
nsString temp (nsSubsumeStr( (PRUnichar *) aInString, PR_FALSE, aInLength));
|
2000-06-17 01:20:13 +04:00
|
|
|
PRInt32 i = pos <= 0 ? kNotFound : temp.RFindCharInSet("<>\"", pos - 1);
|
|
|
|
if (i != kNotFound && (temp[PRUint32(i)] == '<' ||
|
|
|
|
temp[PRUint32(i)] == '"'))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
start = PRUint32(++i);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
case freetext:
|
|
|
|
{
|
|
|
|
PRInt32 i = pos - 1;
|
|
|
|
for (; i >= 0 && (
|
2000-03-12 12:14:14 +03:00
|
|
|
nsCRT::IsAsciiAlpha(aInString[PRUint32(i)]) ||
|
|
|
|
nsCRT::IsAsciiDigit(aInString[PRUint32(i)]) ||
|
2000-03-03 09:49:23 +03:00
|
|
|
aInString[PRUint32(i)] == '+' ||
|
|
|
|
aInString[PRUint32(i)] == '-' ||
|
|
|
|
aInString[PRUint32(i)] == '.'
|
1999-12-05 19:56:04 +03:00
|
|
|
); i--)
|
|
|
|
;
|
2000-06-17 01:20:13 +04:00
|
|
|
if (++i >= 0 && nsCRT::IsAsciiAlpha(aInString[PRUint32(i)]))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
start = PRUint32(i);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
case abbreviated:
|
|
|
|
{
|
2000-06-17 01:20:13 +04:00
|
|
|
PRInt32 i = pos - 1;
|
1999-12-05 19:56:04 +03:00
|
|
|
for (; i >= 0
|
2000-03-03 09:49:23 +03:00
|
|
|
&& aInString[PRUint32(i)] != '>' && aInString[PRUint32(i)] != '<'
|
|
|
|
&& aInString[PRUint32(i)] != '"' && aInString[PRUint32(i)] != '\''
|
|
|
|
&& aInString[PRUint32(i)] != '`' && aInString[PRUint32(i)] != ','
|
|
|
|
&& aInString[PRUint32(i)] != '{' && aInString[PRUint32(i)] != '['
|
|
|
|
&& aInString[PRUint32(i)] != '(' && aInString[PRUint32(i)] != '|'
|
|
|
|
&& aInString[PRUint32(i)] != '\\'
|
2000-03-12 12:14:14 +03:00
|
|
|
&& !nsCRT::IsAsciiSpace(aInString[PRUint32(i)])
|
1999-12-05 19:56:04 +03:00
|
|
|
; i--)
|
|
|
|
;
|
2000-01-11 04:56:25 +03:00
|
|
|
if
|
|
|
|
(
|
2000-06-17 01:20:13 +04:00
|
|
|
++i >= 0
|
|
|
|
&&
|
|
|
|
(
|
|
|
|
nsCRT::IsAsciiAlpha(aInString[PRUint32(i)]) ||
|
|
|
|
nsCRT::IsAsciiDigit(aInString[PRUint32(i)])
|
|
|
|
)
|
2000-01-11 04:56:25 +03:00
|
|
|
)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-01-11 04:56:25 +03:00
|
|
|
start = PRUint32(i);
|
1999-12-05 19:56:04 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return PR_FALSE;
|
|
|
|
} //switch
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2000-03-03 09:49:23 +03:00
|
|
|
mozTXTToHTMLConv::FindURLEnd(const PRUnichar * aInString, PRInt32 aInStringLength, const PRUint32 pos,
|
1999-12-05 19:56:04 +03:00
|
|
|
const modetype check, const PRUint32 start, PRUint32& end)
|
|
|
|
{
|
|
|
|
switch(check)
|
|
|
|
{ // no breaks, because end of blocks is never reached
|
|
|
|
case RFC1738:
|
|
|
|
case RFC2396E:
|
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
nsString temp (nsSubsumeStr( (PRUnichar *) aInString, PR_FALSE, aInStringLength));
|
|
|
|
|
|
|
|
PRInt32 i = temp.FindCharInSet("<>\"", pos + 1);
|
|
|
|
if (i != kNotFound && temp[PRUint32(i--)] ==
|
|
|
|
(check == RFC1738 || temp[start - 1] == '<' ? '>' : '"'))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
end = PRUint32(i);
|
1999-12-05 19:56:04 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
case freetext:
|
|
|
|
case abbreviated:
|
|
|
|
{
|
|
|
|
PRUint32 i = pos + 1;
|
2000-03-03 09:49:23 +03:00
|
|
|
for (; PRInt32(i) < aInStringLength
|
|
|
|
&& aInString[i] != '>' && aInString[i] != '<'
|
|
|
|
&& aInString[i] != '"' && aInString[i] != '\''
|
|
|
|
&& aInString[i] != '`'
|
|
|
|
&& aInString[i] != '}' && aInString[i] != ']'
|
|
|
|
&& aInString[i] != ')' && aInString[i] != '|'
|
2000-03-12 12:14:14 +03:00
|
|
|
&& !nsCRT::IsAsciiSpace(aInString[i])
|
1999-12-05 19:56:04 +03:00
|
|
|
; i++)
|
|
|
|
;
|
|
|
|
while (--i > pos && (
|
2000-03-03 09:49:23 +03:00
|
|
|
aInString[i] == '.' || aInString[i] == ',' || aInString[i] == ';' ||
|
|
|
|
aInString[i] == '!' || aInString[i] == '?' || aInString[i] == '-'
|
1999-12-05 19:56:04 +03:00
|
|
|
))
|
|
|
|
;
|
|
|
|
if (i > pos)
|
|
|
|
{
|
|
|
|
end = i;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return PR_FALSE;
|
|
|
|
} //switch
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-03-03 09:49:23 +03:00
|
|
|
mozTXTToHTMLConv::CalculateURLBoundaries(const PRUnichar * aInString, PRInt32 aInStringLength,
|
1999-12-05 19:56:04 +03:00
|
|
|
const PRUint32 pos, const PRUint32 whathasbeendone,
|
|
|
|
const modetype check, const PRUint32 start, const PRUint32 end,
|
2000-03-03 09:49:23 +03:00
|
|
|
nsString& txtURL, nsString& desc,
|
1999-12-05 19:56:04 +03:00
|
|
|
PRInt32& replaceBefore, PRInt32& replaceAfter)
|
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
PRUint32 descstart = start;
|
1999-12-05 19:56:04 +03:00
|
|
|
switch(check)
|
|
|
|
{
|
|
|
|
case RFC1738:
|
|
|
|
{
|
|
|
|
descstart = start - 5;
|
2000-03-03 09:49:23 +03:00
|
|
|
desc.Append(&aInString[descstart], end - descstart + 2); // include "<URL:" and ">"
|
1999-12-05 19:56:04 +03:00
|
|
|
replaceAfter = end - pos + 1;
|
|
|
|
} break;
|
|
|
|
case RFC2396E:
|
|
|
|
{
|
|
|
|
descstart = start - 1;
|
2000-03-03 09:49:23 +03:00
|
|
|
desc.Append(&aInString[descstart], end - descstart + 2); // include brackets
|
1999-12-05 19:56:04 +03:00
|
|
|
replaceAfter = end - pos + 1;
|
|
|
|
} break;
|
|
|
|
case freetext:
|
|
|
|
case abbreviated:
|
|
|
|
{
|
|
|
|
descstart = start;
|
2000-03-03 09:49:23 +03:00
|
|
|
desc.Append(&aInString[descstart], end - start + 1); // don't include brackets
|
1999-12-05 19:56:04 +03:00
|
|
|
replaceAfter = end - pos;
|
|
|
|
} break;
|
|
|
|
default: break;
|
|
|
|
} //switch
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
EscapeStr(desc);
|
1999-12-05 19:56:04 +03:00
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
txtURL.Append(&aInString[start], end - start + 1);
|
1999-12-05 19:56:04 +03:00
|
|
|
txtURL.StripWhitespace();
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
// FIX ME
|
|
|
|
nsAutoString temp2;
|
|
|
|
ScanTXT(&aInString[descstart], pos - descstart, ~kURLs /*prevents loop*/ & whathasbeendone, temp2);
|
|
|
|
replaceBefore = temp2.Length();
|
1999-12-05 19:56:04 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
mozTXTToHTMLConv::CheckURLAndCreateHTML(
|
2000-05-17 08:22:49 +04:00
|
|
|
const nsString& txtURL, const nsString& desc, const modetype mode,
|
2000-03-03 09:49:23 +03:00
|
|
|
nsString& outputHTML)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
// Create *uri from txtURL
|
2000-03-03 09:49:23 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (!mIOService)
|
|
|
|
mIOService = do_GetService(kIOServiceCID, &rv);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || !mIOService)
|
1999-12-08 05:10:57 +03:00
|
|
|
return PR_FALSE;
|
2000-03-03 09:49:23 +03:00
|
|
|
|
|
|
|
char* specStr = txtURL.ToNewCString(); //I18N this forces a single byte char
|
1999-12-08 05:10:57 +03:00
|
|
|
if (specStr == nsnull)
|
1999-12-05 19:56:04 +03:00
|
|
|
return PR_FALSE;
|
2000-03-03 09:49:23 +03:00
|
|
|
|
|
|
|
// it would be faster if we could just check to see if there is a protocol
|
|
|
|
// handler for the url and return instead of actually trying to create a url...
|
|
|
|
rv = mIOService->NewURI(specStr, nsnull, getter_AddRefs(uri));
|
1999-12-05 19:56:04 +03:00
|
|
|
Recycle(specStr);
|
|
|
|
|
|
|
|
// Real work
|
|
|
|
if (NS_SUCCEEDED(rv) && uri)
|
|
|
|
{
|
2000-09-13 06:11:00 +04:00
|
|
|
outputHTML.AssignWithConversion("<a class=\"moz-txt-link-");
|
2000-05-17 08:22:49 +04:00
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case RFC1738:
|
|
|
|
outputHTML.AppendWithConversion("rfc1738");
|
|
|
|
break;
|
|
|
|
case RFC2396E:
|
|
|
|
outputHTML.AppendWithConversion("rfc2396E");
|
|
|
|
break;
|
|
|
|
case freetext:
|
|
|
|
outputHTML.AppendWithConversion("freetext");
|
|
|
|
break;
|
|
|
|
case abbreviated:
|
|
|
|
outputHTML.AppendWithConversion("abbreviated");
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
outputHTML.AppendWithConversion("\" href=\"");
|
1999-12-05 19:56:04 +03:00
|
|
|
outputHTML += txtURL;
|
2000-04-02 13:10:15 +04:00
|
|
|
outputHTML.AppendWithConversion("\">");
|
1999-12-05 19:56:04 +03:00
|
|
|
outputHTML += desc;
|
2000-04-02 13:10:15 +04:00
|
|
|
outputHTML.AppendWithConversion("</a>");
|
1999-12-05 19:56:04 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2000-03-03 09:49:23 +03:00
|
|
|
mozTXTToHTMLConv::FindURL(const PRUnichar * aInString, PRInt32 aInLength, const PRUint32 pos,
|
1999-12-05 19:56:04 +03:00
|
|
|
const PRUint32 whathasbeendone,
|
2000-03-03 09:49:23 +03:00
|
|
|
nsString& outputHTML, PRInt32& replaceBefore, PRInt32& replaceAfter)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
enum statetype {unchecked, invalid, startok, endok, success};
|
2000-03-03 09:49:23 +03:00
|
|
|
static const modetype ranking[] = {RFC1738, RFC2396E, freetext, abbreviated};
|
1999-12-05 19:56:04 +03:00
|
|
|
|
1999-12-08 05:10:57 +03:00
|
|
|
statetype state[mozTXTToHTMLConv_lastMode + 1]; // 0(=unknown)..lastMode
|
1999-12-05 19:56:04 +03:00
|
|
|
/* I don't like this abuse of enums as index for the array,
|
|
|
|
but I don't know a better method */
|
|
|
|
|
|
|
|
// Define, which modes to check
|
|
|
|
/* all modes but abbreviated are checked for text[pos] == ':',
|
|
|
|
only abbreviated for '.', RFC2396E and abbreviated for '@' */
|
1999-12-08 05:10:57 +03:00
|
|
|
for (modetype iState = unknown; iState <= mozTXTToHTMLConv_lastMode;
|
1999-12-05 19:56:04 +03:00
|
|
|
iState = modetype(iState + 1))
|
2000-03-03 09:49:23 +03:00
|
|
|
state[iState] = aInString[pos] == ':' ? unchecked : invalid;
|
|
|
|
switch (aInString[pos])
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
case '@':
|
|
|
|
state[RFC2396E] = unchecked;
|
|
|
|
// no break here
|
|
|
|
case '.':
|
|
|
|
state[abbreviated] = unchecked;
|
|
|
|
break;
|
|
|
|
case ':':
|
|
|
|
state[abbreviated] = invalid;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test, first successful mode wins, sequence defined by |ranking|
|
1999-12-08 05:10:57 +03:00
|
|
|
PRInt32 iCheck = 0; // the currently tested modetype
|
1999-12-05 19:56:04 +03:00
|
|
|
modetype check = ranking[iCheck];
|
1999-12-08 05:10:57 +03:00
|
|
|
for (; iCheck < mozTXTToHTMLConv_numberOfModes && state[check] != success;
|
|
|
|
iCheck++)
|
|
|
|
/* check state from last run.
|
|
|
|
If this is the first, check this one, which isn't = success yet */
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
check = ranking[iCheck];
|
|
|
|
|
|
|
|
PRUint32 start, end;
|
|
|
|
|
|
|
|
if (state[check] == unchecked)
|
2000-03-03 09:49:23 +03:00
|
|
|
if (FindURLStart(aInString, aInLength, pos, check, start))
|
1999-12-05 19:56:04 +03:00
|
|
|
state[check] = startok;
|
|
|
|
|
|
|
|
if (state[check] == startok)
|
2000-03-03 09:49:23 +03:00
|
|
|
if (FindURLEnd(aInString, aInLength, pos, check, start, end))
|
1999-12-05 19:56:04 +03:00
|
|
|
state[check] = endok;
|
|
|
|
|
|
|
|
if (state[check] == endok)
|
|
|
|
{
|
|
|
|
nsAutoString txtURL, desc;
|
|
|
|
PRInt32 resultReplaceBefore, resultReplaceAfter;
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
CalculateURLBoundaries(aInString, aInLength, pos, whathasbeendone, check, start, end,
|
1999-12-05 19:56:04 +03:00
|
|
|
txtURL, desc,
|
|
|
|
resultReplaceBefore, resultReplaceAfter);
|
1999-12-08 05:10:57 +03:00
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
if (aInString[pos] != ':')
|
|
|
|
{
|
|
|
|
nsAutoString temp = txtURL;
|
2000-04-02 13:10:15 +04:00
|
|
|
txtURL.SetLength(0);
|
2000-03-03 09:49:23 +03:00
|
|
|
CompleteAbbreviatedURL(temp.GetUnicode(),temp.Length(), pos - start, txtURL);
|
|
|
|
}
|
1999-12-05 19:56:04 +03:00
|
|
|
|
2000-05-17 08:22:49 +04:00
|
|
|
if (!txtURL.IsEmpty() && CheckURLAndCreateHTML(txtURL, desc, check,
|
|
|
|
outputHTML))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
replaceBefore = resultReplaceBefore;
|
|
|
|
replaceAfter = resultReplaceAfter;
|
|
|
|
state[check] = success;
|
|
|
|
}
|
|
|
|
} // if
|
|
|
|
} // for
|
|
|
|
return state[check] == success;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2000-03-03 09:49:23 +03:00
|
|
|
mozTXTToHTMLConv::ItMatchesDelimited(const PRUnichar * aInString, PRInt32 aInLength,
|
|
|
|
const char* rep, PRInt32 aRepLen, LIMTYPE before, LIMTYPE after)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
|
|
|
|
// this little method gets called a LOT. I found we were spending a lot of time
|
|
|
|
// just calculating the length of the variable "rep" over and over again every time
|
|
|
|
// we called it. So we're now passing an integer in here.
|
|
|
|
PRInt32 textLen = aInLength;
|
|
|
|
|
1999-12-05 19:56:04 +03:00
|
|
|
if
|
|
|
|
(
|
1999-12-08 05:10:57 +03:00
|
|
|
(before == LT_IGNORE && (after == LT_IGNORE || after == LT_DELIMITER))
|
2000-03-03 09:49:23 +03:00
|
|
|
&& textLen < aRepLen ||
|
1999-12-08 05:10:57 +03:00
|
|
|
(before != LT_IGNORE || after != LT_IGNORE && after != LT_DELIMITER)
|
2000-03-03 09:49:23 +03:00
|
|
|
&& textLen < aRepLen + 1 ||
|
1999-12-05 19:56:04 +03:00
|
|
|
before != LT_IGNORE && after != LT_IGNORE && after != LT_DELIMITER
|
2000-03-03 09:49:23 +03:00
|
|
|
&& textLen < aRepLen + 2
|
1999-12-05 19:56:04 +03:00
|
|
|
)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
PRUnichar text0 = aInString[0];
|
|
|
|
PRUnichar textAfterPos = aInString[aRepLen + (before == LT_IGNORE ? 0 : 1)];
|
1999-12-08 05:10:57 +03:00
|
|
|
|
1999-12-05 19:56:04 +03:00
|
|
|
if
|
|
|
|
(
|
|
|
|
before == LT_ALPHA
|
2000-03-12 12:14:14 +03:00
|
|
|
&& !nsCRT::IsAsciiAlpha(text0) ||
|
1999-12-05 19:56:04 +03:00
|
|
|
before == LT_DIGIT
|
2000-03-12 12:14:14 +03:00
|
|
|
&& !nsCRT::IsAsciiDigit(text0) ||
|
1999-12-05 19:56:04 +03:00
|
|
|
before == LT_DELIMITER
|
|
|
|
&&
|
|
|
|
(
|
2000-03-12 12:14:14 +03:00
|
|
|
nsCRT::IsAsciiAlpha(text0) ||
|
|
|
|
nsCRT::IsAsciiDigit(text0) ||
|
2000-03-03 09:49:23 +03:00
|
|
|
text0 == *rep
|
1999-12-05 19:56:04 +03:00
|
|
|
) ||
|
|
|
|
after == LT_ALPHA
|
2000-03-12 12:14:14 +03:00
|
|
|
&& !nsCRT::IsAsciiAlpha(textAfterPos) ||
|
1999-12-05 19:56:04 +03:00
|
|
|
after == LT_DIGIT
|
2000-03-12 12:14:14 +03:00
|
|
|
&& !nsCRT::IsAsciiDigit(textAfterPos) ||
|
1999-12-05 19:56:04 +03:00
|
|
|
after == LT_DELIMITER
|
|
|
|
&&
|
|
|
|
(
|
2000-03-12 12:14:14 +03:00
|
|
|
nsCRT::IsAsciiAlpha(textAfterPos) ||
|
|
|
|
nsCRT::IsAsciiDigit(textAfterPos) ||
|
2000-03-03 09:49:23 +03:00
|
|
|
textAfterPos == *rep
|
1999-12-05 19:56:04 +03:00
|
|
|
) ||
|
2000-03-03 09:49:23 +03:00
|
|
|
!(before == LT_IGNORE ? !nsCRT::strncasecmp(aInString, rep, aRepLen) :
|
|
|
|
!nsCRT::strncasecmp(aInString + 1, rep, aRepLen))
|
1999-12-05 19:56:04 +03:00
|
|
|
)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32
|
2000-03-03 09:49:23 +03:00
|
|
|
mozTXTToHTMLConv::NumberOfMatches(const PRUnichar * aInString, PRInt32 aInStringLength,
|
|
|
|
const char* rep, PRInt32 aRepLen, LIMTYPE before, LIMTYPE after)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
PRUint32 result = 0;
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < aInStringLength; i++)
|
|
|
|
{
|
|
|
|
const PRUnichar * indexIntoString = &aInString[i];
|
|
|
|
if (ItMatchesDelimited(indexIntoString, aInStringLength - i, rep, aRepLen, before, after))
|
1999-12-05 19:56:04 +03:00
|
|
|
result++;
|
2000-03-03 09:49:23 +03:00
|
|
|
}
|
1999-12-05 19:56:04 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
|
|
|
|
// NOTE: the converted html for the phrase is appended to aOutString
|
1999-12-05 19:56:04 +03:00
|
|
|
PRBool
|
2000-03-03 09:49:23 +03:00
|
|
|
mozTXTToHTMLConv::StructPhraseHit(const PRUnichar * aInString, PRInt32 aInStringLength, PRBool col0,
|
|
|
|
const char* tagTXT, PRInt32 aTagTXTLen,
|
1999-12-15 06:30:55 +03:00
|
|
|
const char* tagHTML, const char* attributeHTML,
|
2000-03-03 09:49:23 +03:00
|
|
|
nsString& aOutString, PRUint32& openTags)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
/* We're searching for the following pattern:
|
|
|
|
LT_DELIMITER - "*" - ALPHA -
|
|
|
|
[ some text (maybe more "*"-pairs) - ALPHA ] "*" - LT_DELIMITER.
|
1999-12-08 05:10:57 +03:00
|
|
|
<strong> is only inserted, if existance of a pair could be verified
|
|
|
|
We use the first opening/closing tag, if we can choose */
|
1999-12-05 19:56:04 +03:00
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
const PRUnichar * newOffset = aInString;
|
|
|
|
PRInt32 newLength = aInStringLength;
|
|
|
|
if (!col0) // skip the first element?
|
|
|
|
{
|
|
|
|
newOffset = &aInString[1];
|
|
|
|
newLength = aInStringLength - 1;
|
|
|
|
}
|
|
|
|
|
1999-12-05 19:56:04 +03:00
|
|
|
// opening tag
|
1999-12-08 05:10:57 +03:00
|
|
|
if
|
|
|
|
(
|
2000-03-03 09:49:23 +03:00
|
|
|
ItMatchesDelimited(aInString, aInStringLength, tagTXT, aTagTXTLen,
|
|
|
|
(col0 ? LT_IGNORE : LT_DELIMITER), LT_ALPHA) // is opening tag
|
|
|
|
&& NumberOfMatches(newOffset, newLength, tagTXT, aTagTXTLen,
|
|
|
|
LT_ALPHA, LT_DELIMITER) // remaining closing tags
|
|
|
|
> openTags
|
1999-12-08 05:10:57 +03:00
|
|
|
)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
openTags++;
|
2000-04-02 13:10:15 +04:00
|
|
|
aOutString.AppendWithConversion("<");
|
|
|
|
aOutString.AppendWithConversion(tagHTML);
|
|
|
|
aOutString.AppendWithConversion(' ');
|
|
|
|
aOutString.AppendWithConversion(attributeHTML);
|
2000-09-13 06:11:00 +04:00
|
|
|
aOutString.AppendWithConversion("><span class=\"moz-txt-tag\">");
|
2000-04-02 13:10:15 +04:00
|
|
|
aOutString.AppendWithConversion(tagTXT);
|
2000-05-17 08:22:49 +04:00
|
|
|
aOutString.AppendWithConversion("</span>");
|
1999-12-05 19:56:04 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// closing tag
|
|
|
|
else if (openTags > 0
|
2000-03-03 09:49:23 +03:00
|
|
|
&& ItMatchesDelimited(aInString, aInStringLength, tagTXT, aTagTXTLen, LT_ALPHA, LT_DELIMITER))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
openTags--;
|
2000-09-13 06:11:00 +04:00
|
|
|
aOutString.AppendWithConversion("<span class=\"moz-txt-tag\">");
|
2000-04-02 13:10:15 +04:00
|
|
|
aOutString.AppendWithConversion(tagTXT);
|
2000-05-17 08:22:49 +04:00
|
|
|
aOutString.AppendWithConversion("</span></");
|
2000-04-02 13:10:15 +04:00
|
|
|
aOutString.AppendWithConversion(tagHTML);
|
|
|
|
aOutString.AppendWithConversion('>');
|
1999-12-05 19:56:04 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2000-03-03 09:49:23 +03:00
|
|
|
mozTXTToHTMLConv::SmilyHit(const PRUnichar * aInString, PRInt32 aLength, PRBool col0,
|
|
|
|
const char* tagTXT, PRInt32 aTagTxtLength, const char* tagHTML,
|
|
|
|
nsString& outputHTML, PRInt32& glyphTextLen)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
1999-12-15 06:30:55 +03:00
|
|
|
PRInt32 tagLen = nsCRT::strlen(tagTXT);
|
|
|
|
|
|
|
|
PRUint32 delim = (col0 ? 0 : 1) + tagLen;
|
1999-12-08 05:10:57 +03:00
|
|
|
if
|
1999-12-05 19:56:04 +03:00
|
|
|
(
|
2000-03-12 12:14:14 +03:00
|
|
|
(col0 || nsCRT::IsAsciiSpace(aInString[0]))
|
1999-12-05 19:56:04 +03:00
|
|
|
&&
|
|
|
|
(
|
2000-03-03 09:49:23 +03:00
|
|
|
aLength <= PRInt32(delim) ||
|
2000-03-12 12:14:14 +03:00
|
|
|
nsCRT::IsAsciiSpace(aInString[delim]) ||
|
2000-03-03 09:49:23 +03:00
|
|
|
aLength > PRInt32(delim + 1)
|
1999-12-05 19:56:04 +03:00
|
|
|
&&
|
|
|
|
(
|
2000-03-03 09:49:23 +03:00
|
|
|
aInString[delim] == '.' ||
|
|
|
|
aInString[delim] == ',' ||
|
|
|
|
aInString[delim] == ';' ||
|
|
|
|
aInString[delim] == '!' ||
|
|
|
|
aInString[delim] == '?'
|
1999-12-05 19:56:04 +03:00
|
|
|
)
|
2000-03-12 12:14:14 +03:00
|
|
|
&& nsCRT::IsAsciiSpace(aInString[delim + 1])
|
1999-12-05 19:56:04 +03:00
|
|
|
)
|
2000-03-03 09:49:23 +03:00
|
|
|
&& ItMatchesDelimited(aInString, aLength, tagTXT, aTagTxtLength,
|
1999-12-08 05:10:57 +03:00
|
|
|
col0 ? LT_IGNORE : LT_DELIMITER, LT_IGNORE)
|
|
|
|
// Note: tests at different pos for LT_IGNORE and LT_DELIMITER
|
1999-12-05 19:56:04 +03:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (col0)
|
1999-12-08 05:10:57 +03:00
|
|
|
{
|
2000-04-02 13:10:15 +04:00
|
|
|
outputHTML.AssignWithConversion(tagHTML);
|
1999-12-08 05:10:57 +03:00
|
|
|
}
|
1999-12-05 19:56:04 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
outputHTML.Truncate();
|
2000-04-02 13:10:15 +04:00
|
|
|
outputHTML.AppendWithConversion(' ');
|
|
|
|
outputHTML.AppendWithConversion(tagHTML);
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
1999-12-15 06:30:55 +03:00
|
|
|
glyphTextLen = (col0 ? 0 : 1) + tagLen;
|
1999-12-05 19:56:04 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
// the glyph is appended to aOutputString instead of the original string...
|
1999-12-05 19:56:04 +03:00
|
|
|
PRBool
|
2000-03-03 09:49:23 +03:00
|
|
|
mozTXTToHTMLConv::GlyphHit(const PRUnichar * aInString, PRInt32 aInLength, PRBool col0,
|
|
|
|
nsString& aOutputString, PRInt32& glyphTextLen)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
1999-12-15 06:30:55 +03:00
|
|
|
MOZ_TIMER_START(mGlyphHitTimer);
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
PRUnichar text0 = aInString[0];
|
|
|
|
PRUnichar text1 = aInString[1];
|
|
|
|
|
|
|
|
// temporary variable used to store the glyph html text
|
|
|
|
nsAutoString outputHTML;
|
|
|
|
|
1999-12-08 05:10:57 +03:00
|
|
|
if
|
|
|
|
(
|
2000-01-11 04:56:25 +03:00
|
|
|
( // Performance increase
|
2000-03-03 09:49:23 +03:00
|
|
|
(col0 ? text0 : text1) == ':' ||
|
|
|
|
(col0 ? text0 : text1) == ';'
|
2000-01-11 04:56:25 +03:00
|
|
|
)
|
2000-03-03 09:49:23 +03:00
|
|
|
&&
|
1999-12-15 06:30:55 +03:00
|
|
|
(
|
2000-09-13 06:11:00 +04:00
|
|
|
SmilyHit(aInString, aInLength, col0, ":-)", 3, "<img src=\"chrome://messenger/skin/smile.gif\" alt=\":-)\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen) ||
|
|
|
|
SmilyHit(aInString, aInLength, col0, ":)", 2, "<img src=\"chrome://messenger/skin/smile.gif\" alt=\":)\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen) ||
|
|
|
|
SmilyHit(aInString, aInLength, col0, ":-(", 3, "<img src=\"chrome://messenger/skin/frown.gif\" alt=\":-(\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen) ||
|
|
|
|
SmilyHit(aInString, aInLength, col0, ":(", 2, "<img src=\"chrome://messenger/skin/frown.gif\" alt=\":(\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen) ||
|
|
|
|
SmilyHit(aInString, aInLength, col0, ";-)", 3, "<img src=\"chrome://messenger/skin/wink.gif\" alt=\";-)\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen) ||
|
|
|
|
SmilyHit(aInString, aInLength, col0, ";)", 2, "<img src=\"chrome://messenger/skin/wink.gif\" alt=\";)\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen) ||
|
|
|
|
SmilyHit(aInString, aInLength, col0, ";-P", 3, "<img src=\"chrome://messenger/skin/sick.gif\" alt=\";-P\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen)
|
1999-12-15 06:30:55 +03:00
|
|
|
)
|
1999-12-08 05:10:57 +03:00
|
|
|
)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
aOutputString.Append(outputHTML);
|
1999-12-15 06:30:55 +03:00
|
|
|
MOZ_TIMER_STOP(mGlyphHitTimer);
|
1999-12-08 05:10:57 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-01-11 04:56:25 +03:00
|
|
|
if // XXX Hotfix
|
|
|
|
(
|
2000-03-03 09:49:23 +03:00
|
|
|
( // Performance increase
|
|
|
|
col0
|
|
|
|
&&
|
|
|
|
(
|
|
|
|
text1 == ':' ||
|
|
|
|
text1 == ';'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
&&
|
2000-01-11 04:56:25 +03:00
|
|
|
(
|
2000-09-13 06:11:00 +04:00
|
|
|
SmilyHit(aInString, aInLength, PR_FALSE, ":-)", 3, "<img src=\"chrome://messenger/skin/smile.gif\" alt=\":-)\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen) ||
|
|
|
|
SmilyHit(aInString, aInLength, PR_FALSE, ":)", 2, "<img src=\"chrome://messenger/skin/smile.gif\" alt=\":)\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen) ||
|
|
|
|
SmilyHit(aInString, aInLength, PR_FALSE, ":-(", 3, "<img src=\"chrome://messenger/skin/frown.gif\" alt=\":-(\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen) ||
|
|
|
|
SmilyHit(aInString, aInLength, PR_FALSE, ":(", 2, "<img src=\"chrome://messenger/skin/frown.gif\" alt=\":(\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen) ||
|
|
|
|
SmilyHit(aInString, aInLength, PR_FALSE, ";-)", 3, "<img src=\"chrome://messenger/skin/wink.gif\" alt=\";-)\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen) ||
|
|
|
|
SmilyHit(aInString, aInLength, PR_FALSE, ";)", 2, "<img src=\"chrome://messenger/skin/wink.gif\" alt=\";)\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen) ||
|
|
|
|
SmilyHit(aInString, aInLength, PR_FALSE, ";-P", 3, "<img src=\"chrome://messenger/skin/sick.gif\" alt=\";-P\" class=\"moz-txt-smily\" height=17 width=17 align=ABSCENTER>", outputHTML, glyphTextLen)
|
2000-01-11 04:56:25 +03:00
|
|
|
)
|
1999-12-08 05:10:57 +03:00
|
|
|
)
|
|
|
|
{
|
2000-06-08 04:50:41 +04:00
|
|
|
aOutputString.Append(outputHTML);
|
|
|
|
MOZ_TIMER_STOP(mGlyphHitTimer);
|
1999-12-08 05:10:57 +03:00
|
|
|
return PR_TRUE;
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
2000-03-03 09:49:23 +03:00
|
|
|
if (text0 == '+' || text1 == '+')
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
if (ItMatchesDelimited(aInString, aInLength, " +/-", 4, LT_IGNORE, LT_IGNORE))
|
|
|
|
{
|
2000-04-02 13:10:15 +04:00
|
|
|
aOutputString.AppendWithConversion(" ±");
|
2000-03-03 09:49:23 +03:00
|
|
|
glyphTextLen = 4;
|
|
|
|
MOZ_TIMER_STOP(mGlyphHitTimer);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (col0 && ItMatchesDelimited(aInString, aInLength, "+/-", 3, LT_IGNORE, LT_IGNORE))
|
|
|
|
{
|
2000-04-02 13:10:15 +04:00
|
|
|
aOutputString.AppendWithConversion("±");
|
2000-03-03 09:49:23 +03:00
|
|
|
glyphTextLen = 3;
|
|
|
|
MOZ_TIMER_STOP(mGlyphHitTimer);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
2000-03-03 09:49:23 +03:00
|
|
|
|
2000-01-11 04:56:25 +03:00
|
|
|
if // x^2 -> sup
|
1999-12-05 19:56:04 +03:00
|
|
|
(
|
2000-03-03 09:49:23 +03:00
|
|
|
text1 == '^' // Performance increase
|
1999-12-05 19:56:04 +03:00
|
|
|
&&
|
|
|
|
(
|
2000-03-03 09:49:23 +03:00
|
|
|
ItMatchesDelimited(aInString, aInLength, "^", 1, LT_DIGIT, LT_DIGIT) ||
|
|
|
|
ItMatchesDelimited(aInString, aInLength, "^", 1, LT_ALPHA, LT_DIGIT) ||
|
|
|
|
ItMatchesDelimited(&aInString[1], aInLength - 1, "^", 1, LT_IGNORE, LT_DIGIT)
|
|
|
|
&& text0 == ')'
|
1999-12-05 19:56:04 +03:00
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// Find first non-digit
|
|
|
|
PRInt32 delimPos = 3; // 3 = Position after first digit after "^"
|
2000-03-03 09:49:23 +03:00
|
|
|
for (; delimPos < aInLength &&
|
2000-03-12 12:14:14 +03:00
|
|
|
nsCRT::IsAsciiDigit(aInString[PRUint32(delimPos)]); delimPos++)
|
1999-12-05 19:56:04 +03:00
|
|
|
;
|
1999-12-08 05:10:57 +03:00
|
|
|
// Note: (delimPos == text.Length()) could be true
|
1999-12-05 19:56:04 +03:00
|
|
|
|
2000-03-12 12:14:14 +03:00
|
|
|
if (nsCRT::IsAsciiAlpha(aInString[PRUint32(delimPos)]))
|
1999-12-15 06:30:55 +03:00
|
|
|
{
|
|
|
|
MOZ_TIMER_STOP(mGlyphHitTimer);
|
1999-12-05 19:56:04 +03:00
|
|
|
return PR_FALSE;
|
1999-12-15 06:30:55 +03:00
|
|
|
}
|
1999-12-05 19:56:04 +03:00
|
|
|
|
|
|
|
outputHTML.Truncate();
|
2000-03-03 09:49:23 +03:00
|
|
|
outputHTML += text0;
|
2000-09-13 06:11:00 +04:00
|
|
|
outputHTML.AppendWithConversion("<sup class=\"moz-txt-sup\">");
|
2000-03-03 09:49:23 +03:00
|
|
|
|
|
|
|
aOutputString.Append(outputHTML);
|
|
|
|
aOutputString.Append(&aInString[2], delimPos - 2);
|
2000-04-02 13:10:15 +04:00
|
|
|
aOutputString.AppendWithConversion("</sup>");
|
2000-03-03 09:49:23 +03:00
|
|
|
|
1999-12-05 19:56:04 +03:00
|
|
|
glyphTextLen = delimPos /* - 1 + 1 */ ;
|
1999-12-15 06:30:55 +03:00
|
|
|
MOZ_TIMER_STOP(mGlyphHitTimer);
|
1999-12-05 19:56:04 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
The following strings are not substituted:
|
|
|
|
|TXT |HTML |Reason
|
|
|
|
+------+---------+----------
|
|
|
|
-> ← Bug #454
|
|
|
|
=> ⇐ dito
|
|
|
|
<- → dito
|
|
|
|
<= ⇒ dito
|
|
|
|
(tm) ™ dito
|
|
|
|
1/4 ¼ is triggered by 1/4 Part 1, 2/4 Part 2, ...
|
|
|
|
3/4 ¾ dito
|
|
|
|
1/2 ½ similar
|
|
|
|
*/
|
1999-12-15 06:30:55 +03:00
|
|
|
MOZ_TIMER_STOP(mGlyphHitTimer);
|
1999-12-05 19:56:04 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-12-08 05:10:57 +03:00
|
|
|
/***************************************************************************
|
|
|
|
Library-internal Interface
|
1999-12-05 19:56:04 +03:00
|
|
|
****************************************************************************/
|
|
|
|
|
1999-12-08 05:10:57 +03:00
|
|
|
mozTXTToHTMLConv::mozTXTToHTMLConv()
|
|
|
|
{
|
|
|
|
NS_INIT_ISUPPORTS();
|
1999-12-15 06:30:55 +03:00
|
|
|
MOZ_TIMER_RESET(mScanTXTTimer);
|
|
|
|
MOZ_TIMER_RESET(mGlyphHitTimer);
|
|
|
|
MOZ_TIMER_RESET(mTotalMimeTime);
|
|
|
|
MOZ_TIMER_START(mTotalMimeTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
mozTXTToHTMLConv::~mozTXTToHTMLConv()
|
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
MOZ_TIMER_STOP(mTotalMimeTime);
|
1999-12-15 06:30:55 +03:00
|
|
|
MOZ_TIMER_DEBUGLOG(("MIME Total Processing Time: "));
|
|
|
|
MOZ_TIMER_PRINT(mTotalMimeTime);
|
|
|
|
|
|
|
|
MOZ_TIMER_DEBUGLOG(("mozTXTToHTMLConv::ScanTXT(): "));
|
|
|
|
MOZ_TIMER_PRINT(mScanTXTTimer);
|
|
|
|
|
|
|
|
MOZ_TIMER_DEBUGLOG(("mozTXTToHTMLConv::GlyphHit(): "));
|
|
|
|
MOZ_TIMER_PRINT(mGlyphHitTimer);
|
1999-12-08 05:10:57 +03:00
|
|
|
}
|
|
|
|
|
2000-11-17 06:45:13 +03:00
|
|
|
NS_IMPL_ISUPPORTS1(mozTXTToHTMLConv, mozTXTToHTMLConv)
|
1999-12-08 05:10:57 +03:00
|
|
|
|
1999-12-05 19:56:04 +03:00
|
|
|
PRInt32
|
2000-03-03 09:49:23 +03:00
|
|
|
mozTXTToHTMLConv::CiteLevelTXT(const PRUnichar *line,
|
1999-12-05 19:56:04 +03:00
|
|
|
PRUint32& logLineStart)
|
|
|
|
{
|
|
|
|
PRInt32 result = 0;
|
2000-03-03 09:49:23 +03:00
|
|
|
PRInt32 lineLength = nsCRT::strlen(line);
|
1999-12-05 19:56:04 +03:00
|
|
|
|
|
|
|
PRBool moreCites = PR_TRUE;
|
|
|
|
while (moreCites)
|
|
|
|
{
|
2000-05-17 08:22:49 +04:00
|
|
|
/* E.g. the following lines count as quote:
|
1999-12-05 19:56:04 +03:00
|
|
|
|
|
|
|
> text
|
2000-05-17 08:22:49 +04:00
|
|
|
//#ifdef QUOTE_RECOGNITION_AGGRESSIVE
|
|
|
|
>text
|
|
|
|
//#ifdef QUOTE_RECOGNITION_AGGRESSIVE
|
1999-12-05 19:56:04 +03:00
|
|
|
> text
|
2000-05-17 08:22:49 +04:00
|
|
|
] text
|
1999-12-05 19:56:04 +03:00
|
|
|
USER> text
|
2000-05-17 08:22:49 +04:00
|
|
|
USER] text
|
|
|
|
//#endif
|
1999-12-05 19:56:04 +03:00
|
|
|
|
|
|
|
logLineStart is the position of "t" in this example
|
|
|
|
*/
|
|
|
|
PRUint32 i = logLineStart;
|
2000-05-17 08:22:49 +04:00
|
|
|
|
|
|
|
#ifdef QUOTE_RECOGNITION_AGGRESSIVE
|
2000-03-12 12:14:14 +03:00
|
|
|
for (; PRInt32(i) < lineLength && nsCRT::IsAsciiSpace(line[i]); i++)
|
1999-12-05 19:56:04 +03:00
|
|
|
;
|
2000-05-17 08:22:49 +04:00
|
|
|
for (; PRInt32(i) < lineLength && nsCRT::IsAsciiAlpha(line[i])
|
|
|
|
&& nsCRT::IsUpper(line[i]) ; i++)
|
1999-12-05 19:56:04 +03:00
|
|
|
;
|
2000-05-17 08:22:49 +04:00
|
|
|
if (PRInt32(i) < lineLength && (line[i] == '>' || line[i] == ']'))
|
|
|
|
#else
|
|
|
|
if (PRInt32(i) < lineLength && line[i] == '>')
|
|
|
|
#endif
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-05-17 08:22:49 +04:00
|
|
|
i++;
|
|
|
|
if (PRInt32(i) < lineLength && line[i] == ' ')
|
|
|
|
i++;
|
|
|
|
// sendmail/mbox
|
|
|
|
// Placed here for performance increase
|
2000-03-03 09:49:23 +03:00
|
|
|
const PRUnichar * indexString = &line[logLineStart];
|
2000-05-17 08:22:49 +04:00
|
|
|
// here, |logLineStart < lineLength| is always true
|
|
|
|
if (!nsCRT::strncasecmp(indexString, ">From ",
|
|
|
|
MinInt(6, nsCRT::strlen(indexString))))
|
|
|
|
//XXX RFC2646
|
1999-12-05 19:56:04 +03:00
|
|
|
moreCites = PR_FALSE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result++;
|
2000-05-17 08:22:49 +04:00
|
|
|
logLineStart = i;
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
moreCites = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
void
|
|
|
|
mozTXTToHTMLConv::ScanTXT(const PRUnichar * aInString, PRInt32 aInStringLength, PRUint32 whattodo, nsString& aOutString)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
PRBool doURLs = whattodo & kURLs;
|
|
|
|
PRBool doGlyphSubstitution = whattodo & kGlyphSubstitution;
|
|
|
|
PRBool doStructPhrase = whattodo & kStructPhrase;
|
|
|
|
|
1999-12-15 06:30:55 +03:00
|
|
|
MOZ_TIMER_START(mScanTXTTimer);
|
|
|
|
|
1999-12-05 19:56:04 +03:00
|
|
|
PRUint32 structPhrase_strong = 0; // Number of currently open tags
|
|
|
|
PRUint32 structPhrase_underline = 0;
|
|
|
|
PRUint32 structPhrase_italic = 0;
|
|
|
|
PRUint32 structPhrase_code = 0;
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
nsAutoString outputHTML; // moved here for performance increase
|
|
|
|
|
|
|
|
for(PRUint32 i = 0; PRInt32(i) < aInStringLength;)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
if (doGlyphSubstitution)
|
|
|
|
{
|
|
|
|
PRInt32 glyphTextLen;
|
2000-03-03 09:49:23 +03:00
|
|
|
if (GlyphHit(&aInString[i], aInStringLength - i, i == 0, aOutString, glyphTextLen))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
i += glyphTextLen;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doStructPhrase)
|
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
const PRUnichar * newOffset = aInString;
|
|
|
|
PRInt32 newLength = aInStringLength;
|
|
|
|
if (i > 0 ) // skip the first element?
|
|
|
|
{
|
|
|
|
newOffset = &aInString[i-1];
|
|
|
|
newLength = aInStringLength - i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aInString[i]) // Performance increase
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
case '*':
|
2000-03-03 09:49:23 +03:00
|
|
|
if (StructPhraseHit(newOffset, newLength, i == 0,
|
2000-09-13 06:11:00 +04:00
|
|
|
"*", 1, "b", "class=\"moz-txt-star\"",
|
2000-03-03 09:49:23 +03:00
|
|
|
aOutString, structPhrase_strong))
|
2000-01-11 04:56:25 +03:00
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
2000-03-03 09:49:23 +03:00
|
|
|
break;
|
2000-09-13 06:11:00 +04:00
|
|
|
case '/':
|
2000-03-03 09:49:23 +03:00
|
|
|
if (StructPhraseHit(newOffset, newLength, i == 0,
|
2000-09-13 06:11:00 +04:00
|
|
|
"/", 1, "i", "class=\"moz-txt-slash\"",
|
|
|
|
aOutString, structPhrase_italic))
|
2000-01-11 04:56:25 +03:00
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
2000-03-03 09:49:23 +03:00
|
|
|
break;
|
2000-09-13 06:11:00 +04:00
|
|
|
case '_':
|
2000-03-03 09:49:23 +03:00
|
|
|
if (StructPhraseHit(newOffset, newLength, i == 0,
|
2000-09-13 06:11:00 +04:00
|
|
|
"_", 1, "span" /* <u> is deprecated */,
|
|
|
|
"class=\"moz-txt-underscore\"",
|
|
|
|
aOutString, structPhrase_underline))
|
2000-01-11 04:56:25 +03:00
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
2000-03-03 09:49:23 +03:00
|
|
|
break;
|
2000-01-11 04:56:25 +03:00
|
|
|
case '|':
|
2000-03-03 09:49:23 +03:00
|
|
|
if (StructPhraseHit(newOffset, newLength, i == 0,
|
2000-09-13 06:11:00 +04:00
|
|
|
"|", 1, "code", "class=\"moz-txt-verticalline\"",
|
2000-03-03 09:49:23 +03:00
|
|
|
aOutString, structPhrase_code))
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
2000-03-03 09:49:23 +03:00
|
|
|
break;
|
1999-12-08 05:10:57 +03:00
|
|
|
}
|
|
|
|
}
|
1999-12-05 19:56:04 +03:00
|
|
|
|
|
|
|
if (doURLs)
|
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
switch (aInString[i])
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
case ':':
|
|
|
|
case '@':
|
|
|
|
case '.':
|
2000-03-03 09:49:23 +03:00
|
|
|
if (aInString[i - 1] != ' ' && aInString[i + 1] != ' ') // Performance increase
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
PRInt32 replaceBefore;
|
|
|
|
PRInt32 replaceAfter;
|
2000-03-03 09:49:23 +03:00
|
|
|
if (FindURL(aInString, aInStringLength, i, whattodo,
|
1999-12-05 19:56:04 +03:00
|
|
|
outputHTML, replaceBefore, replaceAfter)
|
2000-03-03 09:49:23 +03:00
|
|
|
&& structPhrase_strong + structPhrase_italic +
|
|
|
|
structPhrase_underline + structPhrase_code == 0
|
|
|
|
/* workaround for bug #19445 */ )
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
aOutString.Cut(aOutString.Length() - replaceBefore, replaceBefore);
|
|
|
|
aOutString += outputHTML;
|
1999-12-05 19:56:04 +03:00
|
|
|
i += replaceAfter + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1999-12-08 05:10:57 +03:00
|
|
|
} //switch
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
switch (aInString[i])
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
|
|
|
// Special symbols
|
|
|
|
case '<':
|
|
|
|
case '>':
|
|
|
|
case '&':
|
2000-03-03 09:49:23 +03:00
|
|
|
EscapeChar(aInString[i], aOutString);
|
1999-12-05 19:56:04 +03:00
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
// Normal characters
|
|
|
|
default:
|
2000-03-03 09:49:23 +03:00
|
|
|
aOutString += aInString[i];
|
1999-12-05 19:56:04 +03:00
|
|
|
i++;
|
2000-03-03 09:49:23 +03:00
|
|
|
break;
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-15 06:30:55 +03:00
|
|
|
MOZ_TIMER_STOP(mScanTXTTimer);
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
void
|
|
|
|
mozTXTToHTMLConv::ScanHTML(nsString& aInString, PRUint32 whattodo, nsString &aOutString)
|
|
|
|
{
|
|
|
|
// some common variables we were recalculating
|
|
|
|
// every time inside the for loop...
|
|
|
|
PRInt32 lengthOfInString = aInString.Length();
|
|
|
|
const PRUnichar * uniBuffer = aInString.GetUnicode();
|
1999-12-05 19:56:04 +03:00
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
#ifdef DEBUG_BenB_Perf
|
|
|
|
PRTime parsing_start = PR_IntervalNow();
|
1999-12-05 19:56:04 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Look for simple entities not included in a tags and scan them.
|
|
|
|
/* Skip all tags ("<[...]>") and content in an a tag ("<a[...]</a>").
|
|
|
|
Unescape the rest (text between tags) and pass it to ScanTXT. */
|
2001-02-05 13:25:00 +03:00
|
|
|
for (PRInt32 i = 0; PRUint32(i) < lengthOfInString;)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
if (aInString[i] == '<') // html tag
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
PRUint32 start = PRUint32(i);
|
|
|
|
if (nsCRT::ToLower(aInString[PRUint32(i) + 1]) == 'a')
|
|
|
|
// if a tag, skip until </a>
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
i = aInString.Find("</a>", PR_TRUE, i);
|
|
|
|
if (i == kNotFound)
|
|
|
|
i = lengthOfInString;
|
|
|
|
else
|
|
|
|
i += 4;
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
else // just skip tag (attributes etc.)
|
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
i = aInString.FindChar('>', PR_FALSE, i);
|
|
|
|
if (i == kNotFound)
|
2001-02-05 13:25:00 +03:00
|
|
|
i = lengthOfInString;
|
2000-03-03 09:49:23 +03:00
|
|
|
else
|
|
|
|
i++;
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
2000-03-03 09:49:23 +03:00
|
|
|
aOutString.Append(&uniBuffer[start], PRUint32(i) - start);
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
PRUint32 start = PRUint32(i);
|
|
|
|
i = aInString.FindChar('<', PR_FALSE, i);
|
|
|
|
if (i == kNotFound)
|
|
|
|
i = lengthOfInString;
|
|
|
|
|
|
|
|
nsString tempString;
|
2000-03-29 07:58:50 +04:00
|
|
|
tempString.SetCapacity(PRUint32((PRUint32(i) - start) * growthRate));
|
2001-02-05 13:25:00 +03:00
|
|
|
UnescapeStr(uniBuffer, start, PRUint32(i) - start, tempString);
|
2000-03-03 09:49:23 +03:00
|
|
|
ScanTXT(tempString.GetUnicode(), tempString.Length(), whattodo, aOutString);
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-03 09:49:23 +03:00
|
|
|
#ifdef DEBUG_BenB_Perf
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("ScanHTML time: %d ms\n", PR_IntervalToMilliseconds(PR_IntervalNow() - parsing_start));
|
1999-12-05 19:56:04 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-12-08 05:10:57 +03:00
|
|
|
/****************************************************************************
|
|
|
|
XPCOM Interface
|
|
|
|
*****************************************************************************/
|
1999-12-08 01:20:02 +03:00
|
|
|
|
1999-12-08 05:10:57 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
mozTXTToHTMLConv::Convert(nsIInputStream *aFromStream,
|
|
|
|
const PRUnichar *aFromType,
|
|
|
|
const PRUnichar *aToType,
|
|
|
|
nsISupports *aCtxt, nsIInputStream **_retval)
|
1999-12-08 01:20:02 +03:00
|
|
|
{
|
1999-12-08 05:10:57 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-12-08 01:20:02 +03:00
|
|
|
}
|
|
|
|
|
1999-12-08 05:10:57 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
mozTXTToHTMLConv::AsyncConvertData(const PRUnichar *aFromType,
|
|
|
|
const PRUnichar *aToType,
|
|
|
|
nsIStreamListener *aListener, nsISupports *aCtxt) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-12-08 01:20:02 +03:00
|
|
|
}
|
|
|
|
|
1999-12-08 05:10:57 +03:00
|
|
|
NS_IMETHODIMP
|
2001-02-12 06:14:23 +03:00
|
|
|
mozTXTToHTMLConv::OnDataAvailable(nsIChannel *channel, nsISupports *ctxt,
|
1999-12-08 05:10:57 +03:00
|
|
|
nsIInputStream *inStr, PRUint32 sourceOffset,
|
|
|
|
PRUint32 count)
|
1999-12-08 01:20:02 +03:00
|
|
|
{
|
1999-12-08 05:10:57 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-12-08 01:20:02 +03:00
|
|
|
}
|
|
|
|
|
1999-12-08 05:10:57 +03:00
|
|
|
NS_IMETHODIMP
|
2001-02-12 06:14:23 +03:00
|
|
|
mozTXTToHTMLConv::OnStartRequest(nsIChannel *channel, nsISupports *ctxt)
|
1999-12-08 01:20:02 +03:00
|
|
|
{
|
1999-12-08 05:10:57 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-12-08 01:20:02 +03:00
|
|
|
}
|
|
|
|
|
1999-12-08 05:10:57 +03:00
|
|
|
NS_IMETHODIMP
|
2001-02-12 06:14:23 +03:00
|
|
|
mozTXTToHTMLConv::OnStopRequest(nsIChannel *channel, nsISupports *ctxt,
|
2000-07-25 09:45:56 +04:00
|
|
|
nsresult aStatus, const PRUnichar* aStatusArg)
|
1999-12-08 01:20:02 +03:00
|
|
|
{
|
1999-12-08 05:10:57 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-12-08 01:20:02 +03:00
|
|
|
}
|
1999-12-05 19:56:04 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozTXTToHTMLConv::CiteLevelTXT(const PRUnichar *line, PRUint32 *logLineStart,
|
|
|
|
PRUint32 *_retval)
|
|
|
|
{
|
|
|
|
if (!logLineStart || !_retval || !line)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
*_retval = CiteLevelTXT(line, *logLineStart);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-12-08 05:10:57 +03:00
|
|
|
mozTXTToHTMLConv::ScanTXT(const PRUnichar *text, PRUint32 whattodo,
|
|
|
|
PRUnichar **_retval)
|
1999-12-05 19:56:04 +03:00
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
NS_ENSURE_ARG(text);
|
|
|
|
|
|
|
|
// FIX ME!!!
|
|
|
|
nsString outString;
|
|
|
|
PRInt32 inLength = nsCRT::strlen(text);
|
|
|
|
// by setting a large capacity up front, we save time
|
|
|
|
// when appending characters to the output string because we don't
|
|
|
|
// need to reallocate and re-copy the characters already in the out String.
|
2000-03-07 23:49:48 +03:00
|
|
|
NS_ASSERTION(inLength, "ScanTXT passed 0 length string");
|
|
|
|
if (inLength == 0) {
|
2000-03-08 07:21:46 +03:00
|
|
|
*_retval = nsCRT::strdup(text);
|
|
|
|
return NS_OK;
|
2000-03-07 23:49:48 +03:00
|
|
|
}
|
2000-03-08 07:21:46 +03:00
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
outString.SetCapacity(PRUint32(inLength * growthRate));
|
2000-03-03 09:49:23 +03:00
|
|
|
ScanTXT(text, inLength, whattodo, outString);
|
|
|
|
|
|
|
|
*_retval = outString.ToNewUnicode();
|
2000-01-11 04:56:25 +03:00
|
|
|
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozTXTToHTMLConv::ScanHTML(const PRUnichar *text, PRUint32 whattodo,
|
|
|
|
PRUnichar **_retval)
|
|
|
|
{
|
2000-03-03 09:49:23 +03:00
|
|
|
NS_ENSURE_ARG(text);
|
|
|
|
|
|
|
|
// FIX ME!!!
|
|
|
|
nsString outString;
|
|
|
|
nsString inString (text); // look at this nasty extra copy of the entire input buffer!
|
2000-03-29 07:58:50 +04:00
|
|
|
outString.SetCapacity(PRUint32(inString.Length() * growthRate));
|
2000-03-03 09:49:23 +03:00
|
|
|
|
|
|
|
ScanHTML(inString, whattodo, outString);
|
|
|
|
*_retval = outString.ToNewUnicode();
|
2000-01-11 04:56:25 +03:00
|
|
|
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
1999-12-05 19:56:04 +03:00
|
|
|
}
|
|
|
|
|
2001-02-12 06:14:23 +03:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
Global functions
|
|
|
|
***************************************************************************/
|
1999-12-05 19:56:04 +03:00
|
|
|
nsresult
|
|
|
|
MOZ_NewTXTToHTMLConv(mozTXTToHTMLConv** aConv)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aConv != nsnull, "null ptr");
|
|
|
|
if (!aConv)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aConv = new mozTXTToHTMLConv();
|
|
|
|
if (!*aConv)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aConv);
|
|
|
|
// return (*aConv)->Init();
|
|
|
|
return NS_OK;
|
|
|
|
}
|