зеркало из https://github.com/mozilla/pjs.git
Bug #234936 --> expose method to find a url given a string. This allows the spell checker to
ignore urls in mail compose. Porting this functionality to seamonkey. sr=bienvenu
This commit is contained in:
Родитель
29fb68b243
Коммит
df7d090718
|
@ -50,6 +50,9 @@ NS_IMPL_ISUPPORTS1(mozEnglishWordUtils, mozISpellI18NUtil)
|
|||
mozEnglishWordUtils::mozEnglishWordUtils()
|
||||
{
|
||||
mLanguage.Assign(NS_LITERAL_STRING("en"));
|
||||
|
||||
nsresult rv;
|
||||
mURLDetector = do_CreateInstance(MOZ_TXTTOHTMLCONV_CONTRACTID, &rv);
|
||||
}
|
||||
|
||||
mozEnglishWordUtils::~mozEnglishWordUtils()
|
||||
|
@ -179,6 +182,36 @@ NS_IMETHODIMP mozEnglishWordUtils::FindNextWord(const PRUnichar *word, PRUint32
|
|||
{
|
||||
p++;
|
||||
}
|
||||
|
||||
// we could be trying to break down a url, we don't want to break a url into parts,
|
||||
// instead we want to find out if it really is a url and if so, skip it, advancing startWord
|
||||
// to a point after the url.
|
||||
|
||||
// before we spend more time looking to see if the word is a url, look for a url identifer
|
||||
// and make sure that identifer isn't the last character in the word fragment.
|
||||
if ( (*p == ':' || *p == '@' || *p == '.') && p < endbuf - 1) {
|
||||
|
||||
// ok, we have a possible url...do more research to find out if we really have one
|
||||
// and determine the length of the url so we can skip over it.
|
||||
|
||||
if (mURLDetector)
|
||||
{
|
||||
PRInt32 startPos = -1;
|
||||
PRInt32 endPos = -1;
|
||||
|
||||
mURLDetector->FindURLInPlaintext(startWord, endbuf - startWord, p - startWord, &startPos, &endPos);
|
||||
|
||||
// ok, if we got a url, adjust the array bounds, skip the current url text and find the next word again
|
||||
if (startPos != -1 && endPos != -1) {
|
||||
startWord = p + endPos + 1; // skip over the url
|
||||
p = startWord; // reset p
|
||||
|
||||
// now recursively call FindNextWord to search for the next word now that we have skipped the url
|
||||
return FindNextWord(word, length, startWord - word, begin, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while((p > startWord)&&(*(p-1) == '\'')){ // trim trailing apostrophes
|
||||
p--;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
#include "nsString.h"
|
||||
#include "nsICaseConversion.h"
|
||||
|
||||
#include "mozITXTToHTMLConv.h"
|
||||
|
||||
class mozEnglishWordUtils : public mozISpellI18NUtil
|
||||
{
|
||||
public:
|
||||
|
@ -64,6 +66,7 @@ protected:
|
|||
nsString mLanguage;
|
||||
nsString mCharset;
|
||||
nsCOMPtr<nsICaseConversion> mCaseConv;
|
||||
nsCOMPtr<mozITXTToHTMLConv> mURLDetector; // used to detect urls so the spell checker can skip them.
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -461,6 +461,19 @@ mozTXTToHTMLConv::CheckURLAndCreateHTML(
|
|||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP mozTXTToHTMLConv::FindURLInPlaintext(const PRUnichar * aInString, PRInt32 aInLength, PRInt32 aPos, PRInt32 * aStartPos, PRInt32 * aEndPos)
|
||||
{
|
||||
// call FindURL on the passed in string
|
||||
nsString outputHTML; // we'll ignore the generated output HTML
|
||||
|
||||
*aStartPos = -1;
|
||||
*aEndPos = -1;
|
||||
|
||||
FindURL(aInString, aInLength, aPos, kURLs, outputHTML, *aStartPos, *aEndPos);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
mozTXTToHTMLConv::FindURL(const PRUnichar * aInString, PRInt32 aInLength, const PRUint32 pos,
|
||||
const PRUint32 whathasbeendone,
|
||||
|
|
|
@ -105,4 +105,6 @@ interface mozITXTToHTMLConv : nsIStreamConverter {
|
|||
*/
|
||||
unsigned long citeLevelTXT([const] in wstring line,
|
||||
out unsigned long logLineStart);
|
||||
|
||||
void findURLInPlaintext([const] in wstring text, in long aLength, in long aPos, out long aStartPos, out long aEndPos);
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче