Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions
nsWrapUtils Class Reference

Static class to handle wrapping functions. More...

#include <nsWrapUtils.h>

List of all members.

Static Public Member Functions

static nsresult Rewrap (const nsAString &aInString, PRUint32 aWrapCol, PRUint32 aFirstLineOffset, PRBool aRespectNewlines, const nsAString &aLineStartStr, nsAString &aOutString)

Detailed Description

Static class to handle wrapping functions.

Definition at line 45 of file nsWrapUtils.h.

Member Function Documentation

nsresult nsWrapUtils::Rewrap ( const nsAString &  aInString,
PRUint32  aWrapCol,
PRUint32  aFirstLineOffset,
PRBool  aRespectNewlines,
const nsAString &  aLineStartStr,
nsAString &  aOutString 
) [static]

Definition at line 51 of file nsWrapUtils.cpp.

  PRInt32 i;

  nsCOMPtr<nsILineBreaker> lineBreaker;

  nsILineBreakerFactory *lf;
  nsresult rv = CallGetService(NS_LWBRK_CONTRACTID, &lf);
  if (NS_SUCCEEDED(rv))
    nsAutoString lbarg;
    lf->GetBreaker(lbarg, getter_AddRefs(lineBreaker));


  // Now we either have a line breaker, or we don't.
  const nsPromiseFlatString &tString = PromiseFlatString(aInString);
  PRInt32 length = tString.Length();
  const PRUnichar* unicodeStr = tString.get();
  for (i = 0; i < length; )    // loop over lines
    nsAutoString remaining(unicodeStr + i, length - i);

    // If there's a first-line offset, that means we're not starting
    // at the beginning of the line, so don't add a cite string there:
    if (!aFirstLineOffset)

    PRInt32 eol = i + aWrapCol - aFirstLineOffset;
    if (eol > length)
      aOutString.Append(unicodeStr + i, length - i);
      aOutString.Append(PRUnichar('\n'));  // DOM line breaks, not NS_LINEBREAK
    if (i > 0) aFirstLineOffset = 0;
    // eol is the prospective end of line ...
    // look backwards from there for a place to break.
    PRUint32 breakPt;
    PRBool needMore;
    rv = NS_ERROR_BASE;
    if (lineBreaker)
      rv = lineBreaker->Prev(unicodeStr + i, length - i, eol - i,
                             &breakPt, &needMore);
      if (NS_FAILED(rv) || needMore)
        rv = lineBreaker->Next(unicodeStr + i, length - i, eol - i,
                               &breakPt, &needMore);
        if (needMore) rv = NS_ERROR_BASE;
    // If we get out here and rv is set, something went wrong with line breaker.
    // Just break the line, hard.
    // If rv is okay, then breakPt is the place to break.
    if (NS_FAILED(rv))
#ifdef DEBUG_akkana
      printf("nsILineBreaker not working -- breaking hard\n");
      breakPt = eol+1;
    else breakPt += i;
    nsAutoString appending(unicodeStr + i, breakPt - i);
    aOutString.Append(unicodeStr + i, breakPt - i);
    aOutString.Append(PRUnichar('\n'));  // DOM line breaks, not NS_LINEBREAK

    i = breakPt;
  } // continue looping over lines

  return NS_OK;

Here is the call graph for this function:

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