public AsciiCompiledTextSearchNative( NativeMethods.SearchAlgorithmKind kind, string pattern, NativeMethods.SearchOptions searchOptions) { _patternHandle = new SafeHGlobalHandle(Marshal.StringToHGlobalAnsi(pattern)); var patternLength = pattern.Length; _handle = CreateSearchHandle(kind, _patternHandle, patternLength, searchOptions); _searchBufferSize = NativeMethods.AsciiSearchAlgorithm_GetSearchBufferSize(_handle); }
private static unsafe SafeSearchHandle CreateSearchHandle( NativeMethods.SearchAlgorithmKind kind, SafeHGlobalHandle patternHandle, int patternLength, NativeMethods.SearchOptions searchOptions) { NativeMethods.SearchCreateResult createResult; var result = NativeMethods.AsciiSearchAlgorithm_Create( kind, patternHandle.Pointer, patternLength, searchOptions, out createResult); if (createResult.HResult < 0) { // The error is recoverable, since we are dealing with an invalid pattern // or something along the lines. var message = Marshal.PtrToStringAnsi(new IntPtr(createResult.ErrorMessage)); throw new RecoverableErrorException(message); } return result; }
public Utf16CompiledTextSearchStdSearch(string pattern, NativeMethods.SearchOptions searchOptions) { _patternPtr = new SafeHGlobalHandle(Marshal.StringToHGlobalUni(pattern)); _patternLength = pattern.Length; _searchOptions = searchOptions; }
public AsciiStringSearchNative(NativeMethods.SearchAlgorithmKind kind, string pattern, NativeMethods.SearchOptions searchOptions) { _patternHandle = new SafeHGlobalHandle(Marshal.StringToHGlobalAnsi(pattern)); _handle = NativeMethods.AsciiSearchAlgorithm_Create(kind, _patternHandle.Pointer, pattern.Length, searchOptions); _patternLength = pattern.Length; }
public StrStrWStringSearchAlgorithm(string pattern, NativeMethods.SearchOptions searchOptions) { _searchTextUniPtr = new SafeHGlobalHandle(Marshal.StringToHGlobalUni(pattern)); _searchOptions = searchOptions; _patternLength = pattern.Length; }
public static MemoryBlock CreateAsciiMemory(string text) { var size = text.Length + 1; var handle = new SafeHGlobalHandle(Marshal.StringToHGlobalAnsi(text)); return new MemoryBlock(handle, size); }
public static FileContentsMemory CreateUtf16Memory(string text) { var size = (text.Length + 1) * sizeof(char); var handle = new SafeHGlobalHandle(Marshal.StringToHGlobalUni(text)); return new FileContentsMemory(handle, size, 0, size - 1); }
public static FileContentsMemory CreateAsciiMemory(string text) { var size = text.Length + 1; var handle = new SafeHGlobalHandle(Marshal.StringToHGlobalAnsi(text)); return new FileContentsMemory(handle, size, 0, size - 1); }