public string Capture(int nth) { if (disposed) { throw new ObjectDisposedException("ORegex"); } if (!Valid) { throw new ArgumentException(string.Format("Invalid Onigmo regular expression: {0}", regexString)); } if (!regionSet) { throw new InvalidOperationException("ORegex.Capture requires that ORegex.Search be run first."); } var pos = OnigInterop.onigwrap_pos(region, nth); if (pos < 0) { return(null); } var len = OnigInterop.onigwrap_len(region, nth); return(text.Substring(pos, len)); }
public int MatchLength(int nth) { if (disposed) { throw new ObjectDisposedException("ORegex"); } if (!Valid) { throw new ArgumentException(string.Format("Invalid Onigmo regular expression: {0}", regexString)); } if (!regionSet) { throw new InvalidOperationException("ORegex.MatchLength requires that ORegex.Search be run first."); } return(OnigInterop.onigwrap_len(region, nth)); }
/// <summary> /// Performs a thread safe search and returns the results in a list /// </summary> /// <param name="text">The text to search</param> /// <param name="offset">An offset from which to start</param> /// <returns></returns> public List <ORegexResult> SafeSearch(string text, int offset = 0) { if (disposed) { throw new ObjectDisposedException("ORegex"); } if (!Valid) { throw new ArgumentException(string.Format("Invalid Onigmo regular expression: {0}", regexString)); } var resultList = new List <ORegexResult>(); lock (syncObject) { Search(text, offset); var captureCount = OnigInterop.onigwrap_num_regs(region); for (var capture = 0; capture < captureCount; capture++) { var pos = OnigInterop.onigwrap_pos(region, capture); if (capture == 0 && pos == -1) { break; } resultList.Add(new ORegexResult() { Position = pos, Length = pos == -1 ? 0 : OnigInterop.onigwrap_len(region, capture) }); } this.text = null; OnigInterop.onigwrap_region_free(region); regionSet = false; } return(resultList); }