Skip to content

Commit

Permalink
Bug 1089298, part 2: Save the search needle as UTF-16 instead of UTF-…
Browse files Browse the repository at this point in the history
…8, r=rkent.

--HG--
extra : rebase_source : 2fbbf4e393e93ec7ac92c6bfc0b7042554a417ff
  • Loading branch information
jcranmer committed Feb 19, 2015
1 parent 60b141e commit 8be225e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
3 changes: 3 additions & 0 deletions mailnews/base/search/public/nsMsgSearchCore.idl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ interface nsMsgSearchBooleanOp {
[ptr] native nsMsgSearchValue(nsMsgSearchValue);

%{C++
#include "nsStringGlue.h"

typedef struct nsMsgSearchValue
{
nsMsgSearchAttribValue attribute;
Expand All @@ -197,6 +199,7 @@ typedef struct nsMsgSearchValue
uint32_t junkPercent;
} u;
char *string;
nsString utf16String;
} nsMsgSearchValue;
%}

Expand Down
13 changes: 4 additions & 9 deletions mailnews/base/search/src/nsMsgSearchTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ nsresult nsMsgSearchTerm::ParseValue(char *inStream)
m_value.string = (char *) PR_Malloc(valueLen + 1);
PL_strncpy(m_value.string, inStream, valueLen + 1);
m_value.string[valueLen] = '\0';
CopyUTF8toUTF16(m_value.string, m_value.utf16String);
}
else
{
Expand Down Expand Up @@ -733,6 +734,7 @@ nsresult nsMsgSearchTerm::DeStreamNew (char *inStream, int16_t /*length*/)
m_value.attribute = m_attribute = nsMsgSearchAttrib::Keywords;
keyword.Append('0' + m_value.u.label);
m_value.string = PL_strdup(keyword.get());
CopyUTF8toUTF16(m_value.string, m_value.utf16String);
}
return NS_OK;
}
Expand Down Expand Up @@ -1136,15 +1138,7 @@ nsresult nsMsgSearchTerm::MatchString(const nsAString &utf16StrToMatch,
bool result = false;

nsresult rv = NS_OK;
nsAutoString needle;

// Save some performance for opIsEmpty / opIsntEmpty
if(nsMsgSearchOp::IsEmpty != m_operator && nsMsgSearchOp::IsntEmpty != m_operator)
{
NS_ASSERTION(MsgIsUTF8(nsDependentCString(m_value.string)),
"m_value.string is not UTF-8");
CopyUTF8toUTF16(nsDependentCString(m_value.string), needle);
}
auto needle = m_value.utf16String;

switch (m_operator)
{
Expand Down Expand Up @@ -2033,6 +2027,7 @@ nsresult nsMsgResultElement::AssignValues (nsIMsgSearchValue *src, nsMsgSearchVa
nsString unicodeString;
rv = src->GetStr(unicodeString);
dst->string = ToNewUTF8String(unicodeString);
dst->utf16String = unicodeString;
}
else
rv = NS_ERROR_INVALID_ARG;
Expand Down
11 changes: 6 additions & 5 deletions mailnews/base/search/src/nsMsgSearchValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ nsMsgSearchValueImpl::nsMsgSearchValueImpl(nsMsgSearchValue *aInitialValue)
{
mValue = *aInitialValue;
if (IS_STRING_ATTRIBUTE(aInitialValue->attribute) && aInitialValue->string)
{
mValue.string = NS_strdup(aInitialValue->string);
CopyUTF8toUTF16(mValue.string, mValue.utf16String);
}
else
mValue.string = 0;
}
Expand Down Expand Up @@ -59,10 +62,7 @@ NS_IMETHODIMP
nsMsgSearchValueImpl::GetStr(nsAString &aResult)
{
NS_ENSURE_TRUE(IS_STRING_ATTRIBUTE(mValue.attribute), NS_ERROR_ILLEGAL_VALUE);
if (mValue.string)
CopyUTF8toUTF16(nsDependentCString(mValue.string), aResult);
else
aResult.Truncate();
aResult = mValue.utf16String;
return NS_OK;
}

Expand All @@ -73,6 +73,7 @@ nsMsgSearchValueImpl::SetStr(const nsAString &aValue)
if (mValue.string)
NS_Free(mValue.string);
mValue.string = ToNewUTF8String(aValue);
mValue.utf16String = aValue;
return NS_OK;
}

Expand All @@ -81,7 +82,7 @@ nsMsgSearchValueImpl::ToString(nsAString &aResult)
{
aResult.AssignLiteral("[nsIMsgSearchValue: ");
if (IS_STRING_ATTRIBUTE(mValue.attribute)) {
aResult.Append(NS_ConvertUTF8toUTF16(mValue.string));
aResult.Append(mValue.utf16String);
return NS_OK;
}

Expand Down

0 comments on commit 8be225e

Please sign in to comment.