internal DocumentLocation FindCharacterStrictlyAfter(char c, DocumentLocation afterLocation) { List <DocumentLocation> locationList = this.GetLocationList(c); UnitTestUtility.Assert(locationList != null, "We should always find character for special characters only"); // Note that this 'nextLocation' may not represent a real document location (we could hit an end line character here so that there is no next line // position. This is merely used for the search algorithm below: DocumentLocation nextLocation = new DocumentLocation(afterLocation.LineNumber, new OneBasedCounter(afterLocation.LinePosition.Value + 1)); BinarySearchResult result = locationList.MyBinarySearch(nextLocation); if (result.IsFound) { // It is possible that the next location is a quote itself, or return(nextLocation); } else if (result.IsNextIndexAvailable) { // Some other later position is the quote, or return(locationList[result.NextIndex]); } else { // in the worst case no quote can be found. return(null); } }
internal DocumentLocation FindCharacterStrictlyBefore(char c, DocumentLocation documentLocation) { List <DocumentLocation> locationList = this.GetLocationList(c); UnitTestUtility.Assert(locationList != null, "We should always find character for special characters only"); BinarySearchResult result = locationList.MyBinarySearch(documentLocation); if (result.IsFound) { if (result.FoundIndex > 0) { return(locationList[result.FoundIndex - 1]); } else { return(null); } } else if (result.IsNextIndexAvailable) { if (result.NextIndex > 0) { return(locationList[result.NextIndex - 1]); } else { return(null); } } else if (locationList.Count > 0) { return(locationList[locationList.Count - 1]); } else { return(null); } }