コード例 #1
0
 public void Add(Icon icon)
 {
     bool canAdd = true;
     foreach (Icon i in this.Datas)
     {
         if (i.index == icon.index)
         {
             canAdd = false;
             break;
         }
     }
     if (canAdd)
         this.Datas.Add(icon);
 }
コード例 #2
0
 public void Remove(Icon icon)
 {
     this.Datas.Remove(icon);
 }
コード例 #3
0
        public static FontIcons Parse(string aJSON)
        {
            FontIcons icons = new FontIcons();
            bool QuoteMode = false;
            bool isIndex = false;
            string token = string.Empty;
            string tokenName = string.Empty;
            Icon ctx = null;
            int i = 0;
            bool isBreak = false;
            while (i < aJSON.Length)
            {
                if (!isBreak || aJSON[i] == '{')
                {
                    isBreak = false;
                    switch (aJSON[i])
                    {
                        case '.':
                            if (QuoteMode)
                            {
                                token += aJSON[i];
                                break;
                            }
                            ctx = null;
                            isIndex = true;
                            token = string.Empty;
                            break;
                        case '"':
                            QuoteMode ^= true;
                            break;
                        case ':':
                            if (QuoteMode)
                            {
                                token += aJSON[i];
                                break;
                            }
                            if (!isIndex)
                            {
                                token = string.Empty;
                            }
                            else
                            {
                                isBreak = true;
                            }
                            break;
                        case '{':
                            if (QuoteMode)
                            {
                                token += aJSON[i];
                                break;
                            }
                            isIndex = false;
                            tokenName = token;
                            token = "";
                            if (!string.IsNullOrEmpty(tokenName))
                                ctx = new Icon(tokenName);
                            break;
                        case '\\':
                            ++i;
                            if (QuoteMode)
                            {
                                char C = aJSON[i];
                                switch (C)
                                {
                                    case 't': token += '\t'; break;
                                    case 'r': token += '\r'; break;
                                    case 'n': token += '\n'; break;
                                    case 'b': token += '\b'; break;
                                    case 'f': break;
                                    case 'u':
                                        {
                                            string s = aJSON.Substring(i + 1, 4);
                                            token += (char)int.Parse(s, System.Globalization.NumberStyles.AllowHexSpecifier);
                                            i += 4;
                                            break;
                                        }
                                    default: token += C; break;
                                }
                            }
                            break;
                        case '}':
                            if (QuoteMode)
                            {
                                token += aJSON[i];
                                break;
                            }
                            if (ctx != null)
                            {
                                ctx.setCode(token);
                                token = string.Empty;
                                icons.Add(ctx);
                            }
                            else
                            {
                                token = string.Empty;
                            }

                            break;
                        case '\r':
                        case '\n':
                            break;
                        case ' ':
                        case '\t':
                            if (QuoteMode)
                                token += aJSON[i];
                            break;
                        default:
                            token += aJSON[i];
                            break;
                    }
                    ++i;
                }
                else
                {
                    ++i;
                }
            }
            return icons;
        }