Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions
mozTXTToHTMLConv Class Reference

Description: Currently only functions to enhance plain text with HTML tags. More...

#include <mozTXTToHTMLConv.h>

Inheritance diagram for mozTXTToHTMLConv:
Inheritance graph
[legend]
Collaboration diagram for mozTXTToHTMLConv:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 mozTXTToHTMLConv ()
virtual ~mozTXTToHTMLConv ()
NS_DECL_ISUPPORTS
NS_DECL_MOZITXTTOHTMLCONV
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSISTREAMCONVERTER
void 
ScanTXT (const PRUnichar *aInString, PRInt32 aInStringLength, PRUint32 whattodo, nsString &aOutString)
 see mozITXTToHTMLConv::ScanTXT
void ScanHTML (nsString &aInString, PRUint32 whattodo, nsString &aOutString)
 see mozITXTToHTMLConv::ScanHTML.
PRInt32 CiteLevelTXT (const PRUnichar *line, PRUint32 &logLineStart)
 see mozITXTToHTMLConv::CiteLevelTXT
wstring scanTXT (in wstring text, in unsigned long whattodo)
wstring scanHTML (in wstring text, in unsigned long whattodo)
 Adds additional formatting to user edited text, that the user was too lazy or "unknowledged" (DELETEME: is that a word?) to make.
unsigned long citeLevelTXT (in wstring line, out unsigned long logLineStart)
void findURLInPlaintext (in wstring text, in long aLength, in long aPos, out long aStartPos, out long aEndPos)
nsIInputStream convert (in nsIInputStream aFromStream, in string aFromType, in string aToType, in nsISupports aCtxt)
 SYNCRONOUS VERSION Converts a stream of one type, to a stream of another type.
void asyncConvertData (in string aFromType, in string aToType, in nsIStreamListener aListener, in nsISupports aCtxt)
 ASYNCRONOUS VERSION Converts data arriving via the converter's nsIStreamListener::OnDataAvailable() method from one type to another, pushing the converted data out to the caller via aListener::OnDataAvailable().
void onDataAvailable (in nsIRequest aRequest, in nsISupports aContext, in nsIInputStream aInputStream, in unsigned long aOffset, in unsigned long aCount)
 Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.
void onStartRequest (in nsIRequest aRequest, in nsISupports aContext)
 Called to signify the beginning of an asynchronous request.
void onStopRequest (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatusCode)
 Called to signify the end of an asynchronous request.

Public Attributes

const unsigned long kEntities = 0
const unsigned long kURLs = 1 << 1
const unsigned long kGlyphSubstitution = 1 << 2
const unsigned long kStructPhrase = 1 << 3

Protected Member Functions

void CompleteAbbreviatedURL (const PRUnichar *aInString, PRInt32 aInLength, const PRUint32 pos, nsString &aOutString)
 Completes.

Protected Attributes

nsCOMPtr< nsIIOServicemIOService

Private Types

enum  LIMTYPE { LT_IGNORE, LT_DELIMITER, LT_ALPHA, LT_DIGIT }
enum  modetype {
  unknown, RFC1738, RFC2396E, freetext,
  abbreviated
}

Private Member Functions

PRBool ItMatchesDelimited (const PRUnichar *aInString, PRInt32 aInLength, const PRUnichar *rep, PRInt32 aRepLen, LIMTYPE before, LIMTYPE after)
PRUint32 NumberOfMatches (const PRUnichar *aInString, PRInt32 aInStringLength, const PRUnichar *rep, PRInt32 aRepLen, LIMTYPE before, LIMTYPE after)
void EscapeChar (const PRUnichar ch, nsString &aStringToAppendto)
 Currently only changes "<", ">" and "&".
void EscapeStr (nsString &aInString)
 See EscapeChar.
void UnescapeStr (const PRUnichar *aInString, PRInt32 aStartPos, PRInt32 aLength, nsString &aOutString)
 Currently only reverts "<", ">" and "&".
PRBool FindURL (const PRUnichar *aInString, PRInt32 aInLength, const PRUint32 pos, const PRUint32 whathasbeendone, nsString &outputHTML, PRInt32 &replaceBefore, PRInt32 &replaceAfter)
 Note: I use different strategies to pass context between the functions (full text and pos vs.
PRBool FindURLStart (const PRUnichar *aInString, PRInt32 aInLength, const PRUint32 pos, const modetype check, PRUint32 &start)
PRBool FindURLEnd (const PRUnichar *aInString, PRInt32 aInStringLength, const PRUint32 pos, const modetype check, const PRUint32 start, PRUint32 &end)
void CalculateURLBoundaries (const PRUnichar *aInString, PRInt32 aInStringLength, const PRUint32 pos, const PRUint32 whathasbeendone, const modetype check, const PRUint32 start, const PRUint32 end, nsString &txtURL, nsString &desc, PRInt32 &replaceBefore, PRInt32 &replaceAfter)
PRBool CheckURLAndCreateHTML (const nsString &txtURL, const nsString &desc, const modetype mode, nsString &outputHTML)
PRBool StructPhraseHit (const PRUnichar *aInString, PRInt32 aInStringLength, PRBool col0, const PRUnichar *tagTXT, PRInt32 aTagTxtLen, const char *tagHTML, const char *attributeHTML, nsString &aOutputString, PRUint32 &openTags)
PRBool SmilyHit (const PRUnichar *aInString, PRInt32 aLength, PRBool col0, const char *tagTXT, const char *imageName, nsString &outputHTML, PRInt32 &glyphTextLen)
PRBool GlyphHit (const PRUnichar *aInString, PRInt32 aInLength, PRBool col0, nsString &aOutString, PRInt32 &glyphTextLen)
 Checks, if we can replace some chars at the start of line with prettier HTML code.
PRBool ShouldLinkify (const nsCString &aURL)
 Check if a given url should be linkified.

Detailed Description

Description: Currently only functions to enhance plain text with HTML tags.

See mozITXTToHTMLConv. Stream conversion is defunct.

Definition at line 52 of file mozTXTToHTMLConv.h.


Member Enumeration Documentation

enum mozTXTToHTMLConv::LIMTYPE [private]
Enumerator:
LT_IGNORE 
LT_DELIMITER 
LT_ALPHA 
LT_DIGIT 

Definition at line 117 of file mozTXTToHTMLConv.h.

  {
    LT_IGNORE,     // limitation not checked
    LT_DELIMITER,  // not alphanumeric and not rep[0]. End of text is also ok.
    LT_ALPHA,      // alpha char
    LT_DIGIT
  };
Enumerator:
unknown 
RFC1738 
RFC2396E 
freetext 
abbreviated 

Definition at line 198 of file mozTXTToHTMLConv.h.

                {
         unknown,
         RFC1738,          /* Check, if RFC1738, APPENDIX compliant,
                              like "<URL:http://www.mozilla.org>". */
         RFC2396E,         /* RFC2396, APPENDIX E allows anglebrackets (like
                              "<http://www.mozilla.org>") (without "URL:") or
                              quotation marks(like ""http://www.mozilla.org"").
                              Also allow email addresses without scheme,
                              e.g. "<mozilla@bucksch.org>" */
         freetext,         /* assume heading scheme
                              with "[a-zA-Z][a-zA-Z0-9+\-\.]*:" like "news:"
                              (see RFC2396, Section 3.1).
                              Certain characters (see code) or any whitespace
                              (including linebreaks) end the URL.
                              Other certain (punctation) characters (see code)
                              at the end are stripped off. */
         abbreviated       /* Similar to freetext, but without scheme, e.g.
                             "www.mozilla.org", "ftp.mozilla.org" and
                              "mozilla@bucksch.org". */
      /* RFC1738 and RFC2396E type URLs may use multiple lines,
         whitespace is stripped. Special characters like ")" stay intact.*/
  };

Constructor & Destructor Documentation

Definition at line 1014 of file mozTXTToHTMLConv.cpp.

{
  MOZ_TIMER_RESET(mScanTXTTimer);
  MOZ_TIMER_RESET(mGlyphHitTimer);
  MOZ_TIMER_RESET(mTotalMimeTime);
  MOZ_TIMER_START(mTotalMimeTime);
}

Definition at line 1022 of file mozTXTToHTMLConv.cpp.

{
  MOZ_TIMER_STOP(mTotalMimeTime);
  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);
}

Member Function Documentation

void nsIStreamConverter::asyncConvertData ( in string  aFromType,
in string  aToType,
in nsIStreamListener  aListener,
in nsISupports  aCtxt 
) [inherited]

ASYNCRONOUS VERSION Converts data arriving via the converter's nsIStreamListener::OnDataAvailable() method from one type to another, pushing the converted data out to the caller via aListener::OnDataAvailable().

Use this method when you want to proxy (and convert) nsIStreamListener callbacks asynchronously.

Parameters:
aFromTypeThe MIME type of the original/raw data.
aToTypeThe MIME type of the converted data.
aListenerThe listener who receives the converted data.
aCtxtEither an opaque context, or a converter specific context (implementation specific).
void mozTXTToHTMLConv::CalculateURLBoundaries ( const PRUnichar aInString,
PRInt32  aInStringLength,
const PRUint32  pos,
const PRUint32  whathasbeendone,
const modetype  check,
const PRUint32  start,
const PRUint32  end,
nsString txtURL,
nsString desc,
PRInt32 replaceBefore,
PRInt32 replaceAfter 
) [private]
Parameters:
text(in), pos (in), whathasbeendone (in): see FindURL
check(in): Current mode
start(in), end (in): see FindURLEnd
txtURL(out): Guessed (raw) URL. Without whitespace, but not completed.
desc(out): Link as shown to the user, but already escaped. Should be placed between the and tags.
replaceBefore(out),replaceAfter(out): see FindURL

Definition at line 355 of file mozTXTToHTMLConv.cpp.

{
  PRUint32 descstart = start;
  switch(check)
  {
  case RFC1738:
  {
    descstart = start - 5;
    desc.Append(&aInString[descstart], end - descstart + 2);  // include "<URL:" and ">"
    replaceAfter = end - pos + 1;
  } break;
  case RFC2396E:
  {
    descstart = start - 1;
    desc.Append(&aInString[descstart], end - descstart + 2); // include brackets
    replaceAfter = end - pos + 1;
  } break;
  case freetext:
  case abbreviated:
  {
    descstart = start;
    desc.Append(&aInString[descstart], end - start + 1); // don't include brackets  
    replaceAfter = end - pos;
  } break;
  default: break;
  } //switch

  EscapeStr(desc);

  txtURL.Append(&aInString[start], end - start + 1);
  txtURL.StripWhitespace();

  // FIX ME
  nsAutoString temp2;
  ScanTXT(&aInString[descstart], pos - descstart, ~kURLs /*prevents loop*/ & whathasbeendone, temp2);
  replaceBefore = temp2.Length();
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool mozTXTToHTMLConv::CheckURLAndCreateHTML ( const nsString txtURL,
const nsString desc,
const modetype  mode,
nsString outputHTML 
) [private]
Parameters:
txtURL(in), desc (in): see CalculateURLBoundaries
outputHTML(out): see FindURL
Returns:
A valid URL could be found (and creation of HTML successful)

Definition at line 426 of file mozTXTToHTMLConv.cpp.

{
  // Create *uri from txtURL
  nsCOMPtr<nsIURI> uri;
  nsresult rv = NS_OK;
  if (!mIOService)
    mIOService = do_GetService(kIOServiceCID, &rv);
  
  if (NS_FAILED(rv) || !mIOService)
    return PR_FALSE;

  // See if the url should be linkified.
  NS_ConvertUCS2toUTF8 utf8URL(txtURL);
  if (!ShouldLinkify(utf8URL))
    return PR_FALSE;

  // 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(utf8URL, nsnull, nsnull, getter_AddRefs(uri));

  // Real work
  if (NS_SUCCEEDED(rv) && uri)
  {
    outputHTML.AssignLiteral("<a class=\"moz-txt-link-");
    switch(mode)
    {
    case RFC1738:
      outputHTML.AppendLiteral("rfc1738");
      break;
    case RFC2396E:
      outputHTML.AppendLiteral("rfc2396E");
      break;
    case freetext:
      outputHTML.AppendLiteral("freetext");
      break;
    case abbreviated:
      outputHTML.AppendLiteral("abbreviated");
      break;
    default: break;
    }
    outputHTML.AppendLiteral("\" href=\"");
    outputHTML += txtURL;
    outputHTML.AppendLiteral("\">");
    outputHTML += desc;
    outputHTML.AppendLiteral("</a>");
    return PR_TRUE;
  }
  else
    return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

see mozITXTToHTMLConv::CiteLevelTXT

Definition at line 1038 of file mozTXTToHTMLConv.cpp.

{
  PRInt32 result = 0;
  PRInt32 lineLength = nsCRT::strlen(line);

  PRBool moreCites = PR_TRUE;
  while (moreCites)
  {
    /* E.g. the following lines count as quote:

       > text
       //#ifdef QUOTE_RECOGNITION_AGGRESSIVE
       >text
       //#ifdef QUOTE_RECOGNITION_AGGRESSIVE
           > text
       ] text
       USER> text
       USER] text
       //#endif

       logLineStart is the position of "t" in this example
    */
    PRUint32 i = logLineStart;

#ifdef QUOTE_RECOGNITION_AGGRESSIVE
    for (; PRInt32(i) < lineLength && IsSpace(line[i]); i++)
      ;
    for (; PRInt32(i) < lineLength && nsCRT::IsAsciiAlpha(line[i])
                                   && nsCRT::IsUpper(line[i])   ; i++)
      ;
    if (PRInt32(i) < lineLength && (line[i] == '>' || line[i] == ']'))
#else
    if (PRInt32(i) < lineLength && line[i] == '>')
#endif
    {
      i++;
      if (PRInt32(i) < lineLength && line[i] == ' ')
        i++;
      // sendmail/mbox
      // Placed here for performance increase
      const PRUnichar * indexString = &line[logLineStart];
           // here, |logLineStart < lineLength| is always true
      PRUint32 minlength = MinInt(6,nsCRT::strlen(indexString));
      if (Substring(indexString,
                    indexString+minlength).Equals(Substring(NS_LITERAL_STRING(">From "), 0, minlength),
                                                  nsCaseInsensitiveStringComparator()))
        //XXX RFC2646
        moreCites = PR_FALSE;
      else
      {
        result++;
        logLineStart = i;
      }
    }
    else
      moreCites = PR_FALSE;
  }

  return result;
}

Here is the call graph for this function:

unsigned long mozITXTToHTMLConv::citeLevelTXT ( in wstring  line,
out unsigned long  logLineStart 
) [inherited]
Parameters:
line,:line in original msg, possibly starting starting with txt quote tags like ">"
logLineStart,:pos in line, where the real content (logical line) begins, i.e. pos after all txt quote tags. E.g. position of "t" in "> > text". Initial value must be 0, unless line is not real line.
Returns:
Cite Level, i.e. number of txt quote tags found, i.e. number of nested quotes.
void mozTXTToHTMLConv::CompleteAbbreviatedURL ( const PRUnichar aInString,
PRInt32  aInLength,
const PRUint32  pos,
nsString aOutString 
) [protected]

Completes.

  • Case 1: mailto: "mozilla@bucksch.org" -> "mailto:mozilla@bucksch.org"
  • Case 2: http: "www.mozilla.org" -> "http://www.mozilla.org"
  • Case 3: ftp: "ftp.mozilla.org" -> "ftp://www.mozilla.org"

It does no check, if the resulting URL is valid.

Parameters:
text(in): abbreviated URL
pos(in): position of "@" (case 1) or first "." (case 2 and 3)
Returns:
Completed URL at success and empty string at failure

Definition at line 164 of file mozTXTToHTMLConv.cpp.

{
  NS_ASSERTION(pos < aInLength, "bad args to CompleteAbbreviatedURL, see bug #190851");
  if (pos >= aInLength)
    return;

  if (aInString[pos] == '@')
  {
    // only pre-pend a mailto url if the string contains a .domain in it..
    //i.e. we want to linkify johndoe@foo.com but not "let's meet @8pm"
    nsDependentString inString(aInString, aInLength);
    if (inString.FindChar('.', pos) != kNotFound) // if we have a '.' after the @ sign....
    {
      aOutString.AssignLiteral("mailto:");
      aOutString += aInString;
    }
  }
  else if (aInString[pos] == '.')
  {
    if (ItMatchesDelimited(aInString, aInLength,
                           NS_LITERAL_STRING("www.").get(), 4, LT_IGNORE, LT_IGNORE))
    {
      aOutString.AssignLiteral("http://");
      aOutString += aInString;
    }
    else if (ItMatchesDelimited(aInString,aInLength, NS_LITERAL_STRING("ftp.").get(), 4, LT_IGNORE, LT_IGNORE))
    { 
      aOutString.AssignLiteral("ftp://");
      aOutString += aInString;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIInputStream nsIStreamConverter::convert ( in nsIInputStream  aFromStream,
in string  aFromType,
in string  aToType,
in nsISupports  aCtxt 
) [inherited]

SYNCRONOUS VERSION Converts a stream of one type, to a stream of another type.

Use this method when you have a stream you want to convert.

Parameters:
aFromStreamThe stream representing the original/raw data.
aFromTypeThe MIME type of aFromStream.
aToTypeThe MIME type of the returned stream.
aCtxtEither an opaque context, or a converter specific context (implementation specific).
Returns:
The converted stream. NOTE: The returned stream may not already be converted. An efficient stream converter implementation will converter data on demand rather than buffering the converted data until it is used.
void mozTXTToHTMLConv::EscapeChar ( const PRUnichar  ch,
nsString aStringToAppendto 
) [private]

Currently only changes "<", ">" and "&".

All others stay as they are.

"Char" in function name to avoid side effects with nsString(ch) constructors.

Parameters:
ch(in)
aStringToAppendto(out) - the string to append the escaped string to.

Definition at line 67 of file mozTXTToHTMLConv.cpp.

{
    switch (ch)
    {
    case '<':
      aStringToAppendTo.AppendLiteral("&lt;");
      break;
    case '>':
      aStringToAppendTo.AppendLiteral("&gt;");
      break;
    case '&':
      aStringToAppendTo.AppendLiteral("&amp;");
      break;
    default:
      aStringToAppendTo += ch;
    }

    return;
}

Here is the caller graph for this function:

void mozTXTToHTMLConv::EscapeStr ( nsString aInString) [private]

See EscapeChar.

Escapes the string in place.

Definition at line 90 of file mozTXTToHTMLConv.cpp.

{
  // 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("&", "&amp;");
  //aInString.ReplaceSubstring("<", "&lt;");
  //aInString.ReplaceSubstring(">", "&gt;");
  for (PRUint32 i = 0; i < aInString.Length();)
  {
    switch (aInString[i])
    {
    case '<':
      aInString.Cut(i, 1);
      aInString.Insert(NS_LITERAL_STRING("&lt;"), i);
      i += 4; // skip past the integers we just added
      break;
    case '>':
      aInString.Cut(i, 1);
      aInString.Insert(NS_LITERAL_STRING("&gt;"), i);
      i += 4; // skip past the integers we just added
      break;
    case '&':
      aInString.Cut(i, 1);
      aInString.Insert(NS_LITERAL_STRING("&amp;"), i);
      i += 5; // skip past the integers we just added
      break;
    default:
      i++;
    }
  }
}

Here is the caller graph for this function:

PRBool mozTXTToHTMLConv::FindURL ( const PRUnichar aInString,
PRInt32  aInLength,
const PRUint32  pos,
const PRUint32  whathasbeendone,
nsString outputHTML,
PRInt32 replaceBefore,
PRInt32 replaceAfter 
) [private]

Note: I use different strategies to pass context between the functions (full text and pos vs.

cutted text and col0, glphyTextLen vs. replaceBefore/-After). It makes some sense, but is hard to understand (maintain) :-(.

Note: replaceBefore + replaceAfter + 1 (for char at pos) chars in text should be replaced by outputHTML.

Note: This function should be able to process a URL on multiple lines, but currently, ScanForURLs is called for every line, so it can't.

Parameters:
text(in): includes possibly a URL
pos(in): position in text, where either ":", "." or "@" are found
whathasbeendone(in): What the calling ScanTXT did/has to do with the (not-linkified) text, i.e. usually the "whattodo" parameter. (Needed to calculate replaceBefore.) NOT what will be done with the content of the link.
outputHTML(out): URL with HTML-a tag
replaceBefore(out): Number of chars of URL before pos
replaceAfter(out): Number of chars of URL after pos
Returns:
URL found

Definition at line 493 of file mozTXTToHTMLConv.cpp.

{
  enum statetype {unchecked, invalid, startok, endok, success};
  static const modetype ranking[] = {RFC1738, RFC2396E, freetext, abbreviated};

  statetype state[mozTXTToHTMLConv_lastMode + 1]; // 0(=unknown)..lastMode
  /* 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 '@' */
  for (modetype iState = unknown; iState <= mozTXTToHTMLConv_lastMode;
       iState = modetype(iState + 1))
    state[iState] = aInString[pos] == ':' ? unchecked : invalid;
  switch (aInString[pos])
  {
  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|
  PRInt32 iCheck = 0;  // the currently tested modetype
  modetype check = ranking[iCheck];
  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 */
  {
    check = ranking[iCheck];

    PRUint32 start, end;

    if (state[check] == unchecked)
      if (FindURLStart(aInString, aInLength, pos, check, start))
        state[check] = startok;

    if (state[check] == startok)
      if (FindURLEnd(aInString, aInLength, pos, check, start, end))
        state[check] = endok;

    if (state[check] == endok)
    {
      nsAutoString txtURL, desc;
      PRInt32 resultReplaceBefore, resultReplaceAfter;

      CalculateURLBoundaries(aInString, aInLength, pos, whathasbeendone, check, start, end,
                             txtURL, desc,
                             resultReplaceBefore, resultReplaceAfter);

      if (aInString[pos] != ':')
      {
        nsAutoString temp = txtURL;
        txtURL.SetLength(0);
        CompleteAbbreviatedURL(temp.get(),temp.Length(), pos - start, txtURL);
      }

      if (!txtURL.IsEmpty() && CheckURLAndCreateHTML(txtURL, desc, check,
                                                     outputHTML))
      {
        replaceBefore = resultReplaceBefore;
        replaceAfter = resultReplaceAfter;
        state[check] = success;
      }
    } // if
  } // for
  return state[check] == success;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool mozTXTToHTMLConv::FindURLEnd ( const PRUnichar aInString,
PRInt32  aInStringLength,
const PRUint32  pos,
const modetype  check,
const PRUint32  start,
PRUint32 end 
) [private]
Parameters:
text(in), pos (in): see FindURL
check(in): End must be conform with this mode
start(in): see FindURLStart
end(out): Similar to |start| param of FindURLStart
Returns:
|check|-conform end has been found

Definition at line 287 of file mozTXTToHTMLConv.cpp.

{
  switch(check)
  { // no breaks, because end of blocks is never reached
  case RFC1738:
  case RFC2396E:
  {
    nsString temp(aInString, aInStringLength);

    PRInt32 i = temp.FindCharInSet(NS_LITERAL_STRING("<>\"").get(), pos + 1);
    if (i != kNotFound && temp[PRUint32(i--)] ==
        (check == RFC1738 || temp[start - 1] == '<' ? '>' : '"'))
    {
      end = PRUint32(i);
      return end > pos;
    }
    else
      return PR_FALSE;
  }
  case freetext:
  case abbreviated:
  {
    PRUint32 i = pos + 1;
    PRBool isEmail = aInString[pos] == (PRUnichar)'@';
    PRBool haveOpeningBracket = PR_FALSE;
    for (; PRInt32(i) < aInStringLength; i++)
    {
      // These chars mark the end of the URL
      if (aInString[i] == '>' || aInString[i] == '<' ||
          aInString[i] == '"' || aInString[i] == '`' ||
          aInString[i] == '}' || aInString[i] == ']' ||
          aInString[i] == '{' || aInString[i] == '[' ||
          aInString[i] == '|' ||
          (aInString[i] == ')' && !haveOpeningBracket) ||
          IsSpace(aInString[i])    )
          break;
      // Disallow non-ascii-characters for email.
      // Currently correct, but revisit later after standards changed.
      if (isEmail && (
            aInString[i] == '(' || aInString[i] == '\'' ||
            !nsCRT::IsAscii(aInString[i])       ))
          break;
      if (aInString[i] == '(')
        haveOpeningBracket = PR_TRUE;
    }
    // These chars are allowed in the middle of the URL, but not at end.
    // Technically they are, but are used in normal text after the URL.
    while (--i > pos && (
             aInString[i] == '.' || aInString[i] == ',' || aInString[i] == ';' ||
             aInString[i] == '!' || aInString[i] == '?' || aInString[i] == '-' ||
             aInString[i] == '\''
             ))
        ;
    if (i > pos)
    {
      end = i;
      return PR_TRUE;
    }
    else
      return PR_FALSE;
  }
  default:
    return PR_FALSE;
  } //switch
}

Here is the call graph for this function:

Here is the caller graph for this function:

void mozITXTToHTMLConv::findURLInPlaintext ( in wstring  text,
in long  aLength,
in long  aPos,
out long  aStartPos,
out long  aEndPos 
) [inherited]
Parameters:
awide string to scan for the presence of a URL.
aLength--> the length of the buffer to be scanned
aPos--> the position in the buffer to start scanning for a url

aStartPos --> index into the start of a url (-1 if no url found) aEndPos --> index of the last character in the url (-1 if no url found)

PRBool mozTXTToHTMLConv::FindURLStart ( const PRUnichar aInString,
PRInt32  aInLength,
const PRUint32  pos,
const modetype  check,
PRUint32 start 
) [private]
Parameters:
text(in), pos (in): see FindURL
check(in): Start must be conform with this mode
start(out): Position in text, where URL (including brackets or similar) starts
Returns:
|check|-conform start has been found

Definition at line 199 of file mozTXTToHTMLConv.cpp.

{
  switch(check)
  { // no breaks, because end of blocks is never reached
  case RFC1738:
  {
    if (!nsCRT::strncmp(&aInString[MaxInt(pos - 4, 0)], NS_LITERAL_STRING("<URL:").get(), 5))
    {
      start = pos + 1;
      return PR_TRUE;
    }
    else
      return PR_FALSE;
  }
  case RFC2396E:
  {
    nsString temp(aInString, aInLength);
    PRInt32 i = pos <= 0 ? kNotFound : temp.RFindCharInSet(NS_LITERAL_STRING("<>\"").get(), pos - 1);
    if (i != kNotFound && (temp[PRUint32(i)] == '<' ||
                           temp[PRUint32(i)] == '"'))
    {
      start = PRUint32(++i);
      return start < pos;
    }
    else
      return PR_FALSE;
  }
  case freetext:
  {
    PRInt32 i = pos - 1;
    for (; i >= 0 && (
         nsCRT::IsAsciiAlpha(aInString[PRUint32(i)]) ||
         nsCRT::IsAsciiDigit(aInString[PRUint32(i)]) ||
         aInString[PRUint32(i)] == '+' ||
         aInString[PRUint32(i)] == '-' ||
         aInString[PRUint32(i)] == '.'
         ); i--)
      ;
    if (++i >= 0 && i < pos && nsCRT::IsAsciiAlpha(aInString[PRUint32(i)]))
    {
      start = PRUint32(i);
      return PR_TRUE;
    }
    else
      return PR_FALSE;
  }
  case abbreviated:
  {
    PRInt32 i = pos - 1;
    // This disallows non-ascii-characters for email.
    // Currently correct, but revisit later after standards changed.
    PRBool isEmail = aInString[pos] == (PRUnichar)'@';
    // These chars mark the start of the URL
    for (; i >= 0
             && 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)] != '\\'
             && !IsSpace(aInString[PRUint32(i)])
             && (!isEmail || nsCRT::IsAscii(aInString[PRUint32(i)]))
         ; i--)
      ;
    if
      (
        ++i >= 0 && i < pos
          &&
          (
            nsCRT::IsAsciiAlpha(aInString[PRUint32(i)]) ||
            nsCRT::IsAsciiDigit(aInString[PRUint32(i)])
          )
      )
    {
      start = PRUint32(i);
      return PR_TRUE;
    }
    else
      return PR_FALSE;
  }
  default:
    return PR_FALSE;
  } //switch
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool mozTXTToHTMLConv::GlyphHit ( const PRUnichar aInString,
PRInt32  aInLength,
PRBool  col0,
nsString aOutString,
PRInt32 glyphTextLen 
) [private]

Checks, if we can replace some chars at the start of line with prettier HTML code.

If success is reported, replace the first glyphTextLen chars with outputHTML

Parameters:
text(in): line of text possibly with Glyph.

If col0 is true, starting with Glyph
else starting one char before Glyph

Parameters:
col0(in): text starts at the beginning of the line (or paragraph)
aOutString(out): APPENDS html for the glyph to this string
glyphTextLen(out): Length of original text to replace
Returns:
see StructPhraseHit

Definition at line 766 of file mozTXTToHTMLConv.cpp.

{
  MOZ_TIMER_START(mGlyphHitTimer);

  PRUnichar text0 = aInString[0]; 
  PRUnichar text1 = aInString[1];
  PRUnichar firstChar = (col0 ? text0 : text1);

  // temporary variable used to store the glyph html text
  nsAutoString outputHTML;
  PRBool bTestSmilie;
  PRBool bArg;
  int i;

  // refactor some of this mess to avoid code duplication and speed execution a bit
  // there are two cases that need to be tried one after another. To avoid a lot of
  // duplicate code, rolling into a loop

  i = 0;
  while ( i < 2 )
  {
    bTestSmilie = PR_FALSE;
    if ( !i && (firstChar == ':' || firstChar == ';' || firstChar == '=' || firstChar == '>' || firstChar == '8' || firstChar == 'O'))
    {
        // first test passed

        bTestSmilie = PR_TRUE;
        bArg = col0;
    }
    if ( i && col0 && ( text1 == ':' || text1 == ';' || text1 == '=' || text1 == '>' || text1 == '8' || text1 == 'O' ) )
    {
        // second test passed

        bTestSmilie = PR_TRUE;
        bArg = PR_FALSE;
    }
    if ( bTestSmilie && (
          SmilyHit(aInString, aInLength, bArg,
                   ":-)",
                   "moz-smiley-s1", // smile
                   outputHTML, glyphTextLen) ||
  
          SmilyHit(aInString, aInLength, bArg,
                   ":)",
                   "moz-smiley-s1", // smile
                   outputHTML, glyphTextLen) ||
          
          SmilyHit(aInString, aInLength, bArg,
                   ":-D",
                   "moz-smiley-s5", // laughing
                   outputHTML, glyphTextLen) ||
          
          SmilyHit(aInString, aInLength, bArg,
                   ":-(",
                   "moz-smiley-s2", // frown
                   outputHTML, glyphTextLen) ||
          
          SmilyHit(aInString, aInLength, bArg,
                   ":(",
                   "moz-smiley-s2", // frown
                   outputHTML, glyphTextLen) ||
          
          SmilyHit(aInString, aInLength, bArg,
                   ":-[",
                   "moz-smiley-s6", // embarassed
                   outputHTML, glyphTextLen) ||
          
          SmilyHit(aInString, aInLength, bArg,
                   ";-)",
                   "moz-smiley-s3", // wink
                   outputHTML, glyphTextLen) ||

          SmilyHit(aInString, aInLength, col0,
                   ";)",
                   "moz-smiley-s3", // wink
                   outputHTML, glyphTextLen) ||
          
          SmilyHit(aInString, aInLength, bArg,
                   ":-\\",
                   "moz-smiley-s7", // undecided
                   outputHTML, glyphTextLen) ||
          
          SmilyHit(aInString, aInLength, bArg,
                   ":-P",
                   "moz-smiley-s4", // tongue
                   outputHTML, glyphTextLen) ||
                   
          SmilyHit(aInString, aInLength, bArg,
                   ";-P",
                   "moz-smiley-s4", // tongue
                   outputHTML, glyphTextLen) ||  
         
          SmilyHit(aInString, aInLength, bArg,
                   "=-O",
                   "moz-smiley-s8", // surprise
                   outputHTML, glyphTextLen) ||
         
          SmilyHit(aInString, aInLength, bArg,
                   ":-*",
                   "moz-smiley-s9", // kiss
                   outputHTML, glyphTextLen) ||
         
          SmilyHit(aInString, aInLength, bArg,
                   ">:o",
                   "moz-smiley-s10", // yell
                   outputHTML, glyphTextLen) ||
          
          SmilyHit(aInString, aInLength, bArg,
                   ">:-o",
                   "moz-smiley-yell", // yell
                   outputHTML, glyphTextLen) ||
        
          SmilyHit(aInString, aInLength, bArg,
                   "8-)",
                   "moz-smiley-s11", // cool
                   outputHTML, glyphTextLen) ||
         
          SmilyHit(aInString, aInLength, bArg,
                   ":-$",
                   "moz-smiley-s12", // money
                   outputHTML, glyphTextLen) ||
         
          SmilyHit(aInString, aInLength, bArg,
                   ":-!",
                   "moz-smiley-s13", // foot
                   outputHTML, glyphTextLen) ||
         
          SmilyHit(aInString, aInLength, bArg,
                   "O:-)",
                   "moz-smiley-s14", // innocent
                   outputHTML, glyphTextLen) ||
         
          SmilyHit(aInString, aInLength, bArg,
                   ":'(",
                   "moz-smiley-s15", // cry
                   outputHTML, glyphTextLen) ||
         
          SmilyHit(aInString, aInLength, bArg,
                   ":-X",
                   "moz-smiley-s16", // sealed
                   outputHTML, glyphTextLen) 
        )
    )
    {
        aOutputString.Append(outputHTML);
        MOZ_TIMER_STOP(mGlyphHitTimer);
        return PR_TRUE;
    }
    i++;
  }
  if (text0 == '\f')
  {
      aOutputString.AppendLiteral("<span class='moz-txt-formfeed'></span>");
      glyphTextLen = 1;
      MOZ_TIMER_STOP(mGlyphHitTimer);
      return PR_TRUE;
  }
  if (text0 == '+' || text1 == '+')
  {
    if (ItMatchesDelimited(aInString, aInLength,
                           NS_LITERAL_STRING(" +/-").get(), 4,
                           LT_IGNORE, LT_IGNORE))
    {
      aOutputString.AppendLiteral(" &plusmn;");
      glyphTextLen = 4;
      MOZ_TIMER_STOP(mGlyphHitTimer);
      return PR_TRUE;
    }
    if (col0 && ItMatchesDelimited(aInString, aInLength,
                                   NS_LITERAL_STRING("+/-").get(), 3,
                                   LT_IGNORE, LT_IGNORE))
    {
      aOutputString.AppendLiteral("&plusmn;");
      glyphTextLen = 3;
      MOZ_TIMER_STOP(mGlyphHitTimer);
      return PR_TRUE;
    }
  }

  // x^2  =>  x<sup>2</sup>,   also handle powers x^-2,  x^0.5
  // implement regular expression /[\dA-Za-z\)\]}]\^-?\d+(\.\d+)*[^\dA-Za-z]/
  if    
    (
      text1 == '^'
      && 
      (
        nsCRT::IsAsciiDigit(text0) || nsCRT::IsAsciiAlpha(text0) || 
        text0 == ')' || text0 == ']' || text0 == '}'
      )
      &&
      (
        2 < aInLength && nsCRT::IsAsciiDigit(aInString[2]) ||
        3 < aInLength && aInString[2] == '-' && nsCRT::IsAsciiDigit(aInString[3])
      )
    )
  {
    // Find first non-digit
    PRInt32 delimPos = 3;  // skip "^" and first digit (or '-')
    for (; delimPos < aInLength
           &&
           (
             nsCRT::IsAsciiDigit(aInString[delimPos]) || 
             aInString[delimPos] == '.' && delimPos + 1 < aInLength &&
               nsCRT::IsAsciiDigit(aInString[delimPos + 1])
           );
         delimPos++)
      ;

    if (delimPos < aInLength && nsCRT::IsAsciiAlpha(aInString[delimPos]))
    {
      MOZ_TIMER_STOP(mGlyphHitTimer);
      return PR_FALSE;
    }

    outputHTML.Truncate();
    outputHTML += text0;
    outputHTML.AppendLiteral("<sup class=\"moz-txt-sup\">");

    aOutputString.Append(outputHTML);
    aOutputString.Append(&aInString[2], delimPos - 2);
    aOutputString.AppendLiteral("</sup>");

    glyphTextLen = delimPos /* - 1 + 1 */ ;
    MOZ_TIMER_STOP(mGlyphHitTimer);
    return PR_TRUE;
  }
  /*
   The following strings are not substituted:
   |TXT   |HTML     |Reason
   +------+---------+----------
    ->     &larr;    Bug #454
    =>     &lArr;    dito
    <-     &rarr;    dito
    <=     &rArr;    dito
    (tm)   &trade;   dito
    1/4    &frac14;  is triggered by 1/4 Part 1, 2/4 Part 2, ...
    3/4    &frac34;  dito
    1/2    &frac12;  similar
  */
  MOZ_TIMER_STOP(mGlyphHitTimer);
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool mozTXTToHTMLConv::ItMatchesDelimited ( const PRUnichar aInString,
PRInt32  aInLength,
const PRUnichar rep,
PRInt32  aRepLen,
LIMTYPE  before,
LIMTYPE  after 
) [private]
Parameters:
text(in): the string to search through.

If before = IGNORE,
rep is compared starting at 1. char of text (text[0]),
else starting at 2. char of text (text[1]). Chars after "after"-delimiter are ignored.

Parameters:
rep(in): the string to look for
aRepLen(in): the number of bytes in the string to look for
before(in): limitation before rep
after(in): limitation after rep
Returns:
true, if rep is found and limitation spec is met or rep is empty

Definition at line 574 of file mozTXTToHTMLConv.cpp.

{

  // 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;

  if
    (
      (before == LT_IGNORE && (after == LT_IGNORE || after == LT_DELIMITER))
        && textLen < aRepLen ||
      (before != LT_IGNORE || after != LT_IGNORE && after != LT_DELIMITER)
        && textLen < aRepLen + 1 ||
      before != LT_IGNORE && after != LT_IGNORE && after != LT_DELIMITER
        && textLen < aRepLen + 2
    )
    return PR_FALSE;

  PRUnichar text0 = aInString[0];
  PRUnichar textAfterPos = aInString[aRepLen + (before == LT_IGNORE ? 0 : 1)];

  if
    (
      before == LT_ALPHA
        && !nsCRT::IsAsciiAlpha(text0) ||
      before == LT_DIGIT
        && !nsCRT::IsAsciiDigit(text0) ||
      before == LT_DELIMITER
        &&
        (
          nsCRT::IsAsciiAlpha(text0) ||
          nsCRT::IsAsciiDigit(text0) ||
          text0 == *rep
        ) ||
      after == LT_ALPHA
        && !nsCRT::IsAsciiAlpha(textAfterPos) ||
      after == LT_DIGIT
        && !nsCRT::IsAsciiDigit(textAfterPos) ||
      after == LT_DELIMITER
        &&
        (
          nsCRT::IsAsciiAlpha(textAfterPos) ||
          nsCRT::IsAsciiDigit(textAfterPos) ||
          textAfterPos == *rep
        ) ||
        !Substring(Substring(aInString, aInString+aInLength),
                   (before == LT_IGNORE ? 0 : 1),
                   aRepLen).Equals(Substring(rep, rep+aRepLen),
                                   nsCaseInsensitiveStringComparator())
    )
    return PR_FALSE;

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRUint32 mozTXTToHTMLConv::NumberOfMatches ( const PRUnichar aInString,
PRInt32  aInStringLength,
const PRUnichar rep,
PRInt32  aRepLen,
LIMTYPE  before,
LIMTYPE  after 
) [private]
Parameters:
seeItMatchesDelimited
Returns:
Number of ItMatchesDelimited in text

Definition at line 634 of file mozTXTToHTMLConv.cpp.

{
  PRUint32 result = 0;

  for (PRInt32 i = 0; i < aInStringLength; i++)
  {
    const PRUnichar * indexIntoString = &aInString[i];
    if (ItMatchesDelimited(indexIntoString, aInStringLength - i, rep, aRepLen, before, after))
      result++;
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIStreamListener::onDataAvailable ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsIInputStream  aInputStream,
in unsigned long  aOffset,
in unsigned long  aCount 
) [inherited]

Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.

The onDataAvailable impl must read exactly |aCount| bytes of data before returning.

Parameters:
aRequestrequest corresponding to the source of the data
aContextuser defined context
aInputStreaminput stream containing the data chunk
aOffsetNumber of bytes that were sent in previous onDataAvailable calls for this request. In other words, the sum of all previous count parameters. If that number is greater than or equal to 2^32, this parameter will be PR_UINT32_MAX (2^32 - 1).
aCountnumber of bytes available in the stream

NOTE: The aInputStream parameter must implement readSegments.

An exception thrown from onDataAvailable has the side-effect of causing the request to be canceled.

void nsIRequestObserver::onStartRequest ( in nsIRequest  aRequest,
in nsISupports  aContext 
) [inherited]

Called to signify the beginning of an asynchronous request.

Parameters:
aRequestrequest being observed
aContextuser defined context

An exception thrown from onStartRequest has the side-effect of causing the request to be canceled.

Here is the caller graph for this function:

void nsIRequestObserver::onStopRequest ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatusCode 
) [inherited]

Called to signify the end of an asynchronous request.

This call is always preceded by a call to onStartRequest.

Parameters:
aRequestrequest being observed
aContextuser defined context
aStatusCodereason for stopping (NS_OK if completed successfully)

An exception thrown from onStopRequest is generally ignored.

Here is the caller graph for this function:

NS_IMETHODIMP mozTXTToHTMLConv::ScanHTML ( nsString aInString,
PRUint32  whattodo,
nsString aOutString 
)

see mozITXTToHTMLConv::ScanHTML.

We will modify aInString potentially...

Definition at line 1232 of file mozTXTToHTMLConv.cpp.

{ 
  // some common variables we were recalculating
  // every time inside the for loop...
  PRInt32 lengthOfInString = aInString.Length();
  const PRUnichar * uniBuffer = aInString.get();

#ifdef DEBUG_BenB_Perf
  PRTime parsing_start = PR_IntervalNow();
#endif

  // Look for simple entities not included in a tags and scan them.
  /* Skip all tags ("<[...]>") and content in an a tag ("<a[...]</a>")
     or in a tag ("<!--[...]-->").
     Unescape the rest (text between tags) and pass it to ScanTXT. */
  for (PRInt32 i = 0; PRUint32(i) < lengthOfInString;)
  {
    if (aInString[i] == '<')  // html tag
    {
      PRUint32 start = PRUint32(i);
      if (nsCRT::ToLower((char)aInString[PRUint32(i) + 1]) == 'a')
           // if a tag, skip until </a>
      {
        i = aInString.Find("</a>", PR_TRUE, i);
        if (i == kNotFound)
          i = lengthOfInString;
        else
          i += 4;
      }
      else if (aInString[PRUint32(i) + 1] == '!' && aInString[PRUint32(i) + 2] == '-' &&
        aInString[PRUint32(i) + 3] == '-')
          //if out-commended code, skip until -->
      {
        i = aInString.Find("-->", PR_FALSE, i);
        if (i == kNotFound)
          i = lengthOfInString;
        else
          i += 3;

      }
      else  // just skip tag (attributes etc.)
      {
        i = aInString.FindChar('>', i);
        if (i == kNotFound)
          i = lengthOfInString;
        else
          i++;
      }
      aOutString.Append(&uniBuffer[start], PRUint32(i) - start);
    }
    else
    {
      PRUint32 start = PRUint32(i);
      i = aInString.FindChar('<', i);
      if (i == kNotFound)
        i = lengthOfInString;
  
      nsString tempString;     
      tempString.SetCapacity(PRUint32((PRUint32(i) - start) * growthRate));
      UnescapeStr(uniBuffer, start, PRUint32(i) - start, tempString);
      ScanTXT(tempString.get(), tempString.Length(), whattodo, aOutString);
    }
  }

#ifdef DEBUG_BenB_Perf
  printf("ScanHTML time:    %d ms\n", PR_IntervalToMilliseconds(PR_IntervalNow() - parsing_start));
#endif
}

Here is the call graph for this function:

wstring mozITXTToHTMLConv::scanHTML ( in wstring  text,
in unsigned long  whattodo 
) [inherited]

Adds additional formatting to user edited text, that the user was too lazy or "unknowledged" (DELETEME: is that a word?) to make.

Note: Don't use kGlyphSubstitution with this function. This option generates tags, that are unuseable for UAs other than Mozilla. This would be a data loss bug.

Parameters:
text,:HTML source to scan. May be a line, paragraph (recommended) or just a substring.

Must be correct HTML. "<", ">" and "&" must be escaped, other chars must be pure unicode.

Note: ScanTXT(a, o) + ScanTXT(b, o) may be != Scan(a + b, o)

Parameters:
whattodo,:Bitfield describing the modes of operation
Returns:
Additional HTML tags are inserted where appropriate.
NS_IMETHODIMP mozTXTToHTMLConv::ScanTXT ( const PRUnichar aInString,
PRInt32  aInStringLength,
PRUint32  whattodo,
nsString aOutString 
)

see mozITXTToHTMLConv::ScanTXT

Definition at line 1101 of file mozTXTToHTMLConv.cpp.

{
  PRBool doURLs = whattodo & kURLs;
  PRBool doGlyphSubstitution = whattodo & kGlyphSubstitution;
  PRBool doStructPhrase = whattodo & kStructPhrase;

  MOZ_TIMER_START(mScanTXTTimer);

  PRUint32 structPhrase_strong = 0;  // Number of currently open tags
  PRUint32 structPhrase_underline = 0;
  PRUint32 structPhrase_italic = 0;
  PRUint32 structPhrase_code = 0;

  nsAutoString outputHTML;  // moved here for performance increase

  for(PRUint32 i = 0; PRInt32(i) < aInStringLength;)
  {
    if (doGlyphSubstitution)
    {
      PRInt32 glyphTextLen;
      if (GlyphHit(&aInString[i], aInStringLength - i, i == 0, aOutString, glyphTextLen))
      {
        i += glyphTextLen;
        continue;
      }
    }

    if (doStructPhrase)
    {
      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
      {
      case '*':
        if (StructPhraseHit(newOffset, newLength, i == 0,
                            NS_LITERAL_STRING("*").get(), 1,
                            "b", "class=\"moz-txt-star\"",
                            aOutString, structPhrase_strong))
        {
          i++;
          continue;
        }
        break;
      case '/':
        if (StructPhraseHit(newOffset, newLength, i == 0,
                            NS_LITERAL_STRING("/").get(), 1,
                            "i", "class=\"moz-txt-slash\"",
                            aOutString, structPhrase_italic))
        {
          i++;
          continue;
        }
        break;
      case '_':
        if (StructPhraseHit(newOffset, newLength, i == 0,
                            NS_LITERAL_STRING("_").get(), 1,
                            "span" /* <u> is deprecated */,
                            "class=\"moz-txt-underscore\"",
                            aOutString, structPhrase_underline))
        {
          i++;
          continue;
        }
        break;
      case '|':
        if (StructPhraseHit(newOffset, newLength, i == 0,
                            NS_LITERAL_STRING("|").get(), 1,
                            "code", "class=\"moz-txt-verticalline\"",
                            aOutString, structPhrase_code))
        {
          i++;
          continue;
        }
        break;
      }
    }

    if (doURLs)
    {
      switch (aInString[i])
      {
      case ':':
      case '@':
      case '.':
        if ( (i == 0 || ((i > 0) && aInString[i - 1] != ' ')) && aInString[i +1] != ' ') // Performance increase
        {
          PRInt32 replaceBefore;
          PRInt32 replaceAfter;
          if (FindURL(aInString, aInStringLength, i, whattodo,
                      outputHTML, replaceBefore, replaceAfter)
                  && structPhrase_strong + structPhrase_italic +
                       structPhrase_underline + structPhrase_code == 0
                       /* workaround for bug #19445 */ )
          {
            aOutString.Cut(aOutString.Length() - replaceBefore, replaceBefore);
            aOutString += outputHTML;
            i += replaceAfter + 1;
            continue;
          }
        }
        break;
      } //switch
    }

    switch (aInString[i])
    {
    // Special symbols
    case '<':
    case '>':
    case '&':
      EscapeChar(aInString[i], aOutString);
      i++;
      break;
    // Normal characters
    default:
      aOutString += aInString[i];
      i++;
      break;
    }
  }

  MOZ_TIMER_STOP(mScanTXTTimer);
}

Here is the call graph for this function:

Here is the caller graph for this function:

wstring mozITXTToHTMLConv::scanTXT ( in wstring  text,
in unsigned long  whattodo 
) [inherited]
Parameters:
text,:plain text to scan. May be a line, paragraph (recommended) or just a substring.

Must be non-escaped, pure unicode.

Note: ScanTXT(a, o) + ScanTXT(b, o) may be != Scan(a + b, o)

Parameters:
whattodo,:Bitfield describing the modes of operation
Returns:
"<", ">" and "&" are escaped and HTML tags are inserted where appropriate.

Check if a given url should be linkified.

Parameters:
aURL(in): url to be checked on.

Definition at line 398 of file mozTXTToHTMLConv.cpp.

{
  if (!mIOService)
    return PR_FALSE;

  nsCAutoString scheme;
  nsresult rv = mIOService->ExtractScheme(aURL, scheme);
  if(NS_FAILED(rv))
    return PR_FALSE;

  // Get the handler for this scheme.
  nsCOMPtr<nsIProtocolHandler> handler;    
  rv = mIOService->GetProtocolHandler(scheme.get(), getter_AddRefs(handler));
  if(NS_FAILED(rv))
    return PR_FALSE;

  // Is it an external protocol handler? If not, linkify it.
  nsCOMPtr<nsIExternalProtocolHandler> externalHandler = do_QueryInterface(handler, &rv);
  if (!externalHandler)
   return PR_TRUE; // handler is built-in, linkify it!

  // If external app exists for the scheme then linkify it.
  PRBool exists;
  rv = externalHandler->ExternalAppExistsForScheme(scheme, &exists);
  return(NS_SUCCEEDED(rv) && exists);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool mozTXTToHTMLConv::SmilyHit ( const PRUnichar aInString,
PRInt32  aLength,
PRBool  col0,
const char *  tagTXT,
const char *  imageName,
nsString outputHTML,
PRInt32 glyphTextLen 
) [private]
Parameters:
text(in), col0 (in): see GlyphHit
tagTXT(in): Smily, see also StructPhraseHit
imageName(in): the basename of the file that contains the image for this smilie
outputHTML(out): new string containing the html for the smily
glyphTextLen(out): see GlyphHit

Definition at line 710 of file mozTXTToHTMLConv.cpp.

{
  if ( !aInString || !tagTXT || !imageName )
      return PR_FALSE;

  PRInt32  tagLen = nsCRT::strlen(tagTXT);
 
  PRUint32 delim = (col0 ? 0 : 1) + tagLen;

  if
    (
      (col0 || IsSpace(aInString[0]))
        &&
        (
          aLength <= PRInt32(delim) ||
          IsSpace(aInString[delim]) ||
          aLength > PRInt32(delim + 1)
            &&
            (
              aInString[delim] == '.' ||
              aInString[delim] == ',' ||
              aInString[delim] == ';' ||
              aInString[delim] == '8' ||
              aInString[delim] == '>' ||
              aInString[delim] == '!' ||
              aInString[delim] == '?'
            )
            && IsSpace(aInString[delim + 1])
        )
        && ItMatchesDelimited(aInString, aLength, NS_ConvertASCIItoUCS2(tagTXT).get(), tagLen, 
                              col0 ? LT_IGNORE : LT_DELIMITER, LT_IGNORE)
               // Note: tests at different pos for LT_IGNORE and LT_DELIMITER
    )
  {
    if (!col0)
    {
      outputHTML.Truncate();
      outputHTML.Append(PRUnichar(' '));
    }

    outputHTML.AppendLiteral("<span class=\""); // <span class="
    AppendASCIItoUTF16(imageName, outputHTML);        // smiley-frown
    outputHTML.AppendLiteral("\"><span> ");     // "> <span> 
    AppendASCIItoUTF16(tagTXT, outputHTML);           // alt text
    outputHTML.AppendLiteral(" </span></span>"); // </span></span>
    glyphTextLen = (col0 ? 0 : 1) + tagLen;
    return PR_TRUE;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool mozTXTToHTMLConv::StructPhraseHit ( const PRUnichar aInString,
PRInt32  aInStringLength,
PRBool  col0,
const PRUnichar tagTXT,
PRInt32  aTagTxtLen,
const char *  tagHTML,
const char *  attributeHTML,
nsString aOutputString,
PRUint32 openTags 
) [private]
Parameters:
text(in): line of text possibly with tagTXT.

if col0 is true, starting with tagTXT
else starting one char before tagTXT

Parameters:
col0(in): tagTXT is on the beginning of the line (or paragraph). open must be 0 then.
tagTXT(in): Tag in plaintext to search for, e.g. "*"
aTagTxtLen(in): length of tagTXT.
tagHTML(in): HTML-Tag to replace tagTXT with, without "<" and ">", e.g. "strong"
attributeHTML(in): HTML-attribute to add to opening tagHTML, e.g. "class=txt_star"
aOutString,:string to APPEND the converted html into
open(in/out): Number of currently open tags of type tagHTML
Returns:
Conversion succeeded

Definition at line 652 of file mozTXTToHTMLConv.cpp.

{
  /* We're searching for the following pattern:
     LT_DELIMITER - "*" - ALPHA -
     [ some text (maybe more "*"-pairs) - ALPHA ] "*" - LT_DELIMITER.
     <strong> is only inserted, if existance of a pair could be verified
     We use the first opening/closing tag, if we can choose */

  const PRUnichar * newOffset = aInString;
  PRInt32 newLength = aInStringLength;
  if (!col0) // skip the first element?
  {
    newOffset = &aInString[1];
    newLength = aInStringLength - 1;
  }

  // opening tag
  if
    (
      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
    )
  {
    openTags++;
    aOutString.AppendLiteral("<");
    aOutString.AppendASCII(tagHTML);
    aOutString.Append(PRUnichar(' '));
    aOutString.AppendASCII(attributeHTML);
    aOutString.AppendLiteral("><span class=\"moz-txt-tag\">");
    aOutString.Append(tagTXT);
    aOutString.AppendLiteral("</span>");
    return PR_TRUE;
  }

  // closing tag
  else if (openTags > 0
       && ItMatchesDelimited(aInString, aInStringLength, tagTXT, aTagTXTLen, LT_ALPHA, LT_DELIMITER))
  {
    openTags--;
    aOutString.AppendLiteral("<span class=\"moz-txt-tag\">");
    aOutString.Append(tagTXT);
    aOutString.AppendLiteral("</span></");
    aOutString.AppendASCII(tagHTML);
    aOutString.Append(PRUnichar('>'));
    return PR_TRUE;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void mozTXTToHTMLConv::UnescapeStr ( const PRUnichar aInString,
PRInt32  aStartPos,
PRInt32  aLength,
nsString aOutString 
) [private]

Currently only reverts "<", ">" and "&".

All others stay as they are.

Parameters:
aInString(in) HTML string
aStartPos(in) start index into the buffer
aLength(in) length of the buffer
aOutString(out) unescaped buffer

Definition at line 125 of file mozTXTToHTMLConv.cpp.

{
  const PRUnichar * subString = nsnull;
  for (PRUint32 i = aStartPos; PRInt32(i) - aStartPos < aLength;)
  {
    PRInt32 remainingChars = i - aStartPos;
    if (aInString[i] == '&')
    {
      subString = &aInString[i];
      if (!nsCRT::strncmp(subString, NS_LITERAL_STRING("&lt;").get(), MinInt(4, aLength - remainingChars)))
      {
        aOutString.Append(PRUnichar('<'));
        i += 4;
      }
      else if (!nsCRT::strncmp(subString, NS_LITERAL_STRING("&gt;").get(), MinInt(4, aLength - remainingChars)))
      {
        aOutString.Append(PRUnichar('>'));
        i += 4;
      }
      else if (!nsCRT::strncmp(subString, NS_LITERAL_STRING("&amp;").get(), MinInt(5, aLength - remainingChars)))
      {
        aOutString.Append(PRUnichar('&'));
        i += 5;
      }
      else
      {
        aOutString += aInString[i];
        i++;
      }
    }
    else
    {
      aOutString += aInString[i];
      i++;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

const unsigned long mozITXTToHTMLConv::kEntities = 0 [inherited]

Definition at line 62 of file mozITXTToHTMLConv.idl.

const unsigned long mozITXTToHTMLConv::kGlyphSubstitution = 1 << 2 [inherited]

Definition at line 64 of file mozITXTToHTMLConv.idl.

const unsigned long mozITXTToHTMLConv::kStructPhrase = 1 << 3 [inherited]

Definition at line 65 of file mozITXTToHTMLConv.idl.

const unsigned long mozITXTToHTMLConv::kURLs = 1 << 1 [inherited]

Definition at line 63 of file mozITXTToHTMLConv.idl.

Definition at line 97 of file mozTXTToHTMLConv.h.


The documentation for this class was generated from the following files: