Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes
WordSplitState Struct Reference
Collaboration diagram for WordSplitState:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 WordSplitState (mozInlineSpellWordUtil *aWordUtil, const nsString &aString, PRInt32 aStart, PRInt32 aLen)
CharClass ClassifyCharacter (PRInt32 aIndex, PRBool aRecurse) const
void Advance ()
void AdvanceThroughSeparators ()
void AdvanceThroughWord ()
PRInt32 FindSpecialWord ()
PRBool ShouldSkipWord (PRInt32 aStart, PRInt32 aLength)

Public Attributes

mozInlineSpellWordUtilmWordUtil
const nsDependentSubstring mDOMWordText
PRInt32 mDOMWordOffset
CharClass mCurCharClass

Detailed Description

Definition at line 803 of file mozInlineSpellWordUtil.cpp.


Constructor & Destructor Documentation

WordSplitState::WordSplitState ( mozInlineSpellWordUtil aWordUtil,
const nsString aString,
PRInt32  aStart,
PRInt32  aLen 
) [inline]

Definition at line 810 of file mozInlineSpellWordUtil.cpp.


Member Function Documentation

Definition at line 888 of file mozInlineSpellWordUtil.cpp.

{
  NS_ASSERTION(mDOMWordOffset >= 0, "Negative word index");
  NS_ASSERTION(mDOMWordOffset < (PRInt32)mDOMWordText.Length(),
               "Length beyond end");

  mDOMWordOffset ++;
  if (mDOMWordOffset >= (PRInt32)mDOMWordText.Length())
    mCurCharClass = CHAR_CLASS_END_OF_INPUT;
  else
    mCurCharClass = ClassifyCharacter(mDOMWordOffset, PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 905 of file mozInlineSpellWordUtil.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 914 of file mozInlineSpellWordUtil.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

CharClass WordSplitState::ClassifyCharacter ( PRInt32  aIndex,
PRBool  aRecurse 
) const

Definition at line 835 of file mozInlineSpellWordUtil.cpp.

{
  NS_ASSERTION(aIndex >= 0 && aIndex <= PRInt32(mDOMWordText.Length()),
               "Index out of range");
  if (aIndex == PRInt32(mDOMWordText.Length()))
    return CHAR_CLASS_SEPARATOR;

  // this will classify the character, we want to treat "ignorable" characters
  // such as soft hyphens as word characters.
  PRInt32 charCategory = GetCat(mDOMWordText[aIndex]);
  if (charCategory == CHAR_CAT_WORD ||
      IsIgnorableCharacter(mDOMWordText[aIndex]))
    return CHAR_CLASS_WORD;

  // If conditional punctuation is surrounded immediately on both sides by word
  // characters it also counts as a word character.
  if (IsConditionalPunctuation(mDOMWordText[aIndex])) {
    if (!aRecurse) {
      // not allowed to look around, this punctuation counts like a separator
      return CHAR_CLASS_SEPARATOR;
    }

    // check the left-hand character
    if (aIndex == 0)
      return CHAR_CLASS_SEPARATOR;
    if (ClassifyCharacter(aIndex - 1, false) != CHAR_CLASS_WORD)
      return CHAR_CLASS_SEPARATOR;

    // now we know left char is a word-char, check the right-hand character
    if (aIndex == PRInt32(mDOMWordText.Length()) - 1)
      return CHAR_CLASS_SEPARATOR;
    if (ClassifyCharacter(aIndex + 1, false) != CHAR_CLASS_WORD)
      return CHAR_CLASS_SEPARATOR;

    // char on either side is a word, this counts as a word
    return CHAR_CLASS_WORD;
  }

  // all other punctuation
  if (charCategory == CHAR_CAT_SPACE ||
      charCategory == CHAR_CAT_CONTROL ||
      charCategory == CHAR_CAT_PUNCTUATION1 ||
      charCategory == CHAR_CAT_PUNCTUATION2)
    return CHAR_CLASS_SEPARATOR;

  // any other character counts as a word
  return CHAR_CLASS_WORD;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 924 of file mozInlineSpellWordUtil.cpp.

{
  PRInt32 i;

  // Search for email addresses. We simply define these as any sequence of
  // characters with an '@' character in the middle. The DOM word is already
  // split on whitepace, so we know that everything to the end is the address
  //
  // Also look for periods, this tells us if we want to run the URL finder.
  PRBool foundDot = PR_FALSE;
  PRInt32 firstColon = -1;
  for (i = mDOMWordOffset;
       i < PRInt32(mDOMWordText.Length()); i ++) {
    if (mDOMWordText[i] == '@') {
      // only accept this if there are unambigous word characters (don't bother
      // recursing to disambiguate apostrophes) on each side. This prevents
      // classifying, e.g. "@home" as an email address

      // Use this condition to only accept words with '@' in the middle of
      // them. It works, but the inlinespellcker doesn't like this. The problem
      // is that you type "fhsgfh@" that's a misspelled word followed by a
      // symbol, but when you type another letter "fhsgfh@g" that first word
      // need to be unmarked misspelled. It doesn't do this. it only checks the
      // current position for potentially removing a spelling range.
      if (i > 0 && ClassifyCharacter(i - 1, PR_FALSE) == CHAR_CLASS_WORD &&
          i < (PRInt32)mDOMWordText.Length() - 1 &&
          ClassifyCharacter(i + 1, PR_FALSE) == CHAR_CLASS_WORD)

      return mDOMWordText.Length() - mDOMWordOffset;
    } else if (mDOMWordText[i] == '.' && ! foundDot &&
        i > 0 && i < (PRInt32)mDOMWordText.Length() - 1) {
      // we found a period not at the end, we should check harder for URLs
      foundDot = PR_TRUE;
    } else if (mDOMWordText[i] == ':' && firstColon < 0) {
      firstColon = i;
    }
  }

  // If the first colon is followed by a slash, consider it a URL
  // This will catch things like asdf://foo.com
  if (firstColon >= 0 && firstColon < (PRInt32)mDOMWordText.Length() - 1 &&
      mDOMWordText[firstColon + 1] == '/') {
    return mDOMWordText.Length() - mDOMWordOffset;
  }

  // Check the text before the first colon against some known protocols. It
  // is impossible to check against all protocols, especially since you can
  // plug in new protocols. We also don't want to waste time here checking
  // against a lot of obscure protocols.
  if (firstColon > mDOMWordOffset) {
    nsString protocol(Substring(mDOMWordText, mDOMWordOffset,
                      firstColon - mDOMWordOffset));
    if (protocol.EqualsIgnoreCase("http") ||
        protocol.EqualsIgnoreCase("https") ||
        protocol.EqualsIgnoreCase("news") ||
        protocol.EqualsIgnoreCase("ftp") ||
        protocol.EqualsIgnoreCase("file") ||
        protocol.EqualsIgnoreCase("javascript") ||
        protocol.EqualsIgnoreCase("ftp")) {
      return mDOMWordText.Length() - mDOMWordOffset;
    }
  }

  // not anything special
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 994 of file mozInlineSpellWordUtil.cpp.

{
  PRInt32 last = aStart + aLength;

  // check to see if the word contains a digit
  for (PRInt32 i = aStart; i < last; i ++) {
    PRUnichar ch = mDOMWordText[i];
    // XXX Shouldn't this be something a lot more complex, Unicode-based?
    if (ch >= '0' && ch <= '9')
      return PR_TRUE;
  }

  // not special
  return PR_FALSE;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 808 of file mozInlineSpellWordUtil.cpp.

Definition at line 807 of file mozInlineSpellWordUtil.cpp.

Definition at line 806 of file mozInlineSpellWordUtil.cpp.

Definition at line 805 of file mozInlineSpellWordUtil.cpp.


The documentation for this struct was generated from the following file: