Ejemplo n.º 1
0
        internal static HTMLAttribute CreateUnspecified(HTMLElement parent, string name)
        {
            HTMLAttribute r = new HTMLAttribute(parent, name, null);

            r._specified = false;
            return(r);
        }
Ejemplo n.º 2
0
        public bool?Read(HTMLElement elem)
        {
            HTMLAttribute attr = elem.getAttributeNode(this.attrName);

            if (!attr.specified)
            {
                return(false);
            }
            this._val = attr.ToString();
            return(null);
        }
Ejemplo n.º 3
0
        private AttributeKVs GetAttr(int tagIndex, string originalAttrSource)
        {
            // [src='https://github.com/sassembla/Autoya/blob/master/doc/scr.png?raw=true2' width='100' height='200' /]
            var source = originalAttrSource.TrimEnd('/');
            // Debug.LogError("source:" + source);

            var kvDict = new AttributeKVs();

            // k1="v1" k2='v2'
            // k1="v1%" k2='v2%'
            var index = 0;

            while (true)
            {
                if (source.Length <= index)
                {
                    break;
                }

                var eqIndex = source.IndexOf('=', index);
                if (eqIndex == -1)
                {
                    // no "=" found.
                    break;
                }

                // = is found.

                var           keyStr  = source.Substring(index, eqIndex - index);
                HTMLAttribute keyEnum = HTMLAttribute._UNKNOWN;
                try
                {
                    keyEnum = (HTMLAttribute)Enum.Parse(typeof(HTMLAttribute), keyStr, true);
                }
                catch (Exception e)
                {
                    parseFailed((int)ParseErrors.UNSUPPORTED_ATTR_FOUND, "at tag:" + resLoader.GetTagFromValue(tagIndex) + ", found attribute:" + keyStr + " is not supported yet, e:" + e);
                    return(null);
                }

                var valStartIndex = eqIndex + 1;

                var delim       = source[valStartIndex];
                var valEndIndex = source.IndexOf(delim, valStartIndex + 1);
                if (valEndIndex == -1)
                {
                    // no delim end found.
                    parseFailed((int)ParseErrors.UNEXPECTED_ATTR_DESCRIPTION, "attribute at tag:" + resLoader.GetTagFromValue(tagIndex) + " contains illigal description. source:" + originalAttrSource);
                    return(null);
                }

                var val = source.Substring(valStartIndex + 1, valEndIndex - (valStartIndex + 1));

                // align check.
                if (keyEnum == HTMLAttribute.ALIGN)
                {
                    try
                    {
                        Enum.Parse(typeof(AlignMode), val, true);
                    }
                    catch
                    {
                        parseFailed((int)ParseErrors.UNEXPECTED_ATTR_DESCRIPTION, "attribute align at tag:" + resLoader.GetTagFromValue(tagIndex) + " contains illigal align description. legals are:'center','left','right'. source:" + originalAttrSource);
                        return(null);
                    }
                }

                kvDict[keyEnum] = val;

                var spaceIndex = source.IndexOf(" ", valEndIndex);
                if (spaceIndex == -1)
                {
                    break;
                }

                index = spaceIndex + 1;
            }

            // foreach (var dict in kvDict) {
            //  Debug.LogError("kv:" + dict.Key + " val:" + dict.Value);
            // }

            return(kvDict);
        }