Example #1
0
        public static String format(String _pattern, char _sep, Map <String, String> _map)
        {
            int           length_     = _pattern.Length;
            StringBuilder strBuilder_ = new StringBuilder();
            int           i_          = List.FIRST_INDEX;
            StringList    keys_       = new StringList(_map.getKeys());
            bool          quoted_     = false;

            while (i_ < length_)
            {
                if (quoted_)
                {
                    if (_pattern.ElementAt(i_) != _sep)
                    {
                        strBuilder_.Append(_pattern.ElementAt(i_));
                        i_++;
                        continue;
                    }
                    quoted_ = false;
                    i_++;
                    continue;
                }
                int nbSeqQuotes_ = SIZE_EMPTY;
                while (true)
                {
                    if (i_ >= length_)
                    {
                        break;
                    }
                    if (_pattern.ElementAt(i_) != _sep)
                    {
                        break;
                    }
                    nbSeqQuotes_++;
                    i_++;
                }
                quoted_ = nbSeqQuotes_ % 2 == 1;
                int nbAdds_ = nbSeqQuotes_ / 2;
                for (int i = SIZE_EMPTY; i < nbAdds_; i++)
                {
                    strBuilder_.Append(_sep);
                }
                if (quoted_)
                {
                    continue;
                }
                int        j_    = List.FIRST_INDEX;
                StringList list_ = keys_;
                while (true)
                {
                    StringList nexList_ = new StringList();
                    foreach (String k in list_)
                    {
                        if (k.Length <= j_)
                        {
                            continue;
                        }
                        if (k.ElementAt(j_) == _pattern.ElementAt(j_ + i_))
                        {
                            nexList_.Add(k);
                        }
                    }
                    list_ = nexList_;
                    String subString_ = _pattern.Substring(i_, j_ + 1);
                    if (list_.containsObj(subString_))
                    {
                        strBuilder_.Append(_map.getVal(subString_));
                        i_ += j_;
                        break;
                    }
                    if (list_.isEmpty())
                    {
                        strBuilder_.Append(subString_);
                        i_ += j_;
                        break;
                    }
                    j_++;
                }
                i_++;
            }
            return(strBuilder_.ToString());
        }
Example #2
0
        public static String formatBasic(String _pattern, Map <String, String> _map, bool _substringFirst)
        {
            bool          exit_;
            int           i_;
            int           length_;
            StringBuilder strBuilder_;
            StringList    keys_;
            String        subString_;

            if (_substringFirst)
            {
                length_     = _pattern.Length;
                strBuilder_ = new StringBuilder();
                i_          = List.FIRST_INDEX;
                keys_       = new StringList(_map.getKeys());
                exit_       = false;
                while (i_ < length_)
                {
                    int        j_    = List.FIRST_INDEX;
                    StringList list_ = keys_;
                    while (true)
                    {
                        StringList nexList_ = new StringList();
                        foreach (String k in list_)
                        {
                            if (k.Length <= j_)
                            {
                                continue;
                            }
                            if (k.ElementAt(j_) == _pattern.ElementAt(j_ + i_))
                            {
                                nexList_.Add(k);
                            }
                        }
                        list_ = nexList_;
                        if (_pattern.Length <= j_ + i_ + 1)
                        {
                            exit_      = true;
                            subString_ = _pattern.Substring(i_);
                            if (list_.containsObj(subString_))
                            {
                                strBuilder_.Append(_map.getVal(subString_));
                            }
                            else
                            {
                                strBuilder_.Append(subString_);
                            }
                            break;
                        }
                        subString_ = _pattern.Substring(i_, j_ + 1);
                        if (list_.containsObj(subString_))
                        {
                            strBuilder_.Append(_map.getVal(subString_));
                            i_ += j_;
                            break;
                        }
                        if (list_.isEmpty())
                        {
                            strBuilder_.Append(subString_);
                            i_ += j_;
                            break;
                        }
                        j_++;
                    }
                    if (exit_)
                    {
                        break;
                    }
                    i_++;
                }
                return(strBuilder_.ToString());
            }
            length_     = _pattern.Length;
            strBuilder_ = new StringBuilder();
            i_          = List.FIRST_INDEX;
            keys_       = new StringList(_map.getKeys());
            exit_       = false;
            while (i_ < length_)
            {
                int        j_    = List.FIRST_INDEX;
                StringList list_ = keys_;
                while (true)
                {
                    StringList nexList_ = new StringList();
                    foreach (String k in list_)
                    {
                        if (k.Length <= j_)
                        {
                            continue;
                        }
                        if (k.ElementAt(j_) == _pattern.ElementAt(j_ + i_))
                        {
                            nexList_.Add(k);
                        }
                    }
                    list_ = nexList_;
                    if (_pattern.Length <= j_ + i_ + 1)
                    {
                        exit_      = true;
                        subString_ = _pattern.Substring(i_);
                        if (list_.containsObj(subString_))
                        {
                            strBuilder_.Append(_map.getVal(subString_));
                        }
                        else
                        {
                            strBuilder_.Append(subString_);
                        }
                        break;
                    }
                    subString_ = _pattern.Substring(i_, j_ + 1);
                    StringList filterList_ = new StringList(list_);
                    bool       exist_      = false;
                    foreach (String s in filterList_)
                    {
                        if (s.Contains(subString_ + _pattern.ElementAt(j_ + i_ + 1)))
                        {
                            exist_ = true;
                            break;
                        }
                    }
                    if (list_.containsObj(subString_) && !exist_)
                    {
                        strBuilder_.Append(_map.getVal(subString_));
                        i_ += j_;
                        break;
                    }
                    if (list_.isEmpty())
                    {
                        strBuilder_.Append(subString_);
                        i_ += j_;
                        break;
                    }
                    j_++;
                }
                if (exit_)
                {
                    break;
                }
                i_++;
            }
            return(strBuilder_.ToString());
        }