Exemple #1
0
        /// <summary>
        /// 格式化样式表
        /// </summary>
        /// <param name="style">样式表</param>
        /// <returns>样式表</returns>
        private static unsafe string formatStyle(string style)
        {
            if (style != null)
            {
                Dictionary <subString, subString> values = dictionary.CreateSubString <subString>();
                foreach (subString value in style.split(';'))
                {
                    int index = value.IndexOf(':');
                    if (index != -1)
                    {
                        subString name = value.Substring(0, index).toLower();
                        //showjim 修改为数组索引模式
                        if (fastCSharp.web.html.SafeStyleAttributes.Contains(name.ToString()))
                        {
                            values[name] = value.Substring(++index);
                        }
                    }
                }
                if (values.Count != 0)
                {
                    int length = (values.Count << 1) - 1;
                    foreach (KeyValuePair <subString, subString> value in values)
                    {
                        length += value.Key.Length + value.Value.Length;
                    }
                    string newStyle = fastCSharp.String.FastAllocateString(length);
                    byte * bits     = htmlNode.Bits.Byte;
                    fixed(char *newStyleFixed = newStyle, styleFixed = style)
                    {
                        char *write = newStyleFixed;

                        foreach (KeyValuePair <subString, subString> value in values)
                        {
                            if (write != newStyleFixed)
                            {
                                *write++ = ';';
                            }
                            for (char *start = styleFixed + value.Key.StartIndex, end = start + value.Key.Length; start != end; *write++ = *start++)
                            {
                                ;
                            }
                            *write++ = ':';
                            for (char *start = styleFixed + value.Value.StartIndex, end = start + value.Value.Length; start != end; ++start)
                            {
                                *write++ = ((bits[*(byte *)start] & htmlNode.CssFilterBit) | *(((byte *)start) + 1)) == 0 ? ' ' : *start;
                            }
                        }
                    }

                    return(newStyle);
                }
            }
            return(null);
        }
Exemple #2
0
            /// <summary>
            /// 加载配置文件
            /// </summary>
            /// <param name="file">配置文件</param>
            private unsafe void load(FileInfo file)
            {
                if (file.Exists)
                {
                    string fileName = file.FullName.fileNameToLower();
                    int    count    = files.length;
                    if (count != 0)
                    {
                        foreach (string name in files.array)
                        {
                            if (errors.length == 0)
                            {
                                if (name == fileName)
                                {
                                    errors.Add("配置文件循环嵌套");
                                    errors.Add(name);
                                }
                            }
                            else
                            {
                                errors.Add(name);
                            }
                            if (--count == 0)
                            {
                                break;
                            }
                        }
                        if (errors.length != 0)
                        {
                            log.Error.Real(errors.joinString(@"
"), new System.Diagnostics.StackFrame(), false);
                            errors.Empty();
                        }
                    }
                    string config = File.ReadAllText(fileName, appSetting.Encoding);
                    fixed(char *configFixed = config)
                    {
                        for (char *current = configFixed, end = configFixed + config.Length; current != end;)
                        {
                            char *start = current;
                            while (*current != '=' && ++current != end)
                            {
                                ;
                            }
                            if (current == end)
                            {
                                break;
                            }
                            subString name = subString.Unsafe(config, (int)(start - configFixed), (int)(current - start));
                            if (name.Equals(appSetting.ConfigIncludeName))
                            {
                                for (start = ++current; current != end && *current != '\n'; ++current)
                                {
                                    ;
                                }
                                Load(Path.Combine(file.DirectoryName, config.Substring((int)(start - configFixed), (int)(current - start)).Trim()));
                                if (current == end)
                                {
                                    break;
                                }
                                ++current;
                            }
                            else
                            {
                                for (start = ++current; current != end; ++current)
                                {
                                    if (*current == '\n')
                                    {
                                        while (++current != end && *current == '\n')
                                        {
                                            ;
                                        }
                                        if (current == end)
                                        {
                                            break;
                                        }
                                        if (*current != '\t' && *current != ' ')
                                        {
                                            break;
                                        }
                                    }
                                }
                                hashString nameKey = name;
                                if (configs.ContainsKey(nameKey))
                                {
                                    log.Error.Real("重复的配置名称 : " + name.ToString(), new System.Diagnostics.StackFrame(), false);
                                }
                                else
                                {
                                    configs.Add(nameKey, subString.Unsafe(config, (int)(start - configFixed), (int)(current - start)));
                                }
                            }
                        }
                    }
                }
                else
                {
                    log.Default.Real("找不到配置文件 : " + file.FullName, new System.Diagnostics.StackFrame(), false);
                }
            }