コード例 #1
0
ファイル: RegexKeyTests.cs プロジェクト: vector-man/pcre-net
        public void should_freeze_settings()
        {
            var settings = new PcreRegexSettings();

            Assert.That(settings.ReadOnlySettings, Is.False);

            var key = new RegexKey("test", settings);

            Assert.That(key.Settings.ReadOnlySettings, Is.True);
            Assert.That(settings.ReadOnlySettings, Is.False);
        }
コード例 #2
0
ファイル: RegexKeyTests.cs プロジェクト: vector-man/pcre-net
        public void should_not_compare_equal()
        {
            var defaults = new PcreRegexSettings();
            var other    = new PcreRegexSettings
            {
                ParensLimit = 42
            };

            var keyA = new RegexKey("test", defaults);
            var keyB = new RegexKey("test", other);

            Assert.That(keyA, Is.Not.EqualTo(keyB));
        }
コード例 #3
0
        public InternalRegex(string pattern, PcreRegexSettings settings)
        {
            Pattern  = pattern;
            Settings = settings.AsReadOnly();

            Native.compile_result result;

            fixed(char *pPattern = pattern)
            {
                var input = new Native.compile_input
                {
                    pattern        = pPattern,
                    pattern_length = (uint)pattern.Length
                };

                Settings.FillCompileInput(ref input);

                Native.compile(ref input, out result);
                _code = result.code;

                if (_code == IntPtr.Zero || result.error_code != 0)
                {
                    throw new ArgumentException($"Invalid pattern '{pattern}': {Native.GetErrorMessage(result.error_code)} at offset {result.error_offset}");
                }
            }

            CaptureCount = (int)result.capture_count;
            CaptureNames = new Dictionary <string, int[]>((int)result.name_count, StringComparer.Ordinal);

            var currentItem = result.name_entry_table;

            for (var i = 0; i < result.name_count; ++i)
            {
                var groupIndex = (int)*currentItem;
                var groupName  = new string(currentItem + 1);

                if (CaptureNames.TryGetValue(groupName, out var indexes))
                {
                    Array.Resize(ref indexes, indexes.Length + 1);
                    indexes[indexes.Length - 1] = groupIndex;
                }
                else
                {
                    indexes = new[] { groupIndex };
                }

                CaptureNames[groupName] = indexes;

                currentItem += result.name_entry_size;
            }
        }
コード例 #4
0
ファイル: RegexKeyTests.cs プロジェクト: vector-man/pcre-net
        public void should_compare_equal()
        {
            var implicitDefaults = new PcreRegexSettings();
            var explicitDefaults = new PcreRegexSettings
            {
                NewLine     = PcreBuildInfo.NewLine,
                BackslashR  = PcreBuildInfo.BackslashR,
                ParensLimit = PcreBuildInfo.ParensLimit
            };

            var keyA = new RegexKey("test", implicitDefaults);
            var keyB = new RegexKey("test", explicitDefaults);

            Assert.That(keyA, Is.EqualTo(keyB));
        }
コード例 #5
0
ファイル: RegexKey.cs プロジェクト: yusufozturk/pcre-net
 public RegexKey(string pattern, PcreRegexSettings settings)
 {
     Pattern  = pattern;
     Settings = settings.AsReadOnly();
 }