static string GetLine(IVsTextLines lines, int lineNr) { if (lineNr < 0) { throw new ArgumentOutOfRangeException("lineNr"); } else if (lines == null) { return(null); } int lastLine, lastIndex; if (!VSErr.Succeeded(lines.GetLastLineIndex(out lastLine, out lastIndex))) { return(null); } if (lineNr > lastLine) { return(null); } LINEDATA[] data = new LINEDATA[1]; if (!VSErr.Succeeded(lines.GetLineData(lineNr, data, null))) { return(null); } return(Marshal.PtrToStringUni(data[0].pszText, data[0].iLength)); }
private String GetLineContent(IVsTextLines lines, int lineNumber) { String str = ""; var data = new LINEDATA[1]; var markerData = new MARKERDATA[1]; if (VSConstants.S_OK == lines.GetLineData(lineNumber, data, markerData)) { str = Marshal.PtrToStringUni(data[0].pszText, data[0].iLength); // Clean up memory...needed? lines.ReleaseLineData(data); lines.ReleaseMarkerData(markerData); } return(str); }
/// <summary> /// Enumerate over the lines [startIndex, endIndex) for the IVsTextLines buffer. /// </summary> /// <param name="buffer"> The buffer to enumerate. </param> /// <param name="startIndex"> The starting index, inclusive. </param> /// <param name="endIndex"> The end index, exclusive. </param> /// <returns> /// Returns an enumrator that will enumerate over the lines [startIndex, endIndex) of the buffer. /// </returns> private static IEnumerable <Tuple <int, string> > GetTextLinesEnumeratorInternal(IVsTextLines buffer, int startIndex, int endIndex) { LINEDATA[] lineData = new LINEDATA[1]; for (int i = startIndex; i < endIndex; ++i) { int hr = buffer.GetLineData(i, lineData, null); // Skip the line if there is an error. if (ErrorHandler.Failed(hr)) { continue; } string line; try { // We set an arbitrary limit on the line length that we're willing to handle. This is to avoid // loading an unreasonably long string into memory. The buffer is compressed under the covers, so it // can handle much longer strings. // If we choose to handle the case where the string is longer, we would complicate the code significantly. // Since this is an unlikely scenario to have the script tag on a line this long, we will optimize // for the standard case and error; if (lineData[0].iLength >= MaxLineLengthToConsider) { continue; } line = Marshal.PtrToStringUni(lineData[0].pszText); } finally { buffer.ReleaseLineData(lineData); } yield return(new Tuple <int, string>(i, line)); } }
static string GetLine(IVsTextLines lines, int lineNr) { if (lineNr < 0) throw new ArgumentOutOfRangeException("lineNr"); else if (lines == null) return null; int lastLine, lastIndex; if (!ErrorHandler.Succeeded(lines.GetLastLineIndex(out lastLine, out lastIndex))) return null; if (lineNr > lastLine) return null; LINEDATA[] data = new LINEDATA[1]; if (!ErrorHandler.Succeeded(lines.GetLineData(lineNr, data, null))) return null; return Marshal.PtrToStringUni(data[0].pszText, data[0].iLength); }
public int GetLineData(int iLine, LINEDATA[] pLineData, MARKERDATA[] pMarkerData) { return(_textBuffer.GetLineData(iLine, pLineData, pMarkerData)); }
private String GetLineContent(IVsTextLines lines, int lineNumber) { String str = ""; var data = new LINEDATA[1]; var markerData = new MARKERDATA[1]; if (VSConstants.S_OK == lines.GetLineData(lineNumber, data, markerData)) { str = Marshal.PtrToStringUni(data[0].pszText, data[0].iLength); // Clean up memory...needed? lines.ReleaseLineData(data); lines.ReleaseMarkerData(markerData); } return str; }