iTextSharp.tool.xml.html.HTMLUtils.Sanitize C# (CSharp) Method

Sanitize() public static method

public static Sanitize ( String str, bool trim ) : String
str String
trim bool
return String
        public static String Sanitize(String str, bool trim)
        {
            StringBuilder builder = new StringBuilder();
            char previous = '\0';
            bool first = true;
            bool gotChar = false;
            foreach (char c in str) {
                if (!IsWhiteSpace(c)) {
                    if (((!gotChar && !trim) || gotChar)  && !first && IsWhiteSpace(previous)) {
                        builder.Append(' ');
                    }
                    builder.Append(c);
                    gotChar = true;
                }
                previous = c;
                first = false;
            }
            if (gotChar && !trim && IsWhiteSpace(previous)) {
                builder.Append(' ');
            }
            return builder.ToString();
        }

Same methods

HTMLUtils::Sanitize ( String str ) : String

Usage Example

Example #1
0
        /*
         * (non-Javadoc)
         *
         * @see
         * com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag,
         * java.util.List, com.itextpdf.text.Document, java.lang.String)
         */
        public override IList <IElement> Content(IWorkerContext ctx, Tag tag, String content)
        {
            List <Chunk>    sanitizedChunks = HTMLUtils.Sanitize(content, false);
            List <IElement> l = new List <IElement>(1);

            foreach (Chunk sanitized in sanitizedChunks)
            {
                HtmlPipelineContext myctx;
                try {
                    myctx = GetHtmlPipelineContext(ctx);
                } catch (NoCustomContextException e) {
                    throw new RuntimeWorkerException(e);
                }
                if (tag.CSS.ContainsKey(CSS.Property.TAB_INTERVAL))
                {
                    TabbedChunk tabbedChunk = new TabbedChunk(sanitized.Content);
                    if (null != GetLastChild(tag) && GetLastChild(tag).CSS.ContainsKey(CSS.Property.XFA_TAB_COUNT))
                    {
                        tabbedChunk.TabCount = int.Parse(GetLastChild(tag).CSS[CSS.Property.XFA_TAB_COUNT]);
                    }
                    l.Add(GetCssAppliers().Apply(tabbedChunk, tag, myctx));
                }
                else if (null != GetLastChild(tag) && GetLastChild(tag).CSS.ContainsKey(CSS.Property.XFA_TAB_COUNT))
                {
                    TabbedChunk tabbedChunk = new TabbedChunk(sanitized.Content);
                    tabbedChunk.TabCount = int.Parse(GetLastChild(tag).CSS[CSS.Property.XFA_TAB_COUNT]);
                    l.Add(GetCssAppliers().Apply(tabbedChunk, tag, myctx));
                }
                else
                {
                    l.Add(GetCssAppliers().Apply(sanitized, tag, myctx));
                }
            }
            return(l);
        }
All Usage Examples Of iTextSharp.tool.xml.html.HTMLUtils::Sanitize