public void TestEof() { var reader = new InputTextReader(CONTENT); for (var i = 0; i < CONTENT.Length - 1; i++) { reader.Read(); } Assert.False(reader.Eof()); reader.Read(); Assert.True(reader.Eof()); }
/// <summary> /// Removes all leading and trailing dots; replaces consecutive dots with a single dot /// Ex: ".lalal.....com." -> "lalal.com" /// </summary> /// <param name="host"></param> /// <returns></returns> public static string RemoveExtraDots(string host) { var stringBuilder = new StringBuilder(); var reader = new InputTextReader(host); while (!reader.Eof()) { var curr = reader.Read(); stringBuilder.Append(curr); if (curr == '.') { var possibleDot = curr; while (possibleDot == '.' && !reader.Eof()) { possibleDot = reader.Read(); } if (possibleDot != '.') { stringBuilder.Append(possibleDot); } } } if (stringBuilder.Length > 0 && stringBuilder[stringBuilder.Length - 1] == '.') { stringBuilder.Remove(stringBuilder.Length - 1, 1); } if (stringBuilder.Length > 0 && stringBuilder[0] == '.') { stringBuilder.Remove(0, 1); } return(stringBuilder.ToString()); }