コード例 #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
 /// <summary>
 /// Checks if specified url is ftp or not
 /// </summary>
 public static bool IsFTPUrl(string url)
 {
     if (StringCompare.StartsWithIgnoreCase(ref url, "ftp://"))
     {
         return(true);
     }
     return(false);
 }
コード例 #3
0
 /// <summary>
 /// Checks if specified url is javascript code or not
 /// </summary>
 public static bool IsJavascriptUrl(string path)
 {
     if (StringCompare.StartsWithMatchCase(ref path, "javascript:"))
     {
         return(true);
     }
     return(false);
 }
コード例 #4
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);
        }
コード例 #5
0
 /// <summary>
 /// Checks if the specified url is virtual
 /// </summary>
 public static bool IsVirtualUrl(string path)
 {
     path = path.ToLower();
     for (int i = 0; i < _NonVirtualUrls.Length; i++)
     {
         // MatchCase test is faster
         if (StringCompare.StartsWithMatchCase(ref path, _NonVirtualUrls[i]))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
0
        /// <summary>
        /// Removes escaped characters from start and end of phrase
        /// </summary>
        public static string RemoveEscapeQuotesFromTagAttributeValue(string value)
        {
            value = value.Trim();
            if (value.Length > 0)
            {
                // if the text started with escaped characters.
                //if (value.StartsWith("\\'") || value.StartsWith(@"\"""))
                if (StringCompare.StartsWithMatchCase(ref value, "\\'") ||
                    StringCompare.StartsWithMatchCase(ref value, @"\"""))
                {
                    // remove
                    value = value.Remove(0, 2);

                    // End of text will be checked only if begging of it oncludes escaped characters
                    if (value.Length > 0)
                    {
                        // if the text ends with ( \ ) character only,
                        // it seems there is a problem so we will prevent it by adding another ( \ ) at the end of text.
                        if (StringCompare.EndsWithMatchCase(ref value, "\\"))
                        {
                            value = value.Remove(value.Length - 1, 1) + " \\";
                        }
                        else if (StringCompare.EndsWithMatchCase(ref value, "\\'") ||
                                 StringCompare.EndsWithMatchCase(ref value, @"\"""))
                        {
                            value = value.Remove(value.Length - 1, 1);
                        }
                        //if (value.EndsWith("\\"))
                        //    value = value.Remove(value.Length - 1, 1) + " \\";
                        //else if (value.EndsWith("\\'") || value.EndsWith(@"\"""))
                        //    value = value.Remove(value.Length - 1, 1);
                    }
                }
            }
            return(value);
        }
コード例 #9
0
 public static bool IsFramesetHtml(ref string html)
 {
     return(StringCompare.IndexOfIgnoreCase(ref html, "<frameset", 0) != -1);
 }