Exemple #1
0
        private static bool HighlightInvalid(SprPart pPart, List <SprStyle> lStyles,
                                             Stack <SprPart> sToDo, SprContext ctx)
        {
            bool bAT = ((ctx != null) && ctx.EncodeAsAutoTypeSequence);

            if (!bAT)
            {
                return(false);
            }

            string str = pPart.Text;
            int    p   = str.IndexOf('}');

            if (p >= 0)
            {
                Debug.Assert(str.IndexOf('{') < 0);                 // Must be called after regular

                sToDo.Push(pPart.GetPart(p + 1));

                SetStyle(lStyles, pPart, 0, p + 1, SprStyleError);
                return(true);
            }

            return(false);
        }
Exemple #2
0
        private static bool HighlightRegularPlh(SprPart pPart, List <SprStyle> lStyles,
                                                Stack <SprPart> sToDo, SprContext ctx)
        {
            string str = pPart.Text;

            int iStart = str.IndexOf('{');

            if (iStart < 0)
            {
                return(false);
            }

            if ((iStart + 2) >= str.Length)
            {
                SetStyle(lStyles, pPart, iStart, str.Length - iStart, SprStyleError);
            }
            else
            {
                int iOpen  = str.IndexOf('{', iStart + 2);
                int iClose = str.IndexOf('}', iStart + 2);

                bool bAT = ((ctx != null) && ctx.EncodeAsAutoTypeSequence);

                if (iClose < 0)
                {
                    SetStyle(lStyles, pPart, iStart, str.Length - iStart, SprStyleError);
                }
                else if ((iOpen >= 0) && (iOpen < iClose))
                {
                    sToDo.Push(pPart.GetPart(iOpen));

                    SetStyle(lStyles, pPart, iStart, iOpen - iStart, SprStyleError);
                }
                else if (bAT && ((str[iStart + 1] == '{') || (str[iStart + 1] == '}')) &&
                         (iClose != (iStart + 2)))
                {
                    sToDo.Push(pPart.GetPart(iClose + 1));

                    SetStyle(lStyles, pPart, iStart, iClose - iStart + 1, SprStyleError);
                }
                else
                {
                    sToDo.Push(pPart.GetPart(iClose + 1));

                    int iErrLvl = 0;

                    string strPlh = str.Substring(iStart + 1, iClose - iStart - 1);
                    if (strPlh.Length == 0)
                    {
                        Debug.Assert(false); iErrLvl = 2;
                    }
                    else if (char.IsWhiteSpace(strPlh[0]))
                    {
                        iErrLvl = 2;
                    }
                    else if (strPlh.StartsWith("S:", StrUtil.CaseIgnoreCmp) &&
                             (ctx != null) && (ctx.Entry != null))
                    {
                        string strField = strPlh.Substring(2);

                        List <string> lFields = PwDefs.GetStandardFields();
                        lFields.AddRange(ctx.Entry.Strings.GetKeys());

                        bool bFound = false;
                        foreach (string strAvail in lFields)
                        {
                            if (strField.Equals(strAvail, StrUtil.CaseIgnoreCmp))
                            {
                                bFound = true;
                                break;
                            }
                        }

                        if (!bFound)
                        {
                            iErrLvl = 1;
                        }
                    }

                    SprStyle s = SprStyleOK;
                    if (iErrLvl == 1)
                    {
                        s = SprStyleWarning;
                    }
                    else if (iErrLvl > 1)
                    {
                        s = SprStyleError;
                    }

                    SetStyle(lStyles, pPart, iStart, iClose - iStart + 1, s);
                }
            }

            if (iStart > 0)
            {
                sToDo.Push(pPart.GetPart(0, iStart));
            }
            return(true);
        }
Exemple #3
0
        private static bool HighlightDynSepPlh(SprPart pPart, List <SprStyle> lStyles,
                                               Stack <SprPart> sToDo)
        {
            string str = pPart.Text;

            int iStart = -1, p = -1;

            foreach (string strPlh in m_vDynSepPlh)
            {
                iStart = str.IndexOf(strPlh, StrUtil.CaseIgnoreCmp);
                if (iStart >= 0)
                {
                    p = iStart + strPlh.Length;
                    break;
                }
            }
            if (iStart < 0)
            {
                return(false);
            }

            try
            {
                if (p >= str.Length)
                {
                    throw new FormatException();
                }

                char chSep = str[p];

                while (true)
                {
                    if ((p + 1) >= str.Length)
                    {
                        throw new FormatException();
                    }

                    if (str[p + 1] == '}')
                    {
                        break;
                    }

                    int q = str.IndexOf(chSep, p + 1);
                    if (q < 0)
                    {
                        throw new FormatException();
                    }

                    p = q;
                }

                Debug.Assert(str[p + 1] == '}');
                if ((p + 2) < str.Length)
                {
                    sToDo.Push(pPart.GetPart(p + 2));
                }

                SetStyle(lStyles, pPart, iStart, (p + 1) - iStart + 1, SprStyleRaw);
            }
            catch (Exception)
            {
                SetStyle(lStyles, pPart, iStart, str.Length - iStart, SprStyleError);
            }

            if (iStart > 0)
            {
                sToDo.Push(pPart.GetPart(0, iStart));
            }
            return(true);
        }