/*
Filter list data
The source list can be empty or the same as the source list. In this case, only the target list can be deleted without matching the source list.
If the target list and source list addresses are different, the matching Character List is extracted from the source list.
*/
Int filter_list (clistbox * pdstlist, // target list
Clistbox * psrclist, // source list
Lpctstr pszfilter, // match characters
Bool bmatchcase // case-insensitive indication
)
{
Assert (pdstlist); // make sure the list address is valid
If (psrclist & psrclist! = Pdstlist) // the target list and source list address are not the same
{
Pdstlist-> resetcontent (); // clear the list
For (INT I = 0; I <psrclist-> getcount (); I ++)
{
Cstring itemstr;
Psrclist-> gettext (I, itemstr );
Pdstlist-> addstring (itemstr); // Add a string
Pdstlist-> setitemdata (I, psrclist-> getitemdata (I); // copy attributes
}
}
Cstring filter = pszfilter;
Int filter_len = filter. getlength ();
If (filter_len> 0 &&! Bmatchcase) // case insensitive
Filter. makeupper ();
If (strlen (pszfilter)> 0) // The length of the matched string is greater than 0.
{
For (INT I = 0; I <pdstlist-> getcount (); I ++)
{
Cstring itemstr;
Pdstlist-> gettext (I, itemstr );
If (! Bmatchcase)
Itemstr. makeupper ();
If (itemstr. getlength ()> = filter_len
& Itemstr. Left (filter_len) = filter)
{
}
Else // Delete if no match exists
{
Pdstlist-> deletestring (I );
I --; // ensure that the next time the list is deleted
}
}
}
Return (pdstlist-> getcount ());
}