コード例 #1
0
ファイル: TermList.cs プロジェクト: krk/ExCSS
        public override string ToString()
        {
            var builder = new StringBuilder();

            for (var i = 0; i < _items.Count; i++)
            {
                builder.Append(_items[i]);

                if (i == _separator.Count)
                {
                    break;
                }

                switch (_separator[i])
                {
                case GrammarSegment.Whitespace:
                    builder.Append(" ");
                    break;

                case GrammarSegment.Comma:
                    builder.Append(",");
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            return(builder.ToString());
        }
コード例 #2
0
        public string ToString(bool friendlyFormat, int indentation = 0)
        {
            var builder = new StringBuilder();

            foreach (var property in _properties)
            {
                if (friendlyFormat)
                {
                    builder.Append(Environment.NewLine);
                }

                builder.Append(property.ToString(friendlyFormat, indentation + 1)).Append(';');
            }

            return(builder.ToString());
        }
コード例 #3
0
ファイル: StringExtensions.cs プロジェクト: krk/ExCSS
        public static string Indent(this string value, bool friendlyForamt, int indentation)
        {
            if (!friendlyForamt)
            {
                return(value);
            }

            var tabs = new StringBuilder();

            for (var i = 0; i < indentation; i++)
            {
                tabs.Append("\t");
            }
            tabs.Append(value);
            return(tabs.ToString());
        }
コード例 #4
0
ファイル: MultipleSelectorList.cs プロジェクト: krk/ExCSS
        public override string ToString(bool friendlyFormat, int indentation = 0)
        {
            var builder = new StringBuilder();

            if (Selectors.Count <= 0)
            {
                return(builder.ToString());
            }

            builder.Append(Selectors[0]);

            for (var i = 1; i < Selectors.Count; i++)
            {
                builder.Append(',').Append(Selectors[i]);
            }

            return(builder.ToString());
        }
コード例 #5
0
        public string ToString(bool friendlyFormat, int indentation = 0)
        {
            var builder = new StringBuilder();

            foreach (var rule in _rules)
            {
                builder.Append(rule.ToString(friendlyFormat, indentation));
            }

            return(builder.TrimFirstLine().TrimLastLine().ToString());
        }
コード例 #6
0
ファイル: ComplexSelector.cs プロジェクト: krk/ExCSS
        public override string ToString(bool friendlyFormat, int indentation = 0)
        {
            var builder = new StringBuilder();

            if (_selectors.Count <= 0)
            {
                return(builder.ToString());
            }

            var n = _selectors.Count - 1;

            for (var i = 0; i < n; i++)
            {
                builder.Append(_selectors[i].Selector);
                builder.Append(_selectors[i].Character);
            }

            builder.Append(_selectors[n].Selector);

            return(builder.ToString());
        }
コード例 #7
0
        public override string ToString(bool friendlyFormat, int indentation = 0)
        {
            var builder = new StringBuilder();

            foreach (var selector in Selectors)
            {
                builder.Append(selector.ToString(friendlyFormat, indentation + 1));
                builder.Append(Delimiter);
            }

            if (Delimiter.Length <= 0)
            {
                return(builder.ToString());
            }

            if (builder.Length > 0)
            {
                builder.Remove(builder.Length - 1, 1);
            }

            return(builder.ToString());
        }
コード例 #8
0
        public static string DeEntitize(string text)
        {
            if (text == null)
            {
                return(null);
            }
            if (text.Length == 0)
            {
                return(text);
            }
#if !SALTARELLE
            StringBuilder entity = null;
            StringBuilder sb     = null;
#endif
            bool flag = false;
            HtmlEntity.ParseState parseState = HtmlEntity.ParseState.Text;
            for (int i = 0; i < text.Length; i++)
            {
                switch (parseState)
                {
                case HtmlEntity.ParseState.Text:
                {
                    char c = text[i];
                    if (c == '&')
                    {
                        parseState = HtmlEntity.ParseState.EntityStart;
                    }
                    else
                    {
                        if (flag)
                        {
                            sb.Append(text[i]);
                        }
                    }
                    break;
                }

                case HtmlEntity.ParseState.EntityStart:
                {
                    if (!flag)
                    {
                        flag = true;
                        if (sb == null)
                        {
#if SALTARELLE
                            sb = new StringBuilder(text.Length);
#else
                            sb = ReseekableStringBuilder.AcquirePooledStringBuilder();
#endif
                        }
                        else
                        {
                            sb.Length = 0;
                        }
                        sb.Append(text, 0, i - 1);
                        if (entity == null)
                        {
#if SALTARELLE
                            entity = new StringBuilder(10);
#else
                            entity = ReseekableStringBuilder.AcquirePooledStringBuilder();
#endif
                        }
                        entity.Length = 0;
                    }
                    char c2 = text[i];
                    if (c2 == ';' || c2 == '<' || c2 == '"' || c2 == '\'' || HtmlEntity.IsWhiteSpace(c2))
                    {
                        bool flag2 = c2 == ';';
                        if (!flag2)
                        {
                            i--;
                        }
                        if (entity.Length == 0)
                        {
                            if (c2 == ';')
                            {
                                sb.Append("&;");
                            }
                            else
                            {
                                sb.Append('&');
                            }
                        }
                        else
                        {
                            if (entity[0] == '#')
                            {
                                string text2 = entity.ToString();
                                try
                                {
                                    string text3 = text2.SubstringCached(1).Trim().ToLowerFast();
                                    int    fromBase;
                                    if (text3.StartsWith("x"))
                                    {
                                        fromBase = 16;
                                        text3    = text3.SubstringCached(1);
                                    }
                                    else
                                    {
                                        fromBase = 10;
                                    }
#if SALTARELLE
                                    int num = int.Parse(text3, fromBase);
#else
                                    int num = Convert.ToInt32(text3, fromBase);
#endif
                                    if (num > 65535)
                                    {
#if SALTARELLE
                                        sb.Append(StringFromCodePoint(num));
#else
                                        sb.Append(char.ConvertFromUtf32(num));
#endif
                                    }
                                    else
                                    {
                                        sb.Append((char)num);
                                    }
                                    goto IL_235;
                                }
                                catch
                                {
                                    sb.Append("&#" + text2 + ";");
                                    goto IL_235;
                                }
                                goto IL_1DC;
                            }
                            goto IL_1DC;
IL_235:
                            entity.Remove(0, entity.Length);
                            goto IL_24B;
IL_1DC:
                            int num2;
#if SALTARELLE
                            num2 = HtmlEntity._entityValue[entity.ToStringCached()];
                            if (!Script.IsNullOrUndefined(num2))
                            {
                                sb.Append((char)num2);
                                goto IL_235;
                            }
#else
                            if (HtmlEntity._entityValue.TryGetValue(entity.ToStringCached(), out num2))
                            {
                                int num3 = num2;
                                sb.Append((char)num3);
                                goto IL_235;
                            }
#endif
                            sb.Append('&');
                            sb.Append(entity);
                            if (flag2)
                            {
                                sb.Append(';');
                                goto IL_235;
                            }
                            goto IL_235;
                        }
IL_24B:
                        parseState = HtmlEntity.ParseState.Text;
                    }
                    else
                    {
                        if (c2 == '&')
                        {
                            sb.Append("&" + entity);
                            entity.Remove(0, entity.Length);
                        }
                        else
                        {
                            entity.Append(text[i]);
                            if (entity.Length > HtmlEntity._maxEntitySize)
                            {
                                parseState = HtmlEntity.ParseState.Text;
                                sb.Append("&" + entity);
                                entity.Remove(0, entity.Length);
                            }
                        }
                    }
                    break;
                }
                }
            }
            if (parseState == HtmlEntity.ParseState.EntityStart && flag)
            {
                sb.Append("&" + entity);
            }
            if (!flag)
            {
                return(text);
            }
            return(sb.ToStringCached());
        }
コード例 #9
0
        private Block DoubleQuoteString(char current)
        {
            while (true)
            {
                switch (current)
                {
                case Specification.DoubleQuote:
                case Specification.EndOfFile:
                    return(StringBlock.Plain(FlushBuffer()));

                case Specification.FormFeed:
                case Specification.LineFeed:
                    ErrorHandler(ParserError.UnexpectedLineBreak, ErrorMessages.DoubleQuotedString);
                    _stylesheetReader.Back();
                    return(StringBlock.Plain(FlushBuffer(), true));

                case Specification.ReverseSolidus:
                    current = _stylesheetReader.Next;

                    if (current.IsLineBreak())
                    {
                        _buffer.AppendLine();
                    }
                    else if (current != Specification.EndOfFile)
                    {
                        _buffer.Append(ConsumeEscape(current));
                    }
                    else
                    {
                        ErrorHandler(ParserError.EndOfFile, ErrorMessages.DoubleQuotedStringEof);
                        _stylesheetReader.Back();
                        return(StringBlock.Plain(FlushBuffer(), true));
                    }

                    break;

                default:
                    _buffer.Append(current);
                    break;
                }

                current = _stylesheetReader.Next;
            }
        }