public void Compare() { using (new CultureSwapper(PredefinedCulture.EnglishUnitedStates)) { Assert.AreEqual(0, Math.Sign(Substring.Compare("abcdef", 2, 2, "CD", 0, 2, StringComparison.CurrentCultureIgnoreCase))); Assert.AreEqual(-1, Math.Sign(Substring.Compare("abcdef", 1, 3, "CD", 0, 2, StringComparison.OrdinalIgnoreCase)), "'b' should be less than 'C' for case-insensitive comparison"); Assert.AreEqual(1, Math.Sign(Substring.Compare("abcdef", 1, 3, "CD", 0, 2, StringComparison.Ordinal)), "'b' should be greater than 'C' for case-sensitive comparison"); Assert.AreEqual(0, Math.Sign(Substring.Compare("Encyclopædia", 8, 2, "aedia", 0, 3, StringComparison.CurrentCulture))); Assert.AreEqual(0, Math.Sign(Substring.Compare("café", 0, 4, "cafe\u0301", 0, 5, StringComparison.CurrentCulture))); Assert.AreEqual(0, Math.Sign(Substring.Compare("café", 0, 4, "cafe\u0301", 0, 5, StringComparison.CurrentCultureIgnoreCase))); Assert.AreEqual(0, Math.Sign(Substring.Compare("café", 0, 4, "cafe\u0301", 0, 5, StringComparison.InvariantCulture))); Assert.AreEqual(0, Math.Sign(Substring.Compare("café", 0, 4, "cafe\u0301", 0, 5, StringComparison.InvariantCultureIgnoreCase))); Assert.AreEqual(1, Math.Sign(Substring.Compare("café", 0, 4, "cafe\u0301", 0, 5, StringComparison.Ordinal))); Assert.AreEqual(1, Math.Sign(Substring.Compare("café", 0, 4, "cafe\u0301", 0, 5, StringComparison.OrdinalIgnoreCase))); Assert.AreEqual(-1, Math.Sign(Substring.Compare("café", 0, 4, "CAFE\u0301", 0, 5, StringComparison.CurrentCulture))); Assert.AreEqual(0, Math.Sign(Substring.Compare("café", 0, 4, "CAFE\u0301", 0, 5, StringComparison.CurrentCultureIgnoreCase))); Assert.AreEqual(-1, Math.Sign(Substring.Compare("café", 0, 4, "CAFE\u0301", 0, 5, StringComparison.InvariantCulture))); Assert.AreEqual(0, Math.Sign(Substring.Compare("café", 0, 4, "CAFE\u0301", 0, 5, StringComparison.InvariantCultureIgnoreCase))); Assert.AreEqual(1, Math.Sign(Substring.Compare("café", 0, 4, "CAFE\u0301", 0, 5, StringComparison.Ordinal))); Assert.AreEqual(1, Math.Sign(Substring.Compare("café", 0, 4, "CAFE\u0301", 0, 5, StringComparison.OrdinalIgnoreCase))); Assert.AreEqual(0, Math.Sign(Substring.Compare("café", 2, 2, "cafe\u0301", 2, 3, StringComparison.CurrentCulture))); Assert.AreEqual(1, Math.Sign(Substring.Compare("café", 0, 4, "cafe\u0301", 0, 4, StringComparison.CurrentCulture))); Assert.AreEqual(1, Math.Sign(Substring.Compare("abc", 1, 2, "", 0, 0, StringComparison.Ordinal))); Assert.AreEqual(-1, Math.Sign(Substring.Compare("", 0, 0, "abc", 0, 2, StringComparison.Ordinal))); Assert.AreEqual(0, Math.Sign(Substring.Compare("abc", 1, 0, "", 0, 0, StringComparison.Ordinal))); Assert.AreEqual(0, Math.Sign(Substring.Compare("abc123", 2, 3, "ABC123", 2, 3, StringComparison.OrdinalIgnoreCase))); } }
public bool Equals(Substring theOther) { return (Length == theOther.Length ? string.Compare(Base, Start, theOther.Base, theOther.Start, Length) == 0 : false); }
public void TestCtor_CountTooBig_Throws() { string value = String.Empty; int offset = 0; int count = 1; Substring substring = new Substring(value, offset, count); }
/** ******************************************************************************************** * Searches a domain. If not found, the domain is (or path of domains are) created in * the domain tree. * If the path string starts with the character defined in #PathSeparator, then * the search (and creation) is done starting from the root domain of this domain and not * from this domain. * * @param domainPathAS Path and domain to search. * @param sensitivity Denotes if domain name search is treated case sensitive or not. * @param maxCreate The maximum number of sub domains that are created if not * found at the end of the path. * @param[out] wasCreated Output parameter that is set \c true if domain was not found * and hence created. * @return The domain found or created. **********************************************************************************************/ public Domain Find(AString domainPathAS, Case sensitivity, int maxCreate, ref bool wasCreated) { Substring domainPath = tSubstring; domainPath.Set(domainPathAS); // set optional output parameter as default to false wasCreated = false; int lenBeforeTrim = domainPath.Length(); // if string is empty (resp. contains only separator characters), return ourselves while (domainPath.Consume(PathSeparator)) { ; } if (domainPath.IsEmpty()) { return(this); } // Trailing domain separator found: call find on root domain Domain startDomain = this; if (lenBeforeTrim > domainPath.Length()) { while (startDomain.Parent != null) { startDomain = startDomain.Parent; } } // call find return(startDomain.findRecursive(domainPath, sensitivity, maxCreate, ref wasCreated)); }
/** **************************************************************************************** * Converts variable value data. Replaces certain characters by escape sequences. * @param os The output stream to write to. * @param value The value to write * @param temp A temporary AString needed internally. * @return The difference of length written and given value length. ******************************************************************************************/ protected int addEscapeSequences(TextWriter os, Substring value, AString temp) { int sizeDiff = 0; temp.Clear(); if (char.IsWhiteSpace(value.CharAtStart()) || char.IsWhiteSpace(value.CharAtEnd())) { temp._('\"')._(value)._('\"'); sizeDiff = 2; } else { temp._(value); } for (int i = 0; i < EscapeSequences.Count;) { String replacement = EscapeSequences[i++]; String needle = EscapeSequences[i++]; sizeDiff += temp.SearchAndReplace(needle, replacement, 0) * (replacement.Length - needle.Length); } os.Write(temp.Buffer(), 0, temp.Length()); return(sizeDiff); }
public void Sort(Substring sub = Substring.ID) { List <long> list = getListPosition(sub); string pathFile = ""; using (StreamReader file = new StreamReader(pathHederFile)) { switch (sub) { case Substring.ID: pathFile = pathPositionFile; list.Sort(new IntIComparer(this, file, 0)); break; case Substring.Name: pathFile = pathSortPositionFile; list.Sort(new StringIComparer(this, file, 1)); // перезаписали файл using (BinaryWriter positionFile = new BinaryWriter(File.OpenWrite(pathFile))) { foreach (long position in list) { positionFile.Write(position); } } break; default: break; } } }
/** **************************************************************************************** * Helper method used when reading file. * @param subs A sub-string. * @return true if provided substring starts with comment character. ******************************************************************************************/ protected bool startsWithCommentSymbol(Substring subs) { int i = commentChars.IndexOf(subs.CharAtStart()); return((i >= 0 && i < 2) || (i == 2 && subs.CharAt(1) == '/')); }
public void AreEqual2() { const string base1 = "abcd"; Substring s1 = null; Substring s2 = null; Substring s3 = null; Substring s4 = Substring.FromIndexToEnd(base1, 3); Substring s5 = s4; Substring s6 = Substring.FromIndexToEnd(base1, 3); Substring s7 = Substring.FromIndexToEnd(base1, 2); Substring s8 = Substring.FromIndexToEnd(base1, 2); Substring s9 = Substring.FromIndexWithLength(base1, 2, 2); Substring s10 = Substring.FromIndexToIndex(base1, 2, 3); Assert.IsTrue(Substring.AreEqual(s1, s2, s3)); Assert.IsFalse(Substring.AreEqual(s1, s2, s3, s4)); Assert.IsTrue(Substring.AreEqual(s4, s5)); Assert.IsTrue(Substring.AreEqual(s4, s5, s6)); Assert.IsFalse(Substring.AreEqual(s6, s7)); Assert.IsTrue(Substring.AreEqual(s4, s4, s4, s4)); Assert.IsTrue(Substring.AreEqual(s7, s8, s9, s10)); Assert.IsFalse(Substring.AreEqual(s6, s7, s8, s9, s10)); Substring[] nulls = null; Assert.Throws<ArgumentNullException>(delegate { Substring.AreEqual(nulls); }); Substring[] empty = new Substring[0]; Assert.Throws<ArgumentException>(delegate { Substring.AreEqual(empty); }); Substring[] one = new Substring[1] { s4 }; Assert.Throws<ArgumentException>(delegate { Substring.AreEqual(one); }); Substring[] two = new Substring[2] { s4, s6 }; Assert.IsTrue(Substring.AreEqual(two)); }
public void ConstructorWithContentAndRangeInitializesProperties() { Substring substring = new Substring("abcde", new Range(2, 3)); Assert.AreEqual("abcde", substring.Content); Assert.AreEqual(new Range(2, 3), substring.Range); Assert.AreEqual(3, substring.Length); }
/// <summary> /// Получает и устанавливает коментарии к посту /// </summary> /// <param name="abstractJObject">Пост на стене</param> private void GetComent(VKAbstractJObject abstractJObject) { if (abstractJObject.comments.count != 0) { string GetCommentURL = string.Concat ( "https://api.vk.com/method/wall.getComments?access_token=", (File.ReadAllLines("UserInf.txt"))[0], "&owner_id=", abstractJObject.owner_id, "&v=5.52&count=1&sort=desc&post_id=", abstractJObject.id ); List <Comment> comments = new List <Comment>(); using (WebClient wc = new WebClient()) { string JsonComment = wc.DownloadString(GetCommentURL); JsonComment = @"{" + Substring.GetSubstringStartIncluded(JsonComment, @"""items", "}}") + @"}"; Thread.Sleep(300); if (abstractJObject.id == 127605) { } comments = Converter <Comment> .JsonToList(JsonComment, "items"); } byte[] price = Encoding.Default.GetBytes(comments[0].ToString()); string coment = Encoding.UTF8.GetString(price); abstractJObject.comment = coment; // Black Magic } }
public void SubstringDoesNotEqualEquivalentString() { const string s = "Hello"; var ss = new Substring(s, 0); ss.Equals(s).Should().BeFalse(); }
public void IndexerThrowsIfIndexTooLow() { Substring substring = new Substring("abcde", new Range(1, 3)); char c; Assert.Throws <IndexOutOfRangeException>(() => c = substring[-1]); }
/// <inheritdoc /> protected override async Task <Result <bool, IError> > Run( IStateMonad stateMonad, CancellationToken cancellationToken) { var superstringResult = await String.Run(stateMonad, cancellationToken) .Map(async x => await x.GetStringAsync()); if (superstringResult.IsFailure) { return(superstringResult.ConvertFailure <bool>()); } var substringResult = await Substring.Run(stateMonad, cancellationToken) .Map(async x => await x.GetStringAsync()); if (substringResult.IsFailure) { return(substringResult.ConvertFailure <bool>()); } var ignoreCaseResult = await IgnoreCase.Run(stateMonad, cancellationToken); if (ignoreCaseResult.IsFailure) { return(ignoreCaseResult.ConvertFailure <bool>()); } var comparison = ignoreCaseResult.Value ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; var r = superstringResult.Value.Contains(substringResult.Value, comparison); return(r); }
internal PathSegment(Substring segment, ChainSegment[] chain) { IsNotEmpty = segment.Length != 0; IsContextChange = IsNotEmpty && segment == ".."; IsThis = IsNotEmpty && !IsContextChange && segment == "."; PathChain = chain; }
public void EndsWith(string input, char c, bool expected) { var substring = new Substring(input, 1, 2); var actual = Substring.EndsWith(substring, c); Assert.Equal(expected, actual); }
public void SubstringContainsWithInvalidFunc() { var s = new Substring("Hello", 0); Action contains = () => s.Contains(null); contains.Should().Throw <ArgumentNullException>(); }
private string GetPrice() { startPrice = Substring.GetSubstringNoIncluded(text, @"Стартовая цена:", "\nМинимальный шаг:"); if (this.comments.count == 0) { return(string.Concat(startPrice, @" / 0")); } string GetCommentURL = string.Concat ( "https://api.vk.com/method/wall.getComments?access_token=", access_token[0], "&owner_id=", owner_id, "&v=5.52&count=1&sort=desc&post_id=", id ); List <Comment> comments = new List <Comment>(); using (WebClient wc = new WebClient()) { string JsonComment = wc.DownloadString(GetCommentURL); JsonComment = @"{" + Substring.GetSubstringStartIncluded(JsonComment, @"""items", "}}") + @"}"; Thread.Sleep(300); comments = Converter <Comment> .JsonToList(JsonComment, "items"); } if (comments == null) { return(string.Empty); } price = comments[0]?.ToString(); price = Encoding.UTF8.GetString(Encoding.Default.GetBytes(price)); // Black Magic price = Substring.GetSubstringNoIncluded(price, "(", " рублей)"); return(string.Concat(startPrice, " / ", price)); }
public void ConstructorWithContentOnlyInitializesProperties() { Substring substring = new Substring("abcde"); Assert.AreEqual("abcde", substring.Content); Assert.AreEqual(new Range(0, 5), substring.Range); Assert.AreEqual(5, substring.Length); }
/// <summary> /// Checks whether log event should be logged or not. /// </summary> /// <param name="logEvent">Log event.</param> /// <returns> /// <see cref="FilterResult.Ignore"/> - if the log event should be ignored<br/> /// <see cref="FilterResult.Neutral"/> - if the filter doesn't want to decide<br/> /// <see cref="FilterResult.Log"/> - if the log event should be logged<br/> /// </returns> protected internal override FilterResult Check(LogEventInfo logEvent) { if (IgnoreCase) { if (CompiledLayout.GetFormattedMessage(logEvent).ToLower().IndexOf(Substring.ToLower()) < 0) { return(Result); } else { return(FilterResult.Neutral); } } else { if (CompiledLayout.GetFormattedMessage(logEvent).IndexOf(Substring) < 0) { return(Result); } else { return(FilterResult.Neutral); } } }
public void TestCtor_NegativeCount_Throws() { string value = String.Empty; int offset = 0; int count = -1; Substring substring = new Substring(value, offset, count); }
/** **************************************************************************************** * Interprets given \p src as a verbosity. * A case insensitive comparison of only the first (!) character of the start of the string * is performed (against 'v', 'i', 'w' and 'e'). * If no match is found, \e %Verbosity::Off is returned. * @param src The string to 'parse'. * @returns The verbosity read. ******************************************************************************************/ public static Verbosity ReadVerbosity(Substring src) { int idx = src.IndexOfAny(CString.DefaultWhitespaces, Inclusion.Exclude); if (idx >= 0) { char c = Char.ToLower(src.CharAt(idx)); if (c == 'v') { return(Verbosity.Verbose); } if (c == 'i') { return(Verbosity.Info); } if (c == 'w') { return(Verbosity.Warning); } if (c == 'e') { return(Verbosity.Error); } } return(Verbosity.Off); }
public void SubstringOfSubstringWithInvalidStartOffset() { var s = new Substring("Hello", 1); Action a = () => new Substring(s, -1, 1); a.Should().Throw <ArgumentOutOfRangeException>(); }
public void SubstringOfSubstringWithInvalidLength() { var s = new Substring("Hello", 1); Action a = () => new Substring(s, 1, -1); a.ShouldThrow <ArgumentOutOfRangeException>(); }
public static PathInfo Parse(string path) { if (path == "null") { return(new PathInfo(PathType.Empty, path, false, 0, null)); } var originalPath = path; var pathSubstring = new Substring(path); var isValidHelperLiteral = true; var pathType = GetPathType(pathSubstring); var isVariable = pathType == PathType.Variable; var isInversion = pathType == PathType.Inversion; var isBlockHelper = pathType == PathType.BlockHelper; if (isVariable || isBlockHelper || isInversion) { isValidHelperLiteral = isBlockHelper || isInversion; pathSubstring = new Substring(pathSubstring, 1); } var contextChangeCount = 0; var segments = new List <PathSegment>(); var pathParts = Substring.Split(pathSubstring, '/'); if (pathParts.Count > 1) { isValidHelperLiteral = false; } for (var index = 0; index < pathParts.Count; index++) { var segment = pathParts[index]; if (segment.Length == 2 && segment[0] == '.' && segment[1] == '.') { contextChangeCount++; isValidHelperLiteral = false; segments.Add(new PathSegment(segment, ArrayEx.Empty <ChainSegment>())); continue; } if (segment.Length == 1 && segment[0] == '.') { isValidHelperLiteral = false; segments.Add(new PathSegment(segment, ArrayEx.Empty <ChainSegment>())); continue; } var chainSegments = GetPathChain(segment).ToArray(); if (chainSegments.Length > 1) { isValidHelperLiteral = false; } segments.Add(new PathSegment(segment, chainSegments)); } return(new PathInfo(pathType, originalPath, isValidHelperLiteral, contextChangeCount, segments)); }
public static PathInfo Parse(string path) { if (path == "null") { return(Empty); } var originalPath = path; var pathType = GetPathType(path); var pathSubstring = new Substring(path); var isValidHelperLiteral = true; var isVariable = pathType == PathType.Variable; var isInversion = pathType == PathType.Inversion; var isBlockHelper = pathType == PathType.BlockHelper; if (isVariable || isBlockHelper || isInversion) { isValidHelperLiteral = isBlockHelper || isInversion; pathSubstring = new Substring(pathSubstring, 1); } var segments = new List <PathSegment>(); var pathParts = Substring.Split(pathSubstring, '/'); var extendedEnumerator = ExtendedEnumerator <Substring> .Create(pathParts); while (extendedEnumerator.MoveNext()) { var segment = extendedEnumerator.Current.Value; if (segment.Length == 2 && segment[0] == '.' && segment[1] == '.') { isValidHelperLiteral = false; segments.Add(new PathSegment(segment, ArrayEx.Empty <ChainSegment>())); continue; } if (segment.Length == 1 && segment[0] == '.') { isValidHelperLiteral = false; segments.Add(new PathSegment(segment, ArrayEx.Empty <ChainSegment>())); continue; } var chainSegments = GetPathChain(segment); if (chainSegments.Length > 1) { isValidHelperLiteral = false; } segments.Add(new PathSegment(segment, chainSegments)); } if (isValidHelperLiteral && segments.Count > 1) { isValidHelperLiteral = false; } return(new PathInfo(pathType, originalPath, isValidHelperLiteral, segments.ToArray())); }
public void FindCommonSuffixLength(string content1, int startIndex1, int length1, string content2, int startIndex2, int length2, int expectedResult) { Substring substring1 = new Substring(content1, new Range(startIndex1, length1)); Substring substring2 = new Substring(content2, new Range(startIndex2, length2)); Assert.AreEqual(expectedResult, substring1.FindCommonSuffixLength(substring2)); }
public void IndexerReturnsIndexedCharWithAppropriateOffsets() { Substring substring = new Substring("abcde", new Range(1, 3)); Assert.AreEqual('b', substring[0]); Assert.AreEqual('c', substring[1]); Assert.AreEqual('d', substring[2]); }
public void TrimEndSubstring(string input, char trimChar, string expected) { var substring = new Substring(input); substring = Substring.TrimEnd(substring, trimChar); Assert.Equal(expected, substring.ToString()); }
public void SimpleSubstring(string input, string expected) { var substring = new Substring(input); substring = new Substring(substring, 1, 2); Assert.Equal(expected, substring.ToString()); }
private void Like_CheckedChanged(object sender, EventArgs e) { DisableValueFields(); Substring.Enabled = true; if (Visible) { Substring.Focus(); } }
public void EmptyString() { var s = new Substring(string.Empty, 0); s.Base.Should().Be(string.Empty); s.Length.Should().Be(0); s.StartingOffset.Should().Be(0); s.EndingOffset.Should().Be(0); s.ToString().Should().BeEmpty(); }
public void StrictSubstring() { var s = new Substring("Hello", 2, 2); s.Base.Should().Be("Hello"); s.Length.Should().Be(2); s.StartingOffset.Should().Be(2); s.EndingOffset.Should().Be(4); s.ToString().Should().Be("ll"); }
public void FullSubstring() { var s = new Substring("Hello", 0); s.Base.Should().Be("Hello"); s.Length.Should().Be("Hello".Length); s.StartingOffset.Should().Be(0); s.EndingOffset.Should().Be(s.Length); s.ToString().Should().Be("Hello"); }
public SelectionCriteria(Operator criteriaType, AttributeMap attribute, int start, int length, object attributeValue, string clause) { m_Type = criteriaType; m_Attribute = attribute; m_Substring = new Substring(start, length); m_Substring.Clause = clause; m_AttributeValue = attributeValue; m_CompareMode = CompareMode.CompareSubstring; }
public void SubstringContainsWithFunc() { var s = new Substring("_Hello ", 2, 2); s.Contains(char.IsWhiteSpace).Should().BeFalse(); s.Contains(char.IsUpper).Should().BeFalse(); s.Contains(char.IsLower).Should().BeTrue(); s.Contains(c => c == 'e').Should().BeTrue(); }
public void SubstringTest() { var fn = new Substring(); var result = fn.Apply(null, new object[] { "Equator", 3, 5 }, null); Assert.IsNotNull(result); Assert.AreEqual("uat", result); }
private static string GetTag(Substring theInput) { var tag = new StringBuilder(); int i = 0; if (theInput[0] == '/') tag.Append(theInput[i++]); while (i < theInput.Length && char.IsLetter(theInput[i])) { tag.Append(theInput[i++]); } return tag.ToString().ToLower(); }
public void EmptySubstrings() { var s = new Substring("Hello", 2, 0); s.Base.Should().Be("Hello"); s.Length.Should().Be(0); s.StartingOffset.Should().Be(2); s.EndingOffset.Should().Be(2); s.ToString().Should().BeEmpty(); var s2 = new Substring("Hello", 5, 0); s2.Base.Should().Be("Hello"); s2.Length.Should().Be(0); s2.StartingOffset.Should().Be(5); s2.EndingOffset.Should().Be(5); s2.ToString().Should().BeEmpty(); }
public void FindTokenPair(string theFirstToken, string theSecondToken, TokenBodyFilter theFilter) { Leader = Substring.Empty; Body = Substring.Empty; if (myPrevious >= myInput.Length) return; int first, second = 0; for (first = myPrevious; first < myInput.Length; first = second + theSecondToken.Length) { first = Find(myInput, theFirstToken, first); second = Find(myInput, theSecondToken, first + theFirstToken.Length + 1); if (second == myInput.Length) { first = second; break; } int body = first + theFirstToken.Length; if (second <= body) continue; Body = new Substring(myInput, body, second - body); if (theFilter(Body)) break; } if (first > myPrevious) { Leader = new Substring(myInput, myPrevious, first - myPrevious); } myPrevious = second + theSecondToken.Length; }
public void SubstringContains() { var s = new Substring("_Hello", 1, 2); s.Contains('_').Should().BeFalse(); s.Contains('H').Should().BeTrue(); s.Contains('e').Should().BeTrue(); s.Contains('l').Should().BeFalse(); s.Contains('o').Should().BeFalse(); s.Contains('m').Should().BeFalse(); }
public void TestCtor_WrapsEntireString() { string value = "test"; var substring = new Substring(value); Assert.AreSame(value, substring.Value, "The string was not set as a backing field."); Assert.AreEqual(value.Length, substring.Count, "The substring had the wrong count."); Assert.AreEqual(0, substring.Offset, "The substring had the wrong offset."); char[] expected = { 't', 'e', 's', 't' }; Assert.IsTrue(expected.ToSublist().IsEqualTo(substring), "The substring did not contain the expected items."); }
public void TestCtor_WithOffset_NullString_Throws() { string value = null; int offset = 0; Substring substring = new Substring(value, offset); }
public void TestCtor_WithOffsetAndCount_CreatesSplice() { string value = "test"; var substring = new Substring(value, 1, 2); Assert.AreSame(value, substring.Value, "The string was not set as a backing field."); Assert.AreEqual(2, substring.Count, "The substring had the wrong count."); Assert.AreEqual(1, substring.Offset, "The substring had the wrong offset."); char[] expected = { 'e', 's' }; Assert.IsTrue(expected.ToSublist().IsEqualTo(substring), "The substring did not contain the expected items."); }
public void SubstringContainsWithInvalidFunc() { var s = new Substring("Hello", 0); Action contains = () => s.Contains(null); contains.ShouldThrow<ArgumentNullException>(); }
private static bool IsValidTag(Substring theBody) { return theBody[0] == '/' || char.IsLetter(theBody[0]); }
public void TestShift_ReadOnly() { IReadOnlySublist<StringAdapter, char> sublist = new Substring("Hello"); sublist.Shift(0, true); }
public void DifferentSubstringsAreNotEqual() { var ss1 = new Substring("Hello", 2, 1); ss1.ToString().Should().Be("l"); var ss2 = new Substring("Hello", 3, 1); ss2.ToString().Should().Be("l"); ss1.Equals(ss2).Should().BeFalse(); ss1.Equals(ss2 as object).Should().BeFalse(); (ss1 == ss2).Should().BeFalse(); (ss1 != ss2).Should().BeTrue(); }
public void EquivalentSubstringsAreEqual() { const string s1 = "Hello"; const string s2 = "Hello"; var ss1 = new Substring(s1, 2); var ss2 = new Substring(s2, 2); ss1.Equals(ss2).Should().BeTrue(); ss1.Equals(ss2 as object).Should().BeTrue(); (ss1 == ss2).Should().BeTrue(); (ss1 != ss2).Should().BeFalse(); }
private static bool NullTokenBodyFilter(Substring theTokenBody) { return true; }
public void GetHashCodeIsDifferentForDifferentSubstrings() { var ss1 = new Substring("Hello", 2, 1); ss1.ToString().Should().Be("l"); var ss2 = new Substring("Hello", 3, 1); ss2.ToString().Should().Be("l"); ss1.GetHashCode().Should().NotBe(ss2.GetHashCode()); }
public void GetHashCodeIsSameForEquivalentSubstrings() { const string s1 = "Hello"; const string s2 = "Hello"; var ss1 = new Substring(s1, 2); var ss2 = new Substring(s2, 2); ss1.GetHashCode().Should().Be(ss2.GetHashCode()); }
public void Append(Substring theInput) { for (int i = 0; i < theInput.Length; i++) { char input = theInput[i]; if (isStandard && input != '\u00a0' && char.IsWhiteSpace(input)) { if (!myWhitespace) { myText.Append(' '); myLastTag = myLastTag + " "; } myWhitespace = true; } else { switch (input) { case '\u201c': input = '"'; break; case '\u201d': input = '"'; break; case '\u2018': input = '\''; break; case '\u2019': input = '\''; break; case '\u00a0': input = ' '; break; case '&': if (theInput.Contains(i + 1, "nbsp;")) { input = ' '; i += 5; } break; } myText.Append(input); myWhitespace = false; myLastTag = string.Empty; } } }
public void TestResize_ReadOnly() { IReadOnlySublist<StringAdapter, char> sublist = new Substring("Hello"); sublist.Resize(sublist.Count, true); }
public void SubstringOfSubstringWithInvalidStartOffset() { var s = new Substring("Hello", 1); Action a = () => new Substring(s, -1, 1); a.ShouldThrow<ArgumentOutOfRangeException>(); }
public void SubstringIndexOf() { var s = new Substring("_Hello", 1, 2); s.IndexOf('_').Should().BeNegative(); s.IndexOf('H').Should().Be(1); s.IndexOf('e').Should().Be(2); s.IndexOf('l').Should().BeNegative(); s.IndexOf('o').Should().BeNegative(); s.IndexOf('m').Should().BeNegative(); }
public void TestCtor_NegativeOffset_Throws() { string value = "testing"; int offset = -1; Substring sublist = new Substring(value, offset); }