当前位置: 首页>>代码示例>>C#>>正文


C# RubyRegex类代码示例

本文整理汇总了C#中RubyRegex的典型用法代码示例。如果您正苦于以下问题:C# RubyRegex类的具体用法?C# RubyRegex怎么用?C# RubyRegex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RubyRegex类属于命名空间,在下文中一共展示了RubyRegex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddDomainType

        public static object AddDomainType(RubyContext/*!*/ context, BlockParam/*!*/ block, RubyModule/*!*/ self, 
            MutableString/*!*/ domainAndDate, RubyRegex/*!*/ typeRegex)
        {
            if (block == null) {
                throw RubyExceptions.NoBlockGiven();
            }

            MutableString tag = MutableString.CreateMutable(typeRegex.Encoding).
                Append("tag:").
                Append(domainAndDate).
                Append(':').
                Append(typeRegex.Pattern);

            RubyConstructor.AddExternalMultiConstructor(tag.ConvertToString(), block);
            return null;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:16,代码来源:RubyYaml.cs

示例2: ImplicitMatch

 public static object ImplicitMatch(ConversionStorage<MutableString>/*!*/ stringCast, RubyScope/*!*/ scope, RubyRegex/*!*/ self) {
     return MatchIndex(scope, self, Protocols.CastToString(stringCast, scope.GetInnerMostClosureScope().LastInputLine));
 }
开发者ID:bclubb,项目名称:ironruby,代码行数:3,代码来源:RubyRegexOps.cs

示例3: MatchToScanResult

 private static object MatchToScanResult(RubyScope/*!*/ scope, MutableString/*!*/ self, RubyRegex/*!*/ regex, Match/*!*/ match) {
     if (match.Groups.Count == 1) {
         return MutableString.Create(match.Value).TaintBy(self).TaintBy(regex, scope);
     } else {
         var result = new RubyArray(match.Groups.Count - 1);
         for (int i = 1; i < match.Groups.Count; i++) {
             if (match.Groups[i].Success) {
                 result.Add(MutableString.Create(match.Groups[i].Value).TaintBy(self).TaintBy(regex, scope));
             } else {
                 result.Add(null);
             }
         }
         return result;
     }
 }
开发者ID:mscottford,项目名称:ironruby,代码行数:15,代码来源:MutableStringOps.cs

示例4: BlockReplaceInPlace

        private static object BlockReplaceInPlace(RubyScope/*!*/ scope, BlockParam/*!*/ block, MutableString/*!*/ self, 
            RubyRegex/*!*/ pattern, bool replaceAll) {

            object blockResult;

            uint version = self.Version;

            // prepare replacement in a builder:
            MutableString builder;
            if (replaceAll ?
                BlockReplaceAll(scope, self, block, pattern, out blockResult, out builder) :
                BlockReplaceFirst(scope, self, block, pattern, out blockResult, out builder)) {

                // block jumped:
                return blockResult;
            }

            // unsuccessful match:
            if (builder == null) {
                return null;
            }

            RequireNoVersionChange(version, self);

            if (self.IsFrozen) {
                throw new RuntimeError("string frozen");
            }

            // replace content of self with content of the builder:
            self.Replace(0, self.Length, builder);
            return self.TaintBy(builder);
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:32,代码来源:MutableStringOps.cs

示例5: BlockReplaceFirst

        public static object BlockReplaceFirst(RubyScope/*!*/ scope, [NotNull]BlockParam/*!*/ block, MutableString/*!*/ self, 
            [NotNull]MutableString matchString) {

            object blockResult;
            MutableString result;
            var regex = new RubyRegex(Regex.Escape(matchString.ToString()), RubyRegexOptions.NONE);

            return BlockReplaceFirst(scope, self, block, regex, out blockResult, out result) ? blockResult : (result ?? self.Clone());
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:9,代码来源:MutableStringOps.cs

示例6: ReplaceFirst

        private static MutableString ReplaceFirst(RubyScope/*!*/ scope, MutableString/*!*/ input, MutableString/*!*/ replacement, RubyRegex/*!*/ pattern) {
            MatchData match = RegexpOps.Match(scope, pattern, input);
            if (match == null || !match.Success) {
                return null;
            }

            MutableString result = input.CreateInstance().TaintBy(input).TaintBy(replacement);
            
            // prematch:
            result.Append(input, 0, match.Index);

            AppendReplacementExpression(input, match, result, replacement);

            // postmatch:
            int offset = match.Index + match.Length;
            result.Append(input, offset, input.Length - offset);

            return result;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:19,代码来源:MutableStringOps.cs

示例7: MutableString_IndexRegex1

        public void MutableString_IndexRegex1() {
            var SJIS = RubyEncoding.GetRubyEncoding(RubyEncoding.CodePageSJIS);
            var sjis = new byte[] { 0x82, 0xA0 };
            var u12345 = new byte[] { 0xF0, 0x92, 0x8D, 0x85 }; // \u{12345} in UTF-8
            var invalid = MutableString.CreateBinary(new byte[] { 0x80 }, RubyEncoding.UTF8);
            int i;
            MutableString a;
            RubyRegex r;
            RubyScope scope = new RubyTopLevelScope(Context);

            // incompatible encodings:
            a = MutableString.CreateBinary(sjis, SJIS);
            r = new RubyRegex(MutableString.CreateBinary(u12345, RubyEncoding.UTF8));
            AssertExceptionThrown<EncodingCompatibilityError>(() => MutableStringOps.Index(scope, a, r, 0));

            // invalid character:
            AssertExceptionThrown<ArgumentException>(() => MutableStringOps.Index(scope, invalid, r, 0));

            // returns character index:
            i = (int)MutableStringOps.Index(
                scope,
                MutableString.CreateMutable("aαb", RubyEncoding.UTF8),
                new RubyRegex(MutableString.CreateMutable("b", SJIS)),
                0
            );
            Assert(i == 2);

            // "start at" counts chars in 1.9, returns character index
            i = (int)MutableStringOps.Index(
                scope,
                MutableString.CreateMutable("αabbba", RubyEncoding.UTF8),
                new RubyRegex(MutableString.CreateAscii("a")),
                2
            );
            Assert(i == 5);

            // "start at" counts bytes in 1.8, returns byte index (regardless of KCODE)
            i = (int)MutableStringOps.Index(
                scope,
                MutableString.CreateBinary(Encoding.UTF8.GetBytes("αa"), RubyEncoding.Binary),
                new RubyRegex(MutableString.CreateAscii("a"), RubyRegexOptions.UTF8),
                2
            );
            Assert(i == 2);

            // returns byte index for k-coded strings:
            i = (int)MutableStringOps.Index(
                scope,
                MutableString.CreateMutable("αaβb", RubyEncoding.KCodeUTF8),
                new RubyRegex(MutableString.CreateMutable("a", RubyEncoding.KCodeSJIS)),
                0
            );
            Assert(i == 2);

            // returns byte index for k-coded strings:
            i = (int)MutableStringOps.Index(
                scope,
                MutableString.CreateMutable("αabbba", RubyEncoding.KCodeUTF8),
                new RubyRegex(MutableString.CreateAscii("a")),
                2
            );
            Assert(i == 2);

            // uses the current KCODE for match:
            a = MutableString.CreateBinary(new byte[] { 0x82, 0xa1, 0x82, 0xa0, 0x82, 0xa0 }, RubyEncoding.Binary);
            r = new RubyRegex(MutableString.CreateBinary(new byte[] { 0x82, 0xa0, (byte)'{', (byte)'2', (byte)'}' }, RubyEncoding.Binary));

            Context.KCode = RubyEncoding.KCodeSJIS;
            Assert((int)MutableStringOps.Index(scope, a, r, 0) == 2);

            Context.KCode = null;
            Assert(MutableStringOps.Index(scope, a, r, 0) == null);

            // invalid characters:
            a = MutableString.CreateBinary(new byte[] { 0x82, 0x82, 0xa0, 0xa0, 0x82 }, RubyEncoding.Binary); // invalid
            r = new RubyRegex(MutableString.CreateBinary(new byte[] { 0x82, 0xa0, (byte)'{', (byte)'2', (byte)'}' }, RubyEncoding.Binary)); // valid

            Context.KCode = RubyEncoding.KCodeSJIS;
            Assert(MutableStringOps.Index(scope, a, r, 0) == null);

            Context.KCode = null;
            Assert((int)MutableStringOps.Index(scope, a, r, 0) == 1);
        }
开发者ID:yarrow2,项目名称:ironruby,代码行数:83,代码来源:MutableStringTests.cs

示例8: WriteRegex

 private void WriteRegex(RubyRegex/*!*/ value) {
     WriteSubclassData(value, typeof(RubyRegex));
     _writer.Write((byte)'/');
     WriteStringValue(value.Pattern);
     _writer.Write((byte)value.Options);
 }
开发者ID:rafacv,项目名称:iron_languages,代码行数:6,代码来源:Marshal.cs

示例9: WriteRegex

 private void WriteRegex(RubyRegex/*!*/ value) {
     SubclassData instanceWriter = new SubclassData(this, value, typeof(RubyRegex));
     _writer.Write((byte)'/');
     WriteStringValue(value.GetPattern());
     _writer.Write((byte)value.Options);
 }
开发者ID:mscottford,项目名称:ironruby,代码行数:6,代码来源:Marshal.cs

示例10: Reinitialize

        public static RubyRegex/*!*/ Reinitialize(RubyRegex/*!*/ self, 
            [DefaultProtocol, NotNull]MutableString/*!*/ pattern, int options, [DefaultProtocol, Optional]MutableString encoding) {

            self.Set(pattern, MakeOptions(options, encoding));
            return self;
        }
开发者ID:bclubb,项目名称:ironruby,代码行数:6,代码来源:RubyRegexOps.cs

示例11: Source

 public static MutableString/*!*/ Source(RubyRegex/*!*/ self) {
     return self.GetPattern();
 }
开发者ID:bclubb,项目名称:ironruby,代码行数:3,代码来源:RubyRegexOps.cs

示例12: BlockReplaceAll

        public static object BlockReplaceAll(ConversionStorage<MutableString>/*!*/ tosConversion, 
            RubyScope/*!*/ scope, [NotNull]BlockParam/*!*/ block, MutableString/*!*/ self, 
            [NotNull]MutableString matchString) {

            object blockResult;
            MutableString result;
            // TODO:
            var regex = new RubyRegex(MutableString.CreateMutable(Regex.Escape(matchString.ToString()), matchString.Encoding), RubyRegexOptions.NONE);

            self.TrackChanges();
            object r = BlockReplaceAll(tosConversion, scope, self, block, regex, out blockResult, out result) ? blockResult : (result ?? self.Clone());
            RequireNoVersionChange(self);
            return r;
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:14,代码来源:MutableStringOps.cs

示例13: MatchToScanResult

 private static object MatchToScanResult(RubyScope/*!*/ scope, MutableString/*!*/ self, RubyRegex/*!*/ regex, MatchData/*!*/ match) {
     if (match.GroupCount == 1) {
         return match.GetValue().TaintBy(regex, scope);
     } else {
         var result = new RubyArray(match.GroupCount - 1);
         for (int i = 1; i < match.GroupCount; i++) {
             MutableString value = match.GetGroupValue(i);
             result.Add(value != null ? value.TaintBy(regex, scope) : value);
         }
         return result;
     }
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:12,代码来源:MutableStringOps.cs

示例14: RegexEncoding1

        public void RegexEncoding1() {
            MatchData m;
            // the k-coding of the pattern string is irrelevant:
            foreach (var pe in new[] { RubyEncoding.KCodeSJIS, RubyEncoding.KCodeUTF8, RubyEncoding.Binary }) {
                var p = MutableString.CreateBinary(new byte[] { 0x82, 0xa0, (byte)'{', (byte)'2', (byte)'}' }, pe);

                var r = new RubyRegex(p, RubyRegexOptions.NONE);
                var rs = new RubyRegex(p, RubyRegexOptions.SJIS);

                // the k-coding of the string is irrelevant:
                foreach (var se in new[] { RubyEncoding.KCodeSJIS, RubyEncoding.KCodeUTF8, RubyEncoding.Binary }) {
                    var s = MutableString.CreateBinary(new byte[] { 0x82, 0xa0,  0xa0 }, se);
                    var t = MutableString.CreateBinary(new byte[] { 0x82, 0xa0,  0xa0,  0x82, 0xa0,  0xa0, 0xff }, se);
                    var u = MutableString.CreateBinary(new byte[] { 0x82, 0xa0,  0x82, 0xa0,  0x82, 0xa0 }, se);

                    // /あ{2}/ does not match "あ\xa0"
                    m = r.Match(RubyEncoding.KCodeSJIS, s);
                    Assert(m == null);

                    // /\x82\xa0{2}/ matches "[ \x82\xa0\xa0 ] \x82\xa0\xa0\xff"
                    m = r.Match(null, s);
                    Assert(m != null && m.Index == 0);

                    // /\x82\xa0{2}/ matches "\x82\xa0\xa0 [ \x82\xa0\xa0 ] \xff" starting from byte #1:
                    m = r.Match(null, t, 1, false);
                    Assert(m != null && m.Index == 3 && m.Length == 3);

                    // /あ{2}/s does not match "あ\xa0", current KCODE is ignored
                    m = rs.Match(null, s);
                    Assert(m == null);

                    // /あ{2}/s does not match "あ\xa0", current KCODE is ignored
                    m = rs.Match(RubyEncoding.KCodeUTF8, s);
                    Assert(m == null);

                    // /あ{2}/s matches "ああ\xff", current KCODE is ignored
                    m = rs.Match(RubyEncoding.KCodeUTF8, u, 2, false);
                    Assert(m != null && m.Index == 2 && m.Length == 4);


                    // /あ{2}/ does not match "あ\xa0あ\xa0"
                    m = r.LastMatch(RubyEncoding.KCodeSJIS, t);
                    Assert(m == null);

                    // /\x82\xa0{2}/ matches "\x82\xa0\xa0 [ \x82\xa0\xa0 ] \xff"
                    m = r.LastMatch(null, t);
                    Assert(m != null && m.Index == 3);

                    // /あ{2}/s does not match "あ\xa0あ\xa0", current KCODE is ignored
                    m = rs.LastMatch(null, t);
                    Assert(m == null);

                    // /あ{2}/s does not match "あ\xa0あ\xa0", current KCODE is ignored
                    m = rs.LastMatch(RubyEncoding.KCodeUTF8, t);
                    Assert(m == null);
                }
            }
        }
开发者ID:BrianGenisio,项目名称:ironruby,代码行数:58,代码来源:RegexTests.cs

示例15: Match

 private bool Match(RubyRegex/*!*/ pattern, bool currentPositionOnly, bool advancePosition)
 {
     // TODO: repeated calls on the same ScanString can be optimized:
     MatchData match = pattern.Match(_scanString, _currentPosition, false);
     _lastMatch = null;
     _lastMatchingGroups = null;
     _foundPosition = 0;
     if (match == null) {
         return false;
     }
     if (currentPositionOnly && match.Index != _currentPosition) {
         return false;
     }
     int length = (match.Index - _currentPosition) + match.Length;
     _foundPosition = match.Index;
     _previousPosition = _currentPosition;
     _lastMatch = _scanString.GetSlice(_foundPosition, match.Length);
     _lastMatchingGroups = match;
     if (advancePosition) {
         _currentPosition += length;
     }
     return true;
 }
开发者ID:TerabyteX,项目名称:main,代码行数:23,代码来源:StringScanner.cs


注:本文中的RubyRegex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。