示例#1
0
        public static bool match(String _string, String _filter)
        {
            if (_filter.isEmpty())
            {
                return(true);
            }
            Pair <Pair <StringList, StringList>, Pair <Boolean, Boolean> > wordsAndSeparators_
                = wordsAndSeparators(_filter);

            Console.WriteLine(wordsAndSeparators_);
            StringList words_      = wordsAndSeparators_.getFirst().getSecond();
            StringList separators_ = wordsAndSeparators_.getFirst().getFirst();
            String     lastSep_;
            int        nbPts_     = SIZE_EMPTY;
            int        nbZeroOne_ = SIZE_EMPTY;
            int        index_     = FIRST_INDEX;

            if (words_.isEmpty())
            {
                lastSep_   = separators_.last();
                nbPts_     = 0;
                nbZeroOne_ = 0;
                index_     = FIRST_INDEX;
                foreach (char c in lastSep_.ToCharArray())
                {
                    if (c == CHARACTER)
                    {
                        nbPts_++;
                    }
                    if (c == POSSIBLE_CHAR)
                    {
                        nbZeroOne_++;
                    }
                }
                index_ += nbPts_;
                if (index_ == _string.Count())
                {
                    return(true);
                }
                if (index_ < _string.Count())
                {
                    if (lastSep_.Contains(char.ToString(STRING)))
                    {
                        return(true);
                    }
                    if (_string.Count() <= index_ + nbZeroOne_)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            if (wordsAndSeparators_.getSecond().getFirst())
            {
                separators_.Insert(FIRST_INDEX, EMPTY_STRING);
            }
            //BEGIN MODIF

            /*if (separators_.isEmpty())
             * {
             *  if (wordsAndSeparators_.getSecond().getSecond())
             *  {
             *      separators_.Add(EMPTY_STRING);
             *  }
             * }*/
            //END MODIF
            if (wordsAndSeparators_.getSecond().getSecond())
            {
                separators_.Add(EMPTY_STRING);
            }
            int i_ = FIRST_INDEX;

            index_ = FIRST_INDEX;
            int indiceRDecalePt_ = 0;
            int indiceNext_      = 0;

            foreach (String e in words_)
            {
                String sep_ = separators_.get(i_);
                nbPts_     = 0;
                nbZeroOne_ = 0;
                foreach (char c in sep_.ToCharArray())
                {
                    if (c == CHARACTER)
                    {
                        nbPts_++;
                    }
                    if (c == POSSIBLE_CHAR)
                    {
                        nbZeroOne_++;
                    }
                }
                indiceRDecalePt_ = index_ + nbPts_;
                //indiceNext_ = _string.IndexOf(e, indiceRDecalePt_);
                if (separators_.get(i_).Contains(char.ToString(STRING)))
                {
                    if (words_.isValidIndex(i_ + 1))
                    {
                        indiceNext_ = _string.IndexOf(e, indiceRDecalePt_);
                        //indiceNext_ = greatestIndex(_string, e, indiceRDecalePt_);
                        if (indiceNext_ == INDEX_NOT_FOUND_ELT)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        indiceNext_ = greatestIndex(_string, e, indiceRDecalePt_);
                        if (indiceNext_ == INDEX_NOT_FOUND_ELT)
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    indiceNext_ = _string.IndexOf(e, indiceRDecalePt_);
                    if (indiceRDecalePt_ > indiceNext_ || indiceRDecalePt_ < indiceNext_ - nbZeroOne_)
                    {
                        return(false);
                    }
                }
                index_ = indiceNext_ + e.Count();
                i_++;
            }
            Console.WriteLine(separators_);
            lastSep_ = separators_.last();
            Console.WriteLine(lastSep_ + "%" + _string + "%" + _filter);
            nbPts_     = 0;
            nbZeroOne_ = 0;
            foreach (char c in lastSep_.ToCharArray())
            {
                if (c == CHARACTER)
                {
                    nbPts_++;
                }
                if (c == POSSIBLE_CHAR)
                {
                    nbZeroOne_++;
                }
            }
            index_ += nbPts_;
            if (index_ == _string.Count())
            {
                return(true);
            }
            if (index_ < _string.Count())
            {
                if (lastSep_.Contains(char.ToString(STRING)))
                {
                    return(true);
                }
                if (_string.Count() <= index_ + nbZeroOne_)
                {
                    return(true);
                }
            }
            return(false);
        }