Esempio n. 1
0
        public void HighlightSyntax()
        {
            LayoutManager.RemoveTemporaryAttribute(NSStringAttributeKey.ForegroundColor, new NSRange(0, Value.Length));

            Rule currentRule    = null;
            int  ruleStartIndex = 0;
            int  index          = 0;

            foreach (char c in Value)
            {
                if (currentRule != null)
                {
                    // check if body of match ended
                    switch (currentRule.CheckStatus(c))
                    {
                    case Rule.Status.End:
                        LayoutManager.AddTemporaryAttribute(
                            NSStringAttributeKey.ForegroundColor,
                            currentRule.Color,
                            new NSRange(ruleStartIndex, index - ruleStartIndex));
                        currentRule = null;
                        break;

                    case Rule.Status.Terminate:
                        LayoutManager.AddTemporaryAttribute(
                            NSStringAttributeKey.ForegroundColor,
                            currentRule.Color,
                            new NSRange(ruleStartIndex, index - ruleStartIndex + 1));
                        currentRule = null;
                        index++;
                        continue;
                    }
                }

                // check for a match
                if (currentRule == null)
                {
                    currentRule = Rules.FirstOrDefault(x => x.Initiators.Contains(c));

                    ruleStartIndex = index;
                }

                index++;
            }

            if (currentRule != null)
            {
                LayoutManager.AddTemporaryAttribute(
                    NSStringAttributeKey.ForegroundColor,
                    currentRule.Color,
                    new NSRange(ruleStartIndex, Value.Length - ruleStartIndex));
            }
        }