本文整理汇总了C#中IronRuby.Builtins.Range类的典型用法代码示例。如果您正苦于以下问题:C# Range类的具体用法?C# Range怎么用?C# Range使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Range类属于IronRuby.Builtins命名空间,在下文中一共展示了Range类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: NormalizeSubstringRange
internal static bool NormalizeSubstringRange(ConversionStorage<int>/*!*/ fixnumCast, Range/*!*/ range, int length, out int begin, out int count) {
begin = Protocols.CastToFixnum(fixnumCast, range.Begin);
int end = Protocols.CastToFixnum(fixnumCast, range.End);
begin = IListOps.NormalizeIndex(length, begin);
if (begin < 0 || begin > length) {
count = 0;
return false;
}
end = IListOps.NormalizeIndex(length, end);
count = range.ExcludeEnd ? end - begin : end - begin + 1;
return true;
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:15,代码来源:MutableStringOps.cs
示例2: NormalizeRange
internal static bool NormalizeRange(ConversionStorage<int>/*!*/ fixnumCast, int listCount, Range/*!*/ range, out int begin, out int count) {
begin = Protocols.CastToFixnum(fixnumCast, range.Begin);
int end = Protocols.CastToFixnum(fixnumCast, range.End);
begin = NormalizeIndex(listCount, begin);
if (begin < 0 || begin > listCount) {
count = 0;
return false;
}
end = NormalizeIndex(listCount, end);
count = range.ExcludeEnd ? end - begin : end - begin + 1;
return true;
}
开发者ID:aceptra,项目名称:ironruby,代码行数:16,代码来源:IListOps.cs
示例3: NormalizeRange
internal static bool NormalizeRange(RubyContext/*!*/ context, int listCount, Range/*!*/ range, out int begin, out int count) {
bool excludeEnd;
int end;
Protocols.ConvertToIntegerRange(context, range, out begin, out end, out excludeEnd);
begin = NormalizeIndex(listCount, begin);
if (begin < 0 || begin > listCount) {
count = 0;
return false;
}
end = NormalizeIndex(listCount, end);
count = excludeEnd ? end - begin : end - begin + 1;
return true;
}
开发者ID:mscottford,项目名称:ironruby,代码行数:17,代码来源:IListOps.cs
示例4: Equals
public static bool Equals(BinaryOpStorage/*!*/ equals, Range/*!*/ self, [NotNull]Range/*!*/ other) {
if (self == other) {
return true;
}
return Protocols.IsEqual(equals, self.Begin, other.Begin)
&& Protocols.IsEqual(equals, self.End, other.End)
&& self.ExcludeEnd == other.ExcludeEnd;
}
开发者ID:jcteague,项目名称:ironruby,代码行数:8,代码来源:RangeOps.cs
示例5: Eql
public static bool Eql(BinaryOpStorage/*!*/ equalsStorage, Range/*!*/ self, [NotNull]Range/*!*/ other) {
if (self == other) {
return true;
}
var site = equalsStorage.GetCallSite("eql?");
return Protocols.IsTrue(site.Target(site, self.Begin, other.Begin))
&& Protocols.IsTrue(site.Target(site, self.End, other.End))
&& self.ExcludeEnd == other.ExcludeEnd;
}
开发者ID:jcteague,项目名称:ironruby,代码行数:11,代码来源:RangeOps.cs
示例6: ToYaml
public static Node/*!*/ ToYaml(UnaryOpStorage/*!*/ beginStorage, UnaryOpStorage/*!*/ endStorage, UnaryOpStorage/*!*/ exclStorage,
Range/*!*/ self, [NotNull]RubyRepresenter/*!*/ rep) {
var begin = beginStorage.GetCallSite("begin");
var end = endStorage.GetCallSite("end");
var map = new Dictionary<MutableString, object>() {
{ MutableString.Create("begin"), begin.Target(begin, rep.Context, self) },
{ MutableString.Create("end"), end.Target(end, rep.Context, self) },
{ MutableString.Create("excl"), self.ExcludeEnd },
};
rep.AddYamlProperties(self, map);
return rep.Map(self, map);
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:15,代码来源:BuiltinsOps.cs
示例7: GetHashCode
public static int GetHashCode(UnaryOpStorage/*!*/ hashStorage, Range/*!*/ self) {
// MRI: Ruby treatment of hash return value is inconsistent.
// No conversions happen here (unlike e.g. Array.hash).
var hashSite = hashStorage.GetCallSite("hash");
return unchecked(
Protocols.ToHashCode(hashSite.Target(hashSite, self.Begin)) ^
Protocols.ToHashCode(hashSite.Target(hashSite, self.End)) ^
(self.ExcludeEnd ? 179425693 : 1794210891)
);
}
开发者ID:Jirapong,项目名称:main,代码行数:10,代码来源:RangeOps.cs
示例8: StepString
/// <summary>
/// Step through a Range of Strings.
/// </summary>
/// <remarks>
/// This method requires step to be a Fixnum.
/// It uses a hybrid string comparison to prevent infinite loops and calls String#succ to get each item in the range.
/// </remarks>
private static object StepString(
ConversionStorage<MutableString>/*!*/ stringCast,
BinaryOpStorage/*!*/ comparisonStorage,
BinaryOpStorage/*!*/ lessThanStorage,
BinaryOpStorage/*!*/ greaterThanStorage,
UnaryOpStorage/*!*/ succStorage,
BlockParam block, Range/*!*/ self, MutableString begin, MutableString end, int step) {
CheckStep(step);
object result;
MutableString item = begin;
int comp;
var succSite = succStorage.GetCallSite("succ");
while ((comp = Protocols.Compare(comparisonStorage, lessThanStorage, greaterThanStorage, item, end)) < 0) {
if (block == null) {
throw RubyExceptions.NoBlockGiven();
}
if (block.Yield(item, out result)) {
return result;
}
for (int i = 0; i < step; i++) {
item = Protocols.CastToString(stringCast, succSite.Target(succSite, item));
}
if (item.Length > end.Length) {
return self;
}
}
if (comp == 0 && !self.ExcludeEnd) {
if (block == null) {
throw RubyExceptions.NoBlockGiven();
}
if (block.Yield(item, out result)) {
return result;
}
}
return self;
}
开发者ID:jcteague,项目名称:ironruby,代码行数:50,代码来源:RangeOps.cs
示例9: StepObject
/// <summary>
/// Step through a Range of objects that are not Numeric or String.
/// </summary>
private static object StepObject(
BinaryOpStorage/*!*/ comparisonStorage,
BinaryOpStorage/*!*/ lessThanStorage,
BinaryOpStorage/*!*/ greaterThanStorage,
BinaryOpStorage/*!*/ equalsStorage,
UnaryOpStorage/*!*/ succStorage,
BlockParam block, Range/*!*/ self, object begin, object end, int step) {
CheckStep(lessThanStorage.GetCallSite("<"), equalsStorage.GetCallSite("=="), step);
object item = begin, result;
int comp;
var succSite = succStorage.GetCallSite("succ");
while ((comp = Protocols.Compare(comparisonStorage, lessThanStorage, greaterThanStorage, item, end)) < 0) {
if (block == null) {
throw RubyExceptions.NoBlockGiven();
}
if (block.Yield(item, out result)) {
return result;
}
for (int i = 0; i < step; ++i) {
item = succSite.Target(succSite, item);
}
}
if (comp == 0 && !self.ExcludeEnd) {
if (block == null) {
throw RubyExceptions.NoBlockGiven();
}
if (block.Yield(item, out result)) {
return result;
}
}
return self;
}
开发者ID:jcteague,项目名称:ironruby,代码行数:42,代码来源:RangeOps.cs
示例10: StepString
/// <summary>
/// Step through a Range of Strings.
/// </summary>
/// <remarks>
/// This method requires step to be a Fixnum.
/// It uses a hybrid string comparison to prevent infinite loops and calls String#succ to get each item in the range.
/// </remarks>
private static object StepString(EachStorage/*!*/ storage, BlockParam/*!*/ block, Range/*!*/ self, MutableString begin, MutableString end, int step) {
Assert.NotNull(storage, block, self);
CheckStep(step);
object result;
MutableString item = begin;
int comp;
var succSite = storage.SuccSite;
while ((comp = Protocols.Compare(storage, item, end)) < 0) {
if (block.Yield(item.Clone(), out result)) {
return result;
}
if (ReferenceEquals(item, begin)) {
item = item.Clone();
}
// TODO: this can be optimized
for (int i = 0; i < step; i++) {
MutableStringOps.SuccInPlace(item);
}
if (item.Length > end.Length) {
return self;
}
}
if (comp == 0 && !self.ExcludeEnd) {
if (block.Yield(item.Clone(), out result)) {
return result;
}
}
return self;
}
开发者ID:Jirapong,项目名称:main,代码行数:41,代码来源:RangeOps.cs
示例11: Step
public static object Step(
ConversionStorage<MutableString>/*!*/ stringCast,
ConversionStorage<int>/*!*/ fixnumCast,
RespondToStorage/*!*/ respondToStorage,
BinaryOpStorage/*!*/ comparisonStorage,
BinaryOpStorage/*!*/ lessThanStorage,
BinaryOpStorage/*!*/ lessThanEqualsStorage,
BinaryOpStorage/*!*/ greaterThanStorage,
BinaryOpStorage/*!*/ equalsStorage,
BinaryOpStorage/*!*/ addStorage,
UnaryOpStorage/*!*/ succStorage,
BlockParam block, Range/*!*/ self, [Optional]object step) {
if (step == Missing.Value) {
step = ClrInteger.One;
}
// We attempt to cast step to Fixnum here even though if we were iterating over Floats, for instance, we use step as is.
// This prevents cases such as (1.0..2.0).step(0x800000000000000) {|x| x } from working but that is what MRI does.
if (self.Begin is int && self.End is int) {
// self.begin is Fixnum; directly call item = item + 1 instead of succ
int intStep = Protocols.CastToFixnum(fixnumCast, step);
return StepFixnum(block, self, (int)self.Begin, (int)self.End, intStep);
} else if (self.Begin is MutableString ) {
// self.begin is String; use item.succ and item <=> self.end but make sure you check the length of the strings
int intStep = Protocols.CastToFixnum(fixnumCast, step);
return StepString(stringCast, comparisonStorage, lessThanStorage, greaterThanStorage, succStorage,
block, self, (MutableString)self.Begin, (MutableString)self.End, intStep
);
} else if (succStorage.Context.IsInstanceOf(self.Begin, succStorage.Context.GetClass(typeof(Numeric)))) {
// self.begin is Numeric; invoke item = item + 1 instead of succ and invoke < or <= for compare
return StepNumeric(lessThanStorage, lessThanEqualsStorage, equalsStorage, addStorage,
block, self, self.Begin, self.End, step
);
} else {
// self.begin is not Numeric or String; just invoke item.succ and item <=> self.end
CheckBegin(respondToStorage, self.Begin);
int intStep = Protocols.CastToFixnum(fixnumCast, step);
return StepObject(comparisonStorage, lessThanStorage, greaterThanStorage, equalsStorage, succStorage,
block, self, self.Begin, self.End, intStep
);
}
}
开发者ID:jcteague,项目名称:ironruby,代码行数:43,代码来源:RangeOps.cs
示例12: Step
public static object Step(StepStorage/*!*/ storage, [NotNull]BlockParam/*!*/ block, Range/*!*/ self, [Optional]object step) {
if (step == Missing.Value) {
step = ClrInteger.One;
}
// We attempt to cast step to Fixnum here even though if we were iterating over Floats, for instance, we use step as is.
// This prevents cases such as (1.0..2.0).step(0x800000000000000) {|x| x } from working but that is what MRI does.
if (self.Begin is int && self.End is int) {
// self.begin is Fixnum; directly call item = item + 1 instead of succ
var site = storage.FixnumCastSite;
int intStep = site.Target(site, step);
return StepFixnum(block, self, (int)self.Begin, (int)self.End, intStep);
} else if (self.Begin is MutableString) {
// self.begin is String; use item.succ and item <=> self.end but make sure you check the length of the strings
var site = storage.FixnumCastSite;
int intStep = site.Target(site, step);
return StepString(storage, block, self, (MutableString)self.Begin, (MutableString)self.End, intStep);
} else if (storage.Context.IsInstanceOf(self.Begin, storage.Context.GetClass(typeof(Numeric)))) {
// self.begin is Numeric; invoke item = item + 1 instead of succ and invoke < or <= for compare
return StepNumeric(storage, block, self, self.Begin, self.End, step);
} else {
// self.begin is not Numeric or String; just invoke item.succ and item <=> self.end
var site = storage.FixnumCastSite;
int intStep = site.Target(site, step);
return StepObject(storage, block, self, self.Begin, self.End, intStep);
}
}
开发者ID:Jirapong,项目名称:main,代码行数:27,代码来源:RangeOps.cs
示例13: StepFixnum
/// <summary>
/// Step through a Range of Fixnums.
/// </summary>
/// <remarks>
/// This method is optimized for direct integer operations using < and + directly.
/// It is not used if either begin or end are outside Fixnum bounds.
/// </remarks>
private static object StepFixnum(BlockParam/*!*/ block, Range/*!*/ self, int begin, int end, int step) {
Assert.NotNull(block, self);
CheckStep(step);
object result;
int item = begin;
while (item < end) {
if (block.Yield(item, out result)) {
return result;
}
item += step;
}
if (item == end && !self.ExcludeEnd) {
if (block.Yield(item, out result)) {
return result;
}
}
return self;
}
开发者ID:Jirapong,项目名称:main,代码行数:27,代码来源:RangeOps.cs
示例14: GetStepEnumerator
public static Enumerator/*!*/ GetStepEnumerator(StepStorage/*!*/ storage, Range/*!*/ self, [Optional]object step) {
return new Enumerator((_, block) => Step(storage, block, self, step));
}
开发者ID:Jirapong,项目名称:main,代码行数:3,代码来源:RangeOps.cs
示例15: Each
public static object Each(EachStorage/*!*/ storage, [NotNull]BlockParam/*!*/ block, Range/*!*/ self) {
if (self.Begin is int && self.End is int) {
return StepFixnum(block, self, (int)self.Begin, (int)self.End, 1);
} else if (self.Begin is MutableString) {
return StepString(storage, block, self, (MutableString)self.Begin, (MutableString)self.End, 1);
} else {
return StepObject(storage, block, self, self.Begin, self.End, 1);
}
}
开发者ID:Jirapong,项目名称:main,代码行数:9,代码来源:RangeOps.cs
示例16: GetEachEnumerator
public static Enumerator/*!*/ GetEachEnumerator(EachStorage/*!*/ storage, Range/*!*/ self) {
return new Enumerator((_, block) => Each(storage, block, self));
}
开发者ID:Jirapong,项目名称:main,代码行数:3,代码来源:RangeOps.cs
示例17: GetHashCode
public static int GetHashCode(Range/*!*/ self) {
int hash = RubyUtils.GetHashCode(self.Begin);
hash ^= RubyUtils.GetHashCode(self.End);
hash ^= RubyUtils.GetHashCode(self.ExcludeEnd);
return hash;
}
开发者ID:jcteague,项目名称:ironruby,代码行数:6,代码来源:RangeOps.cs
示例18: StepNumeric
/// <summary>
/// Step through a Range of Numerics.
/// </summary>
private static object StepNumeric(StepStorage/*!*/ storage, BlockParam/*!*/ block, Range/*!*/ self, object begin, object end, object step) {
Assert.NotNull(storage, block, self);
CheckStep(storage, step);
object item = begin;
object result;
var site = self.ExcludeEnd ? storage.LessThanSite : storage.LessThanEqualsSite;
while (RubyOps.IsTrue(site.Target(site, item, end))) {
if (block.Yield(item, out result)) {
return result;
}
var add = storage.AddSite;
item = add.Target(add, item, step);
}
return self;
}
开发者ID:Jirapong,项目名称:main,代码行数:22,代码来源:RangeOps.cs
示例19: Each
public static object Each(
ConversionStorage<MutableString>/*!*/ stringCast,
RespondToStorage/*!*/ respondToStorage,
BinaryOpStorage/*!*/ comparisonStorage,
BinaryOpStorage/*!*/ lessThanStorage,
BinaryOpStorage/*!*/ greaterThanStorage,
BinaryOpStorage/*!*/ equalsStorage,
UnaryOpStorage/*!*/ succStorage,
BlockParam block, Range/*!*/ self) {
// We check that self.begin responds to "succ" even though some of the implementations don't use it.
CheckBegin(respondToStorage, self.Begin);
if (self.Begin is int && self.End is int) {
return StepFixnum(block, self, (int)self.Begin, (int)self.End, 1);
} else if (self.Begin is MutableString) {
return StepString(stringCast, comparisonStorage, lessThanStorage, greaterThanStorage, succStorage,
block, self, (MutableString)self.Begin, (MutableString)self.End, 1
);
} else {
return StepObject(comparisonStorage, lessThanStorage, greaterThanStorage, equalsStorage, succStorage,
block, self, self.Begin, self.End, 1
);
}
}
开发者ID:jcteague,项目名称:ironruby,代码行数:25,代码来源:RangeOps.cs
示例20: StepObject
/// <summary>
/// Step through a Range of objects that are not Numeric or String.
/// </summary>
private static object StepObject(EachStorage/*!*/ storage, BlockParam/*!*/ block, Range/*!*/ self, object begin, object end, int step) {
Assert.NotNull(storage, block, self);
CheckStep(storage, step);
CheckBegin(storage, self.Begin);
object item = begin, result;
int comp;
var succSite = storage.SuccSite;
while ((comp = Protocols.Compare(storage, item, end)) < 0) {
if (block.Yield(item, out result)) {
return result;
}
for (int i = 0; i < step; ++i) {
item = succSite.Target(succSite, item);
}
}
if (comp == 0 && !self.ExcludeEnd) {
if (block.Yield(item, out result)) {
return result;
}
}
return self;
}
开发者ID:Jirapong,项目名称:main,代码行数:29,代码来源:RangeOps.cs
注:本文中的IronRuby.Builtins.Range类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论