/// <summary> /// Creates a new instance of the DomainNameReader object. /// @param reader The input stream to read. /// @param buffer The string buffer to use for storing a domain name. /// @param current The current string that was thought to be a domain name. /// @param options The detector options of this reader. /// @param characterHandler The handler to call on each non-matching character to count matching quotes and stuff. /// </summary> public DomainNameReader( InputTextReader reader, StringBuilder buffer, string current, UrlDetectorOptions options, //CharacterHandler characterHandler Action <char> characterHandler ) { _buffer = buffer; _current = current; _reader = reader; _options = options; _characterHandler = characterHandler; }
/// <summary> /// Creates a new UrlDetector object used to find urls inside of text. /// @param content The content to search inside of. /// @param options The UrlDetectorOptions to use when detecting the content. /// </summary> /// <param name="content"></param> /// <param name="options"></param> /// <param name="validSchemes"></param> public UrlDetector(string content, UrlDetectorOptions options, HashSet <string> validSchemes = null) { _reader = new InputTextReader(content); _options = options; if (validSchemes == null || validSchemes.Count == 0) { validSchemes = new HashSet <string> { "http", "https", "ftp", "ftps" } } ; SetValidSchemes(validSchemes); }
/// <summary> /// Splits a string without the use of a regex, which could split either by isDot() or %2e /// @param input the input string that will be split by dot /// @return an array of strings that is a partition of the original string split by dot /// </summary> /// <param name="input"></param> /// <returns></returns> public static string[] SplitByDot(string input) { var splitList = new List <string>(); var section = new StringBuilder(); if (string.IsNullOrEmpty(input)) { return(new[] { "" }); } var reader = new InputTextReader(input); while (!reader.Eof()) { var curr = reader.Read(); if (IsDot(curr)) { splitList.Add(section.ToString()); section.Length = 0; } else if (curr == '%' && reader.CanReadChars(2) && reader.Peek(2).Equals("2e", StringComparison.InvariantCultureIgnoreCase)) { reader.Read(); reader.Read(); //advance past the 2e splitList.Add(section.ToString()); section.Length = 0; } else { section.Append(curr); } } splitList.Add(section.ToString()); return(splitList.ToArray()); }