Exemplo n.º 1
0
        public void AppendList(OperatorInfo op, bool explode, string variable, IList list)
        {
            foreach (object item in list)
            {
                if (op.Named && explode)
                {
                    _Result.Append(variable);
                    _Result.Append("=");
                }
                AppendValue(item.ToString(), 0, op.AllowReserved);

                _Result.Append(explode ? op.Seperator : ',');
            }
            if (list.Count > 0)
            {
                _Result.Remove(_Result.Length - 1, 1);
            }
        }
Exemplo n.º 2
0
        public void AppendDictionary(OperatorInfo op, bool explode, IDictionary<string, string> dictionary)
        {
            foreach (string key in dictionary.Keys)
            {
                _Result.Append(Encode(key, op.AllowReserved));
                if (explode) _Result.Append('='); else _Result.Append(',');
                AppendValue(dictionary[key], 0, op.AllowReserved);

                if (explode)
                {
                    _Result.Append(op.Seperator);
                }
                else
                {
                    _Result.Append(',');
                }
            }
            if (dictionary.Count() > 0)
            {
                _Result.Remove(_Result.Length - 1, 1);
            }
        }
Exemplo n.º 3
0
        private void ProcessExpression(StringBuilder currentExpression, Result result)
        {
            if (currentExpression.Length == 0)
            {
                result.ErrorDetected = true;
                result.Append("{}");
                return;
            }

            OperatorInfo op = GetOperator(currentExpression[0]);

            var  firstChar = op.Default ? 0 : 1;
            bool multivariableExpression = false;

            var varSpec = new VarSpec(op);

            for (int i = firstChar; i < currentExpression.Length; i++)
            {
                char currentChar = currentExpression[i];
                switch (currentChar)
                {
                case '*':
                    varSpec.Explode = true;
                    break;

                case ':':          // Parse Prefix Modifier
                    var prefixText = new StringBuilder();
                    currentChar = currentExpression[++i];
                    while (currentChar >= '0' && currentChar <= '9' && i < currentExpression.Length)
                    {
                        prefixText.Append(currentChar);
                        i++;
                        if (i < currentExpression.Length)
                        {
                            currentChar = currentExpression[i];
                        }
                    }
                    varSpec.PrefixLength = int.Parse(prefixText.ToString());
                    i--;
                    break;

                case ',':
                    multivariableExpression = true;
                    var  success = ProcessVariable(varSpec, result, multivariableExpression);
                    bool isFirst = varSpec.First;
                    // Reset for new variable
                    varSpec = new VarSpec(op);
                    if (success || !isFirst || _resolvePartially)
                    {
                        varSpec.First = false;
                    }
                    if (!success && _resolvePartially)
                    {
                        result.Append(",");
                    }
                    break;


                default:
                    if (IsVarNameChar(currentChar))
                    {
                        varSpec.VarName.Append(currentChar);
                    }
                    else
                    {
                        result.ErrorDetected = true;
                    }
                    break;
                }
            }

            ProcessVariable(varSpec, result, multivariableExpression);
            if (multivariableExpression && _resolvePartially)
            {
                result.Append("}");
            }
        }
Exemplo n.º 4
0
 public void AppendName(string variable, OperatorInfo op, bool valueIsEmpty)
 {
     _Result.Append(variable);
     if (valueIsEmpty) { _Result.Append(op.IfEmpty); } else { _Result.Append("="); }
 }
Exemplo n.º 5
0
 public VarSpec(OperatorInfo operatorInfo)
 {
     OperatorInfo = operatorInfo;
 }
Exemplo n.º 6
0
 public VarSpec(OperatorInfo operatorInfo)
 {
     _operatorInfo = operatorInfo;
 }