make nsIEditorSpellcheck use nsAString instead of nsString.

bug 225749, r=dwitte, sr=alecf
This commit is contained in:
mvl%exedo.nl 2003-12-20 13:06:44 +00:00
Родитель 8f220b9fdd
Коммит 028692f012
4 изменённых файлов: 62 добавлений и 68 удалений

Просмотреть файл

@ -206,7 +206,7 @@ nsEditorSpellCheck::GetNextMisspelledWord(PRUnichar **aNextMisspelledWord)
nsAutoString nextMisspelledWord;
DeleteSuggestedWordList();
nsresult rv = mSpellChecker->NextMisspelledWord(&nextMisspelledWord,
nsresult rv = mSpellChecker->NextMisspelledWord(nextMisspelledWord,
&mSuggestedWordList);
*aNextMisspelledWord = ToNewUnicode(nextMisspelledWord);
@ -232,28 +232,28 @@ nsEditorSpellCheck::GetSuggestedWord(PRUnichar **aSuggestedWord)
NS_IMETHODIMP
nsEditorSpellCheck::CheckCurrentWord(const PRUnichar *aSuggestedWord,
PRBool *aIsMisspelled)
PRBool *aIsMisspelled)
{
if (!mSpellChecker)
return NS_NOINTERFACE;
nsAutoString suggestedWord(aSuggestedWord);
DeleteSuggestedWordList();
return mSpellChecker->CheckWord(&suggestedWord, aIsMisspelled,
&mSuggestedWordList);
return mSpellChecker->CheckWord(nsDependentString(aSuggestedWord),
aIsMisspelled, &mSuggestedWordList);
}
NS_IMETHODIMP
nsEditorSpellCheck::ReplaceWord(const PRUnichar *aMisspelledWord,
const PRUnichar *aReplaceWord,
PRBool allOccurrences)
const PRUnichar *aReplaceWord,
PRBool allOccurrences)
{
if (!mSpellChecker)
return NS_NOINTERFACE;
nsAutoString misspelledWord(aMisspelledWord);
nsAutoString replaceWord(aReplaceWord);
return mSpellChecker->Replace(&misspelledWord, &replaceWord, allOccurrences);
return mSpellChecker->Replace(nsDependentString(aMisspelledWord),
nsDependentString(aReplaceWord), allOccurrences);
}
NS_IMETHODIMP
@ -262,8 +262,7 @@ nsEditorSpellCheck::IgnoreWordAllOccurrences(const PRUnichar *aWord)
if (!mSpellChecker)
return NS_NOINTERFACE;
nsAutoString word(aWord);
return mSpellChecker->IgnoreAll(&word);
return mSpellChecker->IgnoreAll(nsDependentString(aWord));
}
NS_IMETHODIMP
@ -301,8 +300,7 @@ nsEditorSpellCheck::AddWordToDictionary(const PRUnichar *aWord)
if (!mSpellChecker)
return NS_NOINTERFACE;
nsAutoString word(aWord);
return mSpellChecker->AddWordToPersonalDictionary(&word);
return mSpellChecker->AddWordToPersonalDictionary(nsDependentString(aWord));
}
NS_IMETHODIMP
@ -311,8 +309,7 @@ nsEditorSpellCheck::RemoveWordFromDictionary(const PRUnichar *aWord)
if (!mSpellChecker)
return NS_NOINTERFACE;
nsAutoString word(aWord);
return mSpellChecker->RemoveWordFromPersonalDictionary(&word);
return mSpellChecker->RemoveWordFromPersonalDictionary(nsDependentString(aWord));
}
NS_IMETHODIMP
@ -386,7 +383,7 @@ nsEditorSpellCheck::GetCurrentDictionary(PRUnichar **aDictionary)
*aDictionary = 0;
nsAutoString dictStr;
nsresult rv = mSpellChecker->GetCurrentDictionary(&dictStr);
nsresult rv = mSpellChecker->GetCurrentDictionary(dictStr);
NS_ENSURE_SUCCESS(rv, rv);
*aDictionary = ToNewUnicode(dictStr);
@ -403,8 +400,7 @@ nsEditorSpellCheck::SetCurrentDictionary(const PRUnichar *aDictionary)
if (!aDictionary)
return NS_ERROR_NULL_POINTER;
nsAutoString dictStr(aDictionary);
return mSpellChecker->SetCurrentDictionary(&dictStr);
return mSpellChecker->SetCurrentDictionary(nsDependentString(aDictionary));
}
NS_IMETHODIMP

Просмотреть файл

@ -44,9 +44,9 @@
#define NS_SPELLCHECKER_CONTRACTID "@mozilla.org/spellchecker;1"
#define NS_ISPELLCHECKER_IID \
{ /* F72A52F1-F83B-11d2-8D54-000064657374 */ \
0xf72a52f1, 0xf83b, 0x11d2, \
{ 0x8d, 0x54, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
{ /* E75AC48C-E948-452E-8DB3-30FEE29FE3D2 */ \
0xe75ac48c, 0xe948, 0x452e, \
{ 0x8d, 0xb3, 0x30, 0xfe, 0xe2, 0x9f, 0xe3, 0xd2 } }
class nsITextServicesDocument;
class nsString;
@ -74,7 +74,7 @@ public:
* @param aSuggestions is an array of nsStrings, that represent the
* suggested replacements for the misspelled word.
*/
NS_IMETHOD NextMisspelledWord(nsString *aWord, nsStringArray *aSuggestions) = 0;
NS_IMETHOD NextMisspelledWord(nsAString &aWord, nsStringArray *aSuggestions) = 0;
/**
* Checks if a word is misspelled. No document is required to use this method.
@ -84,7 +84,7 @@ public:
* suggested replacements for the misspelled word. The array will be empty
* if there aren't any suggestions.
*/
NS_IMETHOD CheckWord(const nsString *aWord, PRBool *aIsMisspelled, nsStringArray *aSuggestions) = 0;
NS_IMETHOD CheckWord(const nsAString &aWord, PRBool *aIsMisspelled, nsStringArray *aSuggestions) = 0;
/**
* Replaces the old word with the specified new word.
@ -94,25 +94,25 @@ public:
* word, in the document, with new word when it is true. If
* false, it will replace the 1st occurrence only!
*/
NS_IMETHOD Replace(const nsString *aOldWord, const nsString *aNewWord, PRBool aAllOccurrences) = 0;
NS_IMETHOD Replace(const nsAString &aOldWord, const nsAString &aNewWord, PRBool aAllOccurrences) = 0;
/**
* Ignores all occurrences of the specified word in the document.
* @param aWord is the word to ignore.
*/
NS_IMETHOD IgnoreAll(const nsString *aWord) = 0;
NS_IMETHOD IgnoreAll(const nsAString &aWord) = 0;
/**
* Add a word to the user's personal dictionary.
* @param aWord is the word to add.
*/
NS_IMETHOD AddWordToPersonalDictionary(const nsString *aWord) = 0;
NS_IMETHOD AddWordToPersonalDictionary(const nsAString &aWord) = 0;
/**
* Remove a word from the user's personal dictionary.
* @param aWord is the word to remove.
*/
NS_IMETHOD RemoveWordFromPersonalDictionary(const nsString *aWord) = 0;
NS_IMETHOD RemoveWordFromPersonalDictionary(const nsAString &aWord) = 0;
/**
* Returns the list of words in the user's personal dictionary.
@ -138,14 +138,14 @@ public:
* This name is the same string that is in the list returned
* by GetDictionaryList().
*/
NS_IMETHOD GetCurrentDictionary(nsString *aDictionary) = 0;
NS_IMETHOD GetCurrentDictionary(nsAString &aDictionary) = 0;
/**
* Tells the spellchecker to use a specific dictionary.
* @param aDictionary a string that is in the list returned
* by GetDictionaryList().
*/
NS_IMETHOD SetCurrentDictionary(const nsString *aDictionary) = 0;
NS_IMETHOD SetCurrentDictionary(const nsAString &aDictionary) = 0;
};
#endif // nsISpellChecker_h__

Просмотреть файл

@ -81,7 +81,7 @@ mozSpellChecker::SetDocument(nsITextServicesDocument *aDoc, PRBool aFromStartofD
NS_IMETHODIMP
mozSpellChecker::NextMisspelledWord(nsString *aWord, nsStringArray *aSuggestions)
mozSpellChecker::NextMisspelledWord(nsAString &aWord, nsStringArray *aSuggestions)
{
if(!aSuggestions||!mConverter)
return NS_ERROR_NULL_POINTER;
@ -104,14 +104,13 @@ mozSpellChecker::NextMisspelledWord(nsString *aWord, nsStringArray *aSuggestions
do{
result = mConverter->FindNextWord(str.get(),str.Length(),selOffset,&begin,&end);
if(NS_SUCCEEDED(result)&&(begin != -1)){
nsString currWord;
currWord=Substring(str,begin,end-begin);
result = CheckWord(&currWord,&isMisspelled,aSuggestions);
const nsAString &currWord = Substring(str, begin, end - begin);
result = CheckWord(currWord, &isMisspelled, aSuggestions);
if(isMisspelled){
*aWord = currWord;
mTsDoc->SetSelection(begin, end-begin);
mTsDoc->ScrollSelectionIntoView();
return NS_OK;
aWord = currWord;
mTsDoc->SetSelection(begin, end-begin);
mTsDoc->ScrollSelectionIntoView();
return NS_OK;
}
}
selOffset = end;
@ -123,14 +122,14 @@ mozSpellChecker::NextMisspelledWord(nsString *aWord, nsStringArray *aSuggestions
}
NS_IMETHODIMP
mozSpellChecker::CheckWord(const nsString *aWord, PRBool *aIsMisspelled, nsStringArray *aSuggestions)
mozSpellChecker::CheckWord(const nsAString &aWord, PRBool *aIsMisspelled, nsStringArray *aSuggestions)
{
nsresult result;
PRBool correct;
if(!mSpellCheckingEngine)
return NS_ERROR_NULL_POINTER;
*aIsMisspelled = PR_FALSE;
result = mSpellCheckingEngine->Check(aWord->get(),&correct);
result = mSpellCheckingEngine->Check(PromiseFlatString(aWord).get(), &correct);
if(NS_FAILED(result))
return result;
if(!correct){
@ -139,7 +138,7 @@ mozSpellChecker::CheckWord(const nsString *aWord, PRBool *aIsMisspelled, nsStrin
PRUnichar **words;
nsAutoString temp;
mSpellCheckingEngine->Suggest(aWord->get(),&words,&count);
mSpellCheckingEngine->Suggest(PromiseFlatString(aWord).get(), &words, &count);
for(i=0;i<count;i++){
temp.Assign(words[i]);
aSuggestions->AppendString(temp);
@ -154,11 +153,13 @@ mozSpellChecker::CheckWord(const nsString *aWord, PRBool *aIsMisspelled, nsStrin
}
NS_IMETHODIMP
mozSpellChecker::Replace(const nsString *aOldWord, const nsString *aNewWord, PRBool aAllOccurrences)
mozSpellChecker::Replace(const nsAString &aOldWord, const nsAString &aNewWord, PRBool aAllOccurrences)
{
if(!mConverter)
return NS_ERROR_NULL_POINTER;
nsAutoString newWord(aNewWord); // sigh
if(aAllOccurrences){
PRUint32 selOffset;
PRInt32 startBlock,currentBlock,currOffset;
@ -185,17 +186,17 @@ mozSpellChecker::Replace(const nsString *aOldWord, const nsString *aNewWord, PRB
do{
result = mConverter->FindNextWord(str.get(),str.Length(),currOffset,&begin,&end);
if(NS_SUCCEEDED(result)&&(begin != -1)){
if(aOldWord->Equals(Substring(str,begin,end-begin))){
if (aOldWord.Equals(Substring(str, begin, end-begin))) {
// if we are before the current selection point but in the same block
// move the selection point forwards
if((currentBlock == startBlock)&&(begin < (PRInt32) selOffset)){
selOffset += (aNewWord->Length()-aOldWord->Length());
selOffset += (aNewWord.Length() - aOldWord.Length());
if(selOffset < 0) selOffset=0;
}
mTsDoc->SetSelection(begin, end-begin);
mTsDoc->InsertText(aNewWord);
mTsDoc->InsertText(&newWord);
mTsDoc->GetCurrentTextBlock(&str);
end += (aNewWord->Length()-aOldWord->Length()); // recursion was cute in GEB, not here.
end += (aNewWord.Length() - aOldWord.Length()); // recursion was cute in GEB, not here.
}
}
currOffset = end;
@ -218,39 +219,39 @@ mozSpellChecker::Replace(const nsString *aOldWord, const nsString *aNewWord, PRB
}
}
else{
mTsDoc->InsertText(aNewWord);
mTsDoc->InsertText(&newWord);
}
return NS_OK;
}
NS_IMETHODIMP
mozSpellChecker::IgnoreAll(const nsString *aWord)
mozSpellChecker::IgnoreAll(const nsAString &aWord)
{
if(mPersonalDictionary){
mPersonalDictionary->IgnoreWord(aWord->get());
mPersonalDictionary->IgnoreWord(PromiseFlatString(aWord).get());
}
return NS_OK;
}
NS_IMETHODIMP
mozSpellChecker::AddWordToPersonalDictionary(const nsString *aWord)
mozSpellChecker::AddWordToPersonalDictionary(const nsAString &aWord)
{
nsresult res;
PRUnichar empty=0;
if(!aWord||!mPersonalDictionary)
if (!mPersonalDictionary)
return NS_ERROR_NULL_POINTER;
res = mPersonalDictionary->AddWord(aWord->get(),&empty);
res = mPersonalDictionary->AddWord(PromiseFlatString(aWord).get(),&empty);
return res;
}
NS_IMETHODIMP
mozSpellChecker::RemoveWordFromPersonalDictionary(const nsString *aWord)
mozSpellChecker::RemoveWordFromPersonalDictionary(const nsAString &aWord)
{
nsresult res;
PRUnichar empty=0;
if(!aWord||!mPersonalDictionary)
if (!mPersonalDictionary)
return NS_ERROR_NULL_POINTER;
res = mPersonalDictionary->RemoveWord(aWord->get(),&empty);
res = mPersonalDictionary->RemoveWord(PromiseFlatString(aWord).get(),&empty);
return res;
}
@ -293,27 +294,24 @@ mozSpellChecker::GetDictionaryList(nsStringArray *aDictionaryList)
}
NS_IMETHODIMP
mozSpellChecker::GetCurrentDictionary(nsString *aDictionary)
mozSpellChecker::GetCurrentDictionary(nsAString &aDictionary)
{
NS_ENSURE_ARG_POINTER(aDictionary);
nsXPIDLString dictname;
nsresult res;
res=mSpellCheckingEngine->GetDictionary(getter_Copies(dictname));
if(NS_SUCCEEDED(res))
*aDictionary = dictname;
aDictionary = dictname;
return NS_OK;
}
NS_IMETHODIMP
mozSpellChecker::SetCurrentDictionary(const nsString *aDictionary)
mozSpellChecker::SetCurrentDictionary(const nsAString &aDictionary)
{
NS_ENSURE_ARG_POINTER(aDictionary);
if(!mSpellCheckingEngine)
return NS_ERROR_NULL_POINTER;
nsresult res;
res = mSpellCheckingEngine->SetDictionary(aDictionary->get());
res = mSpellCheckingEngine->SetDictionary(PromiseFlatString(aDictionary).get());
if(NS_FAILED(res)){
NS_WARNING("Dictionary load failed");
return res;

Просмотреть файл

@ -57,18 +57,18 @@ public:
// nsISpellChecker
NS_IMETHOD SetDocument(nsITextServicesDocument *aDoc, PRBool aFromStartofDoc);
NS_IMETHOD NextMisspelledWord(nsString *aWord, nsStringArray *aSuggestions);
NS_IMETHOD CheckWord(const nsString *aWord, PRBool *aIsMisspelled, nsStringArray *aSuggestions);
NS_IMETHOD Replace(const nsString *aOldWord, const nsString *aNewWord, PRBool aAllOccurrences);
NS_IMETHOD IgnoreAll(const nsString *aWord);
NS_IMETHOD NextMisspelledWord(nsAString &aWord, nsStringArray *aSuggestions);
NS_IMETHOD CheckWord(const nsAString &aWord, PRBool *aIsMisspelled, nsStringArray *aSuggestions);
NS_IMETHOD Replace(const nsAString &aOldWord, const nsAString &aNewWord, PRBool aAllOccurrences);
NS_IMETHOD IgnoreAll(const nsAString &aWord);
NS_IMETHOD AddWordToPersonalDictionary(const nsString *aWord);
NS_IMETHOD RemoveWordFromPersonalDictionary(const nsString *aWord);
NS_IMETHOD AddWordToPersonalDictionary(const nsAString &aWord);
NS_IMETHOD RemoveWordFromPersonalDictionary(const nsAString &aWord);
NS_IMETHOD GetPersonalDictionary(nsStringArray *aWordList);
NS_IMETHOD GetDictionaryList(nsStringArray *aDictionaryList);
NS_IMETHOD GetCurrentDictionary(nsString *aDictionary);
NS_IMETHOD SetCurrentDictionary(const nsString *aDictionary);
NS_IMETHOD GetCurrentDictionary(nsAString &aDictionary);
NS_IMETHOD SetCurrentDictionary(const nsAString &aDictionary);
protected:
nsCOMPtr<mozISpellI18NUtil> mConverter;