예제 #1
0
        /// <summary>
        /// Removes URL attribute in css urls like this: url(other.css) will change to "other.css"
        /// </summary>
        public static bool RemoveUrlAttribCssLocation(string text, out string result)
        {
            result = text;
            const string urlAttrib = "url(";
            const string urlEnd    = ")";

            // start attrib
            int start = StringCompare.IndexOfIgnoreCase(ref text, urlAttrib);

            if (start == -1)
            {
                return(false);
            }
            text = text.Remove(start, urlAttrib.Length);

            // end attrib
            start = StringCompare.IndexOfMatchCase(ref text, urlEnd);
            if (start == -1)
            {
                return(false);
            }
            text = text.Remove(start, urlEnd.Length);

            result = text;
            return(true);
        }
예제 #2
0
        public static string GetContentType(ref string html, string defaultValue)
        {
            string result = defaultValue;
            int    end, tmp, start = StringCompare.IndexOfIgnoreCase(ref html, "<meta");

            if (start == -1)
            {
                return(result);
            }

            tmp = StringCompare.IndexOfIgnoreCase(ref html, "http-equiv=\"content-type\"", start);
            if (tmp == -1)
            {
                tmp = StringCompare.IndexOfIgnoreCase(ref html, "http-equiv='content-type'", start);
                if (tmp == -1)
                {
                    tmp = StringCompare.IndexOfIgnoreCase(ref html, "http-equiv=content-type", start);
                    if (tmp == -1)
                    {
                        tmp = StringCompare.IndexOfIgnoreCase(ref html, "http-equiv= content-type", start);
                        if (tmp == -1)
                        {
                            return(result);
                        }
                    }
                }
            }
            start = tmp;

            start = StringCompare.IndexOfIgnoreCase(ref html, "charset", start);
            if (start == -1)
            {
                return(result);
            }
            start = StringCompare.IndexOfIgnoreCase(ref html, "=", start);
            if (start == -1)
            {
                return(result);
            }
            start++;

            end = StringCompare.IndexOfIgnoreCase(ref html, "\"", start);
            if (end == -1)
            {
                return(result);
            }
            tmp = StringCompare.IndexOfIgnoreCase(ref html, "\'", start);
            if (tmp > start && end > tmp)
            {
                end = tmp;
            }

            result = html.Substring(start, end - start);
            result = result.Trim();
            return(result);
        }
예제 #3
0
        /// <summary>
        /// Finds and returns DOCTYPE definition.
        /// </summary>
        public static string GetDocType(ref string html)
        {
            const string startTag = "<!DOCTYPE";
            const string endTag = ">";
            int          start, end;
            string       result = "";

            start = StringCompare.IndexOfIgnoreCase(ref html, startTag);
            if (start == -1)
            {
                return(result);
            }

            end = StringCompare.IndexOfIgnoreCase(ref html, endTag, start);
            if (end == -1)
            {
                return(result);
            }

            // add a character length to position
            end++;

            // Test start tag
            if (start > 0)
            {
                // DocType should be first tag in html document
                string temp = html.Substring(0, start).Trim();
                if (temp.Length > 0 && temp.IndexOf('<') != -1)
                {
                    return(result);
                }
            }

            // substring
            result = html.Substring(start, end - start);

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Specifies that a string with specified position index, is enclosed by some tags
        /// </summary>
        public static bool IsEnclosedBy(ref string htmlCode, int index, string startTag, string endTag)
        {
            int start = StringCompare.LastIndexOfIgnoreCase(ref htmlCode, startTag, index);

            if (start == -1)
            {
                return(false);
            }

            int end = StringCompare.IndexOfIgnoreCase(ref htmlCode, endTag, start);

            if (end == -1)
            {
                return(true);
            }

            if (end > index)
            {
                return(true);
            }

            return(false);
        }
예제 #5
0
 public static bool IsFramesetHtml(ref string html)
 {
     return(StringCompare.IndexOfIgnoreCase(ref html, "<frameset", 0) != -1);
 }