本文整理汇总了C#中RubyRegex类的典型用法代码示例。如果您正苦于以下问题:C# RubyRegex类的具体用法?C# RubyRegex怎么用?C# RubyRegex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RubyRegex类属于命名空间,在下文中一共展示了RubyRegex类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: RegexEncoding2
public void RegexEncoding2() {
var SJIS = RubyEncoding.KCodeSJIS.StrictEncoding;
// 1.9 encodings:
var invalidUtf8 = MutableString.CreateBinary(new byte[] { 0x80 }, RubyEncoding.UTF8);
AssertExceptionThrown<ArgumentException>(() => new RubyRegex(invalidUtf8, RubyRegexOptions.NONE));
// LastMatch
MatchData m;
var u = MutableString.CreateBinary(SJIS.GetBytes("あああ"), RubyEncoding.KCodeSJIS);
var p = MutableString.CreateBinary(SJIS.GetBytes("あ{2}"), RubyEncoding.KCodeSJIS);
var rs = new RubyRegex(p, RubyRegexOptions.SJIS);
// /あ{2}/ matches "あああ", the resulting index is in bytes:
m = rs.LastMatch(null, u);
Assert(m != null && m.Index == 2);
rs = new RubyRegex(MutableString.CreateBinary(SJIS.GetBytes("あ")), RubyRegexOptions.SJIS);
// "start at" in the middle of a character:
m = rs.LastMatch(null, u, 0);
Assert(m != null && m.Index == 0);
m = rs.LastMatch(null, u, 1);
Assert(m != null && m.Index == 0);
m = rs.LastMatch(null, u, 2);
Assert(m != null && m.Index == 2);
m = rs.LastMatch(null, u, 3);
Assert(m != null && m.Index == 2);
// Split
u = MutableString.CreateBinary(SJIS.GetBytes("あちあちあ"), RubyEncoding.UTF8);
rs = new RubyRegex(MutableString.CreateBinary(SJIS.GetBytes("ち")), RubyRegexOptions.SJIS);
var parts = rs.Split(null, u);
Assert(parts.Length == 3);
foreach (var part in parts) {
Assert(part.Encoding == RubyEncoding.KCodeSJIS);
Assert(part.ToString() == "あ");
}
// groups
rs = new RubyRegex(MutableString.CreateBinary(SJIS.GetBytes("ち(a(あ+)(b+))+あ")), RubyRegexOptions.SJIS);
u = MutableString.CreateBinary(SJIS.GetBytes("ちaああbaあbbbあ"));
m = rs.Match(null, u);
Assert(m.GroupCount == 4);
int s, l;
Assert(m.GetGroupStart(0) == (s = 0));
Assert(m.GetGroupLength(0) == (l = u.GetByteCount()));
Assert(m.GetGroupEnd(0) == s + l);
// the group has 2 captures, the last one is its value:
Assert(m.GetGroupStart(1) == (s = SJIS.GetByteCount("ちaああb")));
Assert(m.GetGroupLength(1) == (l = SJIS.GetByteCount("aあbbb")));
Assert(m.GetGroupEnd(1) == s + l);
// the group has 2 captures, the last one is its value:
Assert(m.GetGroupStart(2) == (s = SJIS.GetByteCount("ちaああba")));
Assert(m.GetGroupLength(2) == (l = SJIS.GetByteCount("あ")));
Assert(m.GetGroupEnd(2) == s + l);
// the group has 2 captures, the last one is its value:
Assert(m.GetGroupStart(3) == (s = SJIS.GetByteCount("ちaああbaあ")));
Assert(m.GetGroupLength(3) == (l = SJIS.GetByteCount("bbb")));
Assert(m.GetGroupEnd(3) == s + l);
}
开发者ID:BrianGenisio,项目名称:ironruby,代码行数:73,代码来源:RegexTests.cs
示例17: BlockReplaceAll
// returns true if block jumped
// "result" will be null if there is no successful match
private static bool BlockReplaceAll(RubyScope/*!*/ scope, MutableString/*!*/ input, BlockParam/*!*/ block,
RubyRegex/*!*/ regex, out object blockResult, out MutableString result) {
var matchScope = scope.GetInnerMostClosureScope();
MatchCollection matches = regex.Matches(input);
if (matches.Count == 0) {
result = null;
blockResult = null;
matchScope.CurrentMatch = null;
return false;
}
// create an empty result:
result = input.CreateInstance().TaintBy(input);
int offset = 0;
foreach (Match match in matches) {
MatchData currentMatch = new MatchData(match, input);
matchScope.CurrentMatch = currentMatch;
uint version = input.Version;
if (block.Yield(MutableString.Create(match.Value), out blockResult)) {
return true;
}
if (input.Version != version) {
return false;
}
// resets the $~ scope variable to the last match (skipd if block jumped):
matchScope.CurrentMatch = currentMatch;
MutableString replacement = Protocols.ConvertToString(scope.RubyContext, blockResult);
result.TaintBy(replacement);
// prematch:
result.Append(input, offset, match.Index - offset);
// replacement (unlike ReplaceAll, don't interpolate special sequences like \1 in block return value):
result.Append(replacement);
offset = match.Index + match.Length;
}
// post-last-match:
result.Append(input, offset, input.Length - offset);
blockResult = null;
return false;
}
开发者ID:mscottford,项目名称:ironruby,代码行数:52,代码来源:MutableStringOps.cs
示例18: Match
private bool Match(RubyRegex/*!*/ pattern, bool currentPositionOnly, bool advancePosition) {
Match match = pattern.Match(_scanString, _currentPosition);
_lastMatch = null;
_lastMatchingGroups = null;
_foundPosition = 0;
if (!match.Success) {
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.Groups;
if (advancePosition) {
_currentPosition += length;
}
return true;
}
开发者ID:Hank923,项目名称:ironruby,代码行数:21,代码来源:StringScanner.cs
示例19: ReplaceAll
private static MutableString ReplaceAll(RubyScope/*!*/ scope, MutableString/*!*/ input, MutableString/*!*/ replacement,
RubyRegex/*!*/ regex) {
var matchScope = scope.GetInnerMostClosureScope();
// case of all
MatchCollection matches = regex.Matches(input);
if (matches.Count == 0) {
matchScope.CurrentMatch = null;
return null;
}
MutableString result = input.CreateInstance().TaintBy(input).TaintBy(replacement);
int offset = 0;
foreach (Match match in matches) {
result.Append(input, offset, match.Index - offset);
AppendReplacementExpression(input, match, result, replacement);
offset = match.Index + match.Length;
}
result.Append(input, offset, input.Length - offset);
matchScope.CurrentMatch = new MatchData(matches[matches.Count - 1], input);
return result;
}
开发者ID:mscottford,项目名称:ironruby,代码行数:25,代码来源:MutableStringOps.cs
示例20: ToYaml
public static Node/*!*/ ToYaml(RubyRegex/*!*/ self, [NotNull]RubyRepresenter/*!*/ rep) {
return rep.Scalar(self, rep.Context.Inspect(self));
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:3,代码来源:BuiltinsOps.cs
注:本文中的RubyRegex类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论