public PatternOffset(OffsetType type, Whence whence, int offset) { if (OffsetType.MatchStart == type && Whence.Start == whence && offset < 0) { string msg = StringExtensions.Fi("Iris currently does not support negative a negative match start offset starting from the actual match start"); throw new AssertionViolationException(msg); } this.OffSetType = type; this.Whence = whence; this.Offset = offset; }
private static void AddOffset(Pattern p, string offsetstring) { Match m = m_offsetRegex.Match(offsetstring); if (!m.Success) { throw new ArgumentException(StringExtensions.Fi("Invalid offset string '{0}'", offsetstring)); } string what = m.Groups["what"].Value; string whenceChar = m.Groups["whence"].Value; int displacement; if (m.Groups["displacement"].Success) { displacement = int.Parse(m.Groups["displacement"].Value, CultureInfo.InvariantCulture); } else { displacement = 0; } if ("lc" == what) { if (0 == displacement) { throw new ArgumentException(StringExtensions.Fi("Invalid offset: '{0}' applies to leading context, but does not specify a number", offsetstring)); } p.LeadingContext = displacement; return; } Whence whence = (whenceChar == "s") ? Whence.Start : Whence.End; OffsetType type; switch (what) { case "ms": type = OffsetType.MatchStart; break; case "me": type = OffsetType.MatchEnd; break; case "hs": type = OffsetType.HighlightStart; break; case "he": type = OffsetType.HighlightEnd; break; case "rs": type = OffsetType.RegionStart; break; case "re": type = OffsetType.RegionEnd; break; default: throw new AssertionViolationException(StringExtensions.Fi("Unknown offset type: '{0}'", what)); } p.Offsets.Add(new PatternOffset(type, whence, displacement)); }