Bug #379070 --> re-write MsgFindKeyword so it doesn't take string iterators.

sr=bienvenu
This commit is contained in:
scott%scott-macgregor.org 2007-06-14 03:16:34 +00:00
Родитель 0dcbc6fdb8
Коммит 29b9f97fd2
5 изменённых файлов: 32 добавлений и 52 удалений

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

@ -5047,8 +5047,8 @@ NS_IMETHODIMP nsMsgDBFolder::AddKeywordsToMessages(nsISupportsArray *aMessages,
keywordArray.ParseString(nsCString(aKeywords).get(), " ");
for (PRInt32 j = 0; j < keywordArray.Count(); j++)
{
nsACString::const_iterator start, end;
if (!MsgFindKeyword(*(keywordArray[j]), keywords, start, end))
PRInt32 start, length;
if (!MsgFindKeyword(*(keywordArray[j]), keywords, &start, &length))
{
if (!keywords.IsEmpty())
keywords.Append(' ');
@ -5102,13 +5102,10 @@ NS_IMETHODIMP nsMsgDBFolder::RemoveKeywordsFromMessages(nsISupportsArray *aMessa
if (labelValue == (nsMsgLabelValue) (keywordArray[j]->CharAt(6) - '0'))
message->SetLabel((nsMsgLabelValue) 0);
}
nsACString::const_iterator start, end;
nsACString::const_iterator saveStart;
keywords.BeginReading(saveStart);
if (MsgFindKeyword(*(keywordArray[j]), keywords, start, end))
PRInt32 startOffset, length;
if (MsgFindKeyword(*(keywordArray[j]), keywords, &startOffset,&length))
{
keywords.Cut(Distance(saveStart, start), Distance(start, end));
keywords.Cut(startOffset, length);
NS_ASSERTION(keywords.IsEmpty() || keywords.CharAt(0) != ' ', "space only keyword");
}
}

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

@ -1292,20 +1292,26 @@ nsresult MsgReopenFileStream(nsILocalFile *file, nsIInputStream *fileStream)
return NS_ERROR_FAILURE;
}
PRBool MsgFindKeyword(const nsACString &keyword, nsACString &keywords, nsACString::const_iterator &start, nsACString::const_iterator &end)
PRBool MsgFindKeyword(const nsCString &keyword, nsCString &keywords, PRInt32 *aStartOfKeyword, PRInt32 *aLength)
{
keywords.BeginReading(start);
keywords.EndReading(end);
const char * start = keywords.BeginReading();
const char * end = keywords.EndReading();
if (*start == ' ')
start++;
nsACString::const_iterator saveStart(start), saveEnd(end);
const char * saveStart = start;
const char * saveEnd = end;
PRInt32 offset = 0;
while (PR_TRUE)
{
if (FindInReadable(keyword, start, end))
offset = keywords.Find(keyword, offset);
if (offset >= 0)
{
start += offset;
end = start + keyword.Length();
PRBool beginMatches = start == saveStart;
PRBool endMatches = end == saveEnd;
nsACString::const_iterator beforeStart(start);
const char * beforeStart = start;
beforeStart--;
// start and end point to the beginning and end of the match
if (beginMatches && (end == saveEnd || *end == ' ')
@ -1316,14 +1322,19 @@ PRBool MsgFindKeyword(const nsACString &keyword, nsACString &keywords, nsACStrin
end++;
if (*beforeStart == ' ' && endMatches)
start--;
*aStartOfKeyword = start - saveStart;
*aLength = end - start;
return PR_TRUE;
}
else
start = end; // advance past bogus match.
}
else
break;
break;
}
*aStartOfKeyword = -1;
*aLength = 0;
return PR_FALSE;
}

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

@ -167,9 +167,7 @@ NS_MSG_BASE nsresult MsgReopenFileStream(nsILocalFile *file, nsIInputStream *fil
// fills in the position of the passed in keyword in the passed in keyword list
// and returns false if the keyword isn't present
NS_MSG_BASE PRBool MsgFindKeyword(const nsACString &keyword, nsACString &keywords,
nsACString::const_iterator &start,
nsACString::const_iterator &end);
NS_MSG_BASE PRBool MsgFindKeyword(const nsCString &keyword, nsCString &keywords, PRInt32 *aStartOfKeyword, PRInt32 *aLength);
NS_MSG_BASE PRBool MsgHostDomainIsTrusted(nsCString &host, nsCString &trustedMailDomains);

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

@ -224,25 +224,6 @@ NS_IMETHODIMP nsMsgOfflineImapOperation::GetKeywordsToAdd(char * *aKeywords)
NS_IMETHODIMP nsMsgOfflineImapOperation::AddKeywordToAdd(const char * aKeyword)
{
return AddKeyword(aKeyword, m_keywordsToAdd, PROP_KEYWORD_ADD, m_keywordsToRemove, PROP_KEYWORD_REMOVE);
nsACString::const_iterator start, end;
if (!MsgFindKeyword(nsDependentCString(aKeyword), m_keywordsToAdd, start, end))
{
if (!m_keywordsToAdd.IsEmpty())
m_keywordsToAdd.Append(' ');
m_keywordsToAdd.Append(aKeyword);
}
// if the keyword we're adding was in the list of keywords to remove,
// cut it from that list.
nsACString::const_iterator removeStart, removeEnd;
if (MsgFindKeyword(nsDependentCString(aKeyword), m_keywordsToRemove, removeStart, removeEnd))
{
nsACString::const_iterator saveStart;
m_keywordsToRemove.BeginReading(saveStart);
m_keywordsToRemove.Cut(Distance(saveStart, removeStart), Distance(removeStart, removeEnd));
m_mdb->SetProperty(m_mdbRow, PROP_KEYWORD_REMOVE, m_keywordsToRemove.get());
}
SetOperation(kAddKeywords);
return m_mdb->SetProperty(m_mdbRow, PROP_KEYWORD_ADD, m_keywordsToAdd.get());
}
NS_IMETHODIMP nsMsgOfflineImapOperation::GetKeywordsToRemove(char * *aKeywords)
@ -256,8 +237,8 @@ NS_IMETHODIMP nsMsgOfflineImapOperation::GetKeywordsToRemove(char * *aKeywords)
nsresult nsMsgOfflineImapOperation::AddKeyword(const char *aKeyword, nsCString &addList, const char *addProp,
nsCString &removeList, const char *removeProp)
{
nsACString::const_iterator start, end;
if (!MsgFindKeyword(nsDependentCString(aKeyword), addList, start, end))
PRInt32 startOffset, keywordLength;
if (!MsgFindKeyword(nsDependentCString(aKeyword), addList, &startOffset, &keywordLength))
{
if (!addList.IsEmpty())
addList.Append(' ');
@ -265,12 +246,9 @@ nsresult nsMsgOfflineImapOperation::AddKeyword(const char *aKeyword, nsCString &
}
// if the keyword we're removing was in the list of keywords to add,
// cut it from that list.
nsACString::const_iterator addStart, addEnd;
if (MsgFindKeyword(nsDependentCString(aKeyword), removeList, addStart, addEnd))
if (MsgFindKeyword(nsDependentCString(aKeyword), removeList, &startOffset, &keywordLength))
{
nsACString::const_iterator saveStart;
removeList.BeginReading(saveStart);
removeList.Cut(Distance(saveStart, addStart), Distance(addStart, addEnd));
removeList.Cut(startOffset, keywordLength);
m_mdb->SetProperty(m_mdbRow, removeProp, removeList.get());
}
SetOperation(kRemoveKeywords);

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

@ -3782,20 +3782,16 @@ nsresult nsMsgLocalMailFolder::ChangeKeywordForMessages(nsISupportsArray *aMessa
break;
else
continue;
PRInt32 keywordHdrLength = keywordHeaders.Length();
nsACString::const_iterator start, end;
nsACString::const_iterator keywordHdrStart;
keywordHeaders.BeginReading(keywordHdrStart);
PRInt32 startOffset, keywordLength;
// check if we have the keyword
if (MsgFindKeyword(*(keywordArray[j]), keywordHeaders, start, end))
if (MsgFindKeyword(*(keywordArray[j]), keywordHeaders, &startOffset, &keywordLength))
{
foundKeyword = PR_TRUE;
if (!add) // if we're removing, remove it, and break;
{
PRInt32 keywordStartOffset = Distance(keywordHdrStart, start);
keywordHeaders.Cut(keywordStartOffset, Distance(start, end));
for (PRInt32 i = Distance(start, end); i > 0; i--)
keywordHeaders.Cut(startOffset, keywordLength);
for (PRInt32 i = keywordLength; i > 0; i--)
keywordHeaders.Append(' ');
seekableStream->Seek(nsISeekableStream::NS_SEEK_SET, lineStartPos);
fileStream->Write(keywordHeaders.get(), keywordHeaders.Length(), &bytesWritten);