Exemplo n.º 1
0
        private static void SetRowSpanState(List <GridTableState.ColumnSlice> columns, StringSlice line, out bool isHeaderRow, out bool hasRowSpan)
        {
            var lineStart = line.Start;

            isHeaderRow = line.PeekChar(1) == '=' || line.PeekChar(2) == '=';
            hasRowSpan  = false;
            foreach (var columnSlice in columns)
            {
                if (columnSlice.CurrentCell != null)
                {
                    line.Start = lineStart + columnSlice.Start + 1;
                    line.End   = lineStart + columnSlice.End - 1;
                    line.Trim();
                    if (line.IsEmptyOrWhitespace() || !IsRowSeperator(line))
                    {
                        hasRowSpan = true;
                        columnSlice.CurrentCell.RowSpan++;
                        columnSlice.CurrentCell.AllowClose = false;
                    }
                    else
                    {
                        columnSlice.CurrentCell.AllowClose = true;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to parse a modification.
        /// </summary>
        static public bool TryParse(StringSlice inData, out VariantModification outModification)
        {
            inData = inData.Trim();

            VariantModifyOperator op = default(VariantModifyOperator);
            int operatorIdx          = -1;
            int operatorLength       = 0;

            VariantUtils.TryFindOperator(inData, '=', VariantModifyOperator.Set, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, '+', VariantModifyOperator.Add, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, '-', VariantModifyOperator.Subtract, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, '*', VariantModifyOperator.Multiply, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, '/', VariantModifyOperator.Divide, ref operatorIdx, ref op, ref operatorLength);

            if (operatorIdx < 0)
            {
                outModification = default(VariantModification);
                return(false);
            }

            outModification.Operator = op;

            StringSlice key     = inData.Substring(0, operatorIdx);
            StringSlice operand = inData.Substring(operatorIdx + 1);

            if (!TableKeyPair.TryParse(key, out outModification.VariableKey))
            {
                outModification = default(VariantModification);
                return(false);
            }

            return(VariantOperand.TryParse(operand, out outModification.Operand));
        }
Exemplo n.º 3
0
        static public void CanTrimBoth()
        {
            StringSlice firstString = "\n \tTrim Me\t\n";
            StringSlice trimmed     = firstString.Trim();

            Assert.AreEqual("Trim Me", trimmed.ToString());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns if the given string is a valid identifier.
        /// </summary>
        static public bool IsValidIdentifier(StringSlice inSlice)
        {
            inSlice = inSlice.Trim();
            if (inSlice.Length == 0)
            {
                return(false);
            }

            char c = inSlice[0];

            if (char.IsDigit(c))
            {
                return(false);
            }

            for (int i = 0; i < inSlice.Length; ++i)
            {
                c = inSlice[i];
                if (char.IsLetterOrDigit(c))
                {
                    continue;
                }
                if (c == '_' || c == '.' || c == '-')
                {
                    continue;
                }
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
        public void TestStringLineGroupWithModifiedStart()
        {
            var line1 = new StringSlice("  ABC");
            line1.NextChar();
            line1.NextChar();

            var line2 = new StringSlice("  DEF ");
            line2.Trim();

            var text = new StringLineGroup(4) {line1, line2};

            var result = ToString(text.ToCharIterator());
            TextAssert.AreEqual("ABC\nDEF", result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Attempts to parse a StringSlice into a Variant Key.
        /// Valid formats are:
        /// <list type="bullet">
        /// <item>variableId</item>
        /// <item>tableId:variableId</item>
        /// </list>
        /// </summary>
        static public bool TryParse(StringSlice inSource, out TableKeyPair outKey)
        {
            if (inSource.IsEmpty)
            {
                outKey = default(TableKeyPair);
                return(false);
            }

            inSource = inSource.Trim();

            int operatorIdx = inSource.IndexOf(TableOperator);

            if (operatorIdx >= 0)
            {
                int variantIdx = operatorIdx + TableOperator.Length;
                if (variantIdx >= inSource.Length)
                {
                    outKey = default(TableKeyPair);
                    return(false);
                }

                StringSlice tableId   = inSource.Substring(0, operatorIdx).TrimEnd();
                StringSlice variantId = inSource.Substring(variantIdx).TrimStart();

                if (!VariantUtils.IsValidIdentifier(tableId) || !VariantUtils.IsValidIdentifier(variantId))
                {
                    outKey = default(TableKeyPair);
                    return(false);
                }

                outKey = new TableKeyPair(tableId, variantId);
                return(true);
            }

            if (!VariantUtils.IsValidIdentifier(inSource))
            {
                outKey = default(TableKeyPair);
                return(false);
            }

            outKey = new TableKeyPair(inSource);
            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Parses a tag's contents into data.
        /// </summary>
        static public void Parse(StringSlice inSlice, IDelimiterRules inDelimiters, out TagData outTagData)
        {
            if (inDelimiters == null)
            {
                throw new ArgumentNullException("inDelimiters");
            }

            StringSlice tag = inSlice;

            tag = tag.Trim(MinimalWhitespaceChars);

            bool bRemovedTagBoundaries = false;

            if (tag.StartsWith(inDelimiters.TagStartDelimiter))
            {
                tag = tag.Substring(inDelimiters.TagStartDelimiter.Length);
                bRemovedTagBoundaries = true;
            }
            if (tag.EndsWith(inDelimiters.TagEndDelimiter))
            {
                tag = tag.Substring(0, tag.Length - inDelimiters.TagEndDelimiter.Length);
                bRemovedTagBoundaries = true;
            }

            if (bRemovedTagBoundaries)
            {
                tag = tag.Trim(MinimalWhitespaceChars);
            }

            if (inSlice.Length == 0)
            {
                outTagData = default(TagData);
                return;
            }

            ClosingTagState closeState = 0;

            char endDelim = inDelimiters.RegionCloseDelimiter;

            if (endDelim != 0)
            {
                if (tag.StartsWith(endDelim))
                {
                    closeState |= ClosingTagState.Start;
                    tag         = tag.Substring(1);
                }
                if (tag.EndsWith(endDelim))
                {
                    closeState |= ClosingTagState.End;
                    tag         = tag.Substring(0, tag.Length - 1);
                }
            }

            if (closeState != 0)
            {
                tag = tag.Trim(MinimalWhitespaceChars);
            }

            char[] dataDelims   = inDelimiters.TagDataDelimiters;
            int    dataDelimIdx = tag.Length;

            foreach (var delim in dataDelims)
            {
                int idx = tag.IndexOf(delim);
                if (idx >= 0 && idx < dataDelimIdx)
                {
                    dataDelimIdx = idx;
                    if (idx <= 0)
                    {
                        break;
                    }
                }
            }

            if (dataDelimIdx >= tag.Length)
            {
                outTagData.Id   = tag;
                outTagData.Data = StringSlice.Empty;
            }
            else
            {
                outTagData.Id   = tag.Substring(0, dataDelimIdx).TrimEnd(MinimalWhitespaceChars);
                outTagData.Data = tag.Substring(dataDelimIdx).TrimStart(dataDelims).TrimStart(MinimalWhitespaceChars);
            }

            outTagData.m_CloseState = closeState;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Attempts to parse a comparison.
        /// </summary>
        static public bool TryParse(StringSlice inData, out VariantComparison outComparison)
        {
            inData = inData.Trim();

            VariantCompareOperator op = VariantCompareOperator.True;
            int operatorIdx           = -1;
            int operatorLength        = 0;

            VariantUtils.TryFindOperator(inData, EqualsOperator, VariantCompareOperator.EqualTo, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, NotEqualOperator, VariantCompareOperator.NotEqualTo, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, GreaterThanOrEqualToOperator, VariantCompareOperator.GreaterThanOrEqualTo, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, LessThanOrEqualToOperator, VariantCompareOperator.LessThanOrEqualTo, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, GreaterThanOperator, VariantCompareOperator.GreaterThan, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, LessThanOperator, VariantCompareOperator.LessThan, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, NotOperator, VariantCompareOperator.False, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, ShortEqualsOperator, VariantCompareOperator.EqualTo, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, ExistsOperator, VariantCompareOperator.Exists, ref operatorIdx, ref op, ref operatorLength);
            VariantUtils.TryFindOperator(inData, DoesNotExistOperator, VariantCompareOperator.DoesNotExist, ref operatorIdx, ref op, ref operatorLength);

            if (operatorIdx < 0)
            {
                op = VariantCompareOperator.True;
            }

            outComparison.Operator = op;

            StringSlice idSlice          = StringSlice.Empty;
            StringSlice operandSlice     = StringSlice.Empty;
            bool        bRequiresOperand = true;

            switch (op)
            {
            case VariantCompareOperator.False:
            {
                idSlice          = inData.Substring(1).TrimStart();
                bRequiresOperand = false;
                break;
            }

            case VariantCompareOperator.True:
            {
                idSlice          = inData;
                bRequiresOperand = false;
                break;
            }

            case VariantCompareOperator.Exists:
            {
                idSlice          = inData.Substring(0, operatorIdx).TrimEnd();
                bRequiresOperand = false;
                break;
            }

            case VariantCompareOperator.DoesNotExist:
            {
                idSlice          = inData.Substring(0, operatorIdx).TrimEnd();
                bRequiresOperand = false;
                break;
            }

            default:
            {
                idSlice      = inData.Substring(0, operatorIdx).TrimEnd();
                operandSlice = inData.Substring(operatorIdx + operatorLength).TrimStart();
                break;
            }
            }

            if (!VariantOperand.TryParse(idSlice, out outComparison.Left))
            {
                outComparison = default(VariantComparison);
                return(false);
            }

            if (!bRequiresOperand)
            {
                outComparison.Right = default(VariantOperand);
                return(true);
            }

            return(VariantOperand.TryParse(operandSlice, out outComparison.Right));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Attempts to parse a string slice into a variant.
        /// </summary>
        static public bool TryParse(StringSlice inSlice, bool inbAllowImplicitHash, out Variant outValue)
        {
            inSlice = inSlice.Trim();

            if (inSlice.Length <= 0 || inSlice.Equals("null", true))
            {
                outValue = Variant.Null;
                return(true);
            }

            if (inSlice.StartsWith(StringHashing.CustomHashPrefix) || inSlice.StartsWith(StringHashing.StringPrefix) ||
                (inSlice.Length >= 2 && inSlice.StartsWith('"') && inSlice.EndsWith('"')))
            {
                StringHash32 hash;
                if (StringHash32.TryParse(inSlice, out hash))
                {
                    outValue = hash;
                    return(true);
                }
            }

            bool bBoolVal;

            if (StringParser.TryParseBool(inSlice, out bBoolVal))
            {
                outValue = new Variant(bBoolVal);
                return(true);
            }

            int intVal;

            if (StringParser.TryParseInt(inSlice, out intVal))
            {
                outValue = new Variant(intVal);
                return(true);
            }

            uint uintVal;

            if (StringParser.TryParseUInt(inSlice, out uintVal))
            {
                outValue = new Variant(uintVal);
                return(true);
            }

            float floatVal;

            if (StringParser.TryParseFloat(inSlice, out floatVal))
            {
                outValue = new Variant(floatVal);
                return(true);
            }

            if (inbAllowImplicitHash)
            {
                StringHash32 hash;
                if (StringHash32.TryParse(inSlice, out hash))
                {
                    outValue = hash;
                    return(true);
                }
            }

            outValue = default(Variant);
            return(false);
        }