コード例 #1
0
        public static NSAttributedString DoParseIcons(this IIconText iconText)
        {
            var regex               = new Regex("{.*?}");
            var text                = iconText.Text ?? "";
            var stringBuilder       = new IconStringBuilder(iconText);
            var firstIconGroupEntry = text.IndexOf("{", StringComparison.InvariantCulture);

            if (firstIconGroupEntry != -1)
            {
                stringBuilder.AppendText(text.Substring(0, firstIconGroupEntry));
            }

            foreach (Match match in regex.Matches(text))
            {
                var icon = IconFonts.FindIconForKey(match.Value.Replace("{", "").Replace("}", ""));
                if (icon != null)
                {
                    stringBuilder.AppendIcon(icon);
                }
                else
                {
                    stringBuilder.AppendText("?");
                }

                var nextMatch = match.NextMatch();
                if (!string.IsNullOrEmpty(nextMatch.Value))
                {
                    var textToNextIcon = text.Substring(match.Index + match.Length, nextMatch.Index - match.Index - match.Length);

                    stringBuilder.AppendText(textToNextIcon);
                }
                else
                {
                    var textToEndOfLine = text.Substring(match.Index + match.Length, text.Length - match.Index - match.Length);

                    stringBuilder.AppendText(textToEndOfLine);
                }
            }

            return(stringBuilder.Text);
        }
コード例 #2
0
 public IconStringBuilder(IIconText iconText)
 {
     _iconText = iconText;
 }