本文整理汇总了C#中MutableString.CreateInstance方法的典型用法代码示例。如果您正苦于以下问题:C# MutableString.CreateInstance方法的具体用法?C# MutableString.CreateInstance怎么用?C# MutableString.CreateInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableString
的用法示例。
在下文中一共展示了MutableString.CreateInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSubstring
public static MutableString GetSubstring(ConversionStorage<int>/*!*/ fixnumCast, RubyContext/*!*/ context, MutableString/*!*/ self,
[NotNull]Range/*!*/ range) {
int begin = Protocols.CastToFixnum(fixnumCast, context, range.Begin);
int end = Protocols.CastToFixnum(fixnumCast, context, range.End);
begin = NormalizeIndex(self, begin);
if (begin < 0 || begin > self.Length) {
return null;
}
end = NormalizeIndex(self, end);
int count = range.ExcludeEnd ? end - begin : end - begin + 1;
return (count < 0) ? self.CreateInstance().TaintBy(self) : GetSubstring(self, begin, count);
}
示例2: GetSubstring
public static MutableString GetSubstring(RubyContext/*!*/ context, MutableString/*!*/ self, [NotNull]Range/*!*/ range) {
bool excludeEnd;
int begin, end;
Protocols.ConvertToIntegerRange(context, range, out begin, out end, out excludeEnd);
begin = NormalizeIndex(self, begin);
if (begin < 0 || begin > self.Length) {
return null;
}
end = NormalizeIndex(self, end);
int count = excludeEnd ? end - begin : end - begin + 1;
return (count < 0) ? self.CreateInstance().TaintBy(self) : GetSubstring(self, begin, count);
}
示例3: Repeat
public static MutableString/*!*/ Repeat(MutableString/*!*/ self, [DefaultProtocol]int times) {
if (times < 0) {
throw RubyExceptions.CreateArgumentError("negative argument");
}
MutableString result = self.CreateInstance().TaintBy(self);
for (int i = 0; i < times; i++) {
result.Append(self);
}
return result;
}
示例4: RemoveSubstringInPlace
public static MutableString RemoveSubstringInPlace(RubyContext/*!*/ context, MutableString/*!*/ self, [NotNull]Range/*!*/ range) {
bool excludeEnd;
int begin, end;
Protocols.ConvertToIntegerRange(context, range, out begin, out end, out excludeEnd);
if (!InInclusiveRangeNormalized(self, ref begin)) {
return null;
}
end = NormalizeIndex(self, end);
int count = excludeEnd ? end - begin : end - begin + 1;
return count < 0 ? self.CreateInstance() : RemoveSubstringInPlace(self, begin, count);
}
示例5: WhitespaceSplit
private static RubyArray/*!*/ WhitespaceSplit(MutableString/*!*/ self, int maxComponents) {
char[] separators = new char[] { ' ', '\n', '\r', '\t', '\v' };
MutableString[] elements = self.Split(separators, (maxComponents < 0) ? Int32.MaxValue : maxComponents, StringSplitOptions.RemoveEmptyEntries);
RubyArray result = new RubyArray();
foreach (MutableString element in elements) {
result.Add(self.CreateInstance().Append(element).TaintBy(self));
}
// Strange behavior to match Ruby semantics
if (maxComponents < 0) {
result.Add(self.CreateInstance().TaintBy(self));
}
return result;
}
示例6: TrInternal
private static MutableString/*!*/ TrInternal(MutableString/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ from,
[DefaultProtocol, NotNull]MutableString/*!*/ to, bool squeeze) {
MutableString result = self.CreateInstance().TaintBy(self);
IntervalParser parser = new IntervalParser(from);
// TODO: a single pass to generate both?
MutableString source = parser.ParseSequence();
BitArray bitmap = parser.Parse();
MutableString dest = new IntervalParser(to).ParseSequence();
int lastChar = dest.GetLastChar();
char? lastTranslated = null;
for (int i = 0; i < self.Length; i++) {
char c = self.GetChar(i);
if (bitmap.Get(c)) {
char? thisTranslated = null;
int index = source.IndexOf(c);
if (index >= dest.Length) {
if (lastChar != -1) {
thisTranslated = (char)lastChar;
}
} else {
thisTranslated = dest.GetChar(index);
}
if (thisTranslated != null && (!squeeze || lastTranslated == null || lastTranslated.Value != thisTranslated)) {
result.Append(thisTranslated.Value);
}
lastTranslated = thisTranslated;
} else {
result.Append(c);
lastTranslated = null;
}
}
return result;
}
示例7: GetSubstring
public static MutableString GetSubstring(MutableString/*!*/ self, [DefaultProtocol]int start, [DefaultProtocol]int count) {
int byteCount = self.GetByteCount();
if (!NormalizeSubstringRange(byteCount, ref start, ref count)) {
return (start == byteCount) ? self.CreateInstance().TaintBy(self) : null;
}
return self.CreateInstance().Append(self, start, count).TaintBy(self);
}
示例8: Repeat
public static MutableString/*!*/ Repeat(MutableString/*!*/ self, [DefaultProtocol]int times) {
if (times < 0) {
throw RubyExceptions.CreateArgumentError("negative argument");
}
return self.CreateInstance().TaintBy(self).AppendMultiple(self, times);
}
示例9: RemoveSubstringInPlace
public static MutableString RemoveSubstringInPlace(ConversionStorage<int>/*!*/ fixnumCast,
MutableString/*!*/ self, [NotNull]Range/*!*/ range) {
int begin = Protocols.CastToFixnum(fixnumCast, range.Begin);
int end = Protocols.CastToFixnum(fixnumCast, range.End);
if (!InInclusiveRangeNormalized(self, ref begin)) {
return null;
}
end = IListOps.NormalizeIndex(self.Length, end);
int count = range.ExcludeEnd ? end - begin : end - begin + 1;
return count < 0 ? self.CreateInstance() : RemoveSubstringInPlace(self, begin, count);
}
示例10: Translate
internal static MutableString/*!*/ Translate(MutableString/*!*/ src, MutableString/*!*/ from, MutableString/*!*/ to,
bool inplace, bool squeeze, out bool anyCharacterMaps) {
Assert.NotNull(src, from, to);
if (from.IsEmpty) {
anyCharacterMaps = false;
return inplace ? src : src.Clone();
}
MutableString dst;
if (inplace) {
dst = src;
} else {
dst = src.CreateInstance().TaintBy(src);
}
// TODO: KCODE
src.RequireCompatibleEncoding(from);
dst.RequireCompatibleEncoding(to);
from.SwitchToCharacters();
to.SwitchToCharacters();
CharacterMap map = CharacterMap.Create(from, to);
if (to.IsEmpty) {
anyCharacterMaps = MutableString.TranslateRemove(src, dst, map);
} else if (squeeze) {
anyCharacterMaps = MutableString.TranslateSqueeze(src, dst, map);
} else {
anyCharacterMaps = MutableString.Translate(src, dst, map);
}
return dst;
}
示例11: BlockReplaceAll
// returns true if block jumped
// "result" will be null if there is no successful match
private static bool BlockReplaceAll(ConversionStorage<MutableString>/*!*/ tosConversion,
RubyScope/*!*/ scope, MutableString/*!*/ input, BlockParam/*!*/ block,
RubyRegex/*!*/ regex, out object blockResult, out MutableString result) {
var matchScope = scope.GetInnerMostClosureScope();
var matches = regex.Matches(tosConversion.Context.KCode, 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 (MatchData match in matches) {
matchScope.CurrentMatch = match;
input.TrackChanges();
if (block.Yield(match.GetValue(), out blockResult)) {
return true;
}
if (input.HasChanged) {
return false;
}
// resets the $~ scope variable to the last match (skipd if block jumped):
matchScope.CurrentMatch = match;
MutableString replacement = Protocols.ConvertToString(tosConversion, 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;
}
示例12: Dump
public static MutableString/*!*/ Dump(RubyContext/*!*/ context, MutableString/*!*/ self) {
// Note that "self" could be a subclass of MutableString, and the return value should be
// of the same type
return self.CreateInstance().Append(GetQuotedStringRepresentation(self, context, true, '"')).TaintBy(self);
}
示例13: InternalDelete
private static MutableString/*!*/ InternalDelete(MutableString/*!*/ self, MutableString[]/*!*/ ranges) {
BitArray map = new RangeParser(ranges).Parse();
MutableString result = self.CreateInstance().TaintBy(self);
for (int i = 0; i < self.Length; i++) {
if (!map.Get(self.GetChar(i))) {
result.Append(self.GetChar(i));
}
}
return result;
}
示例14: MakeRubyArray
private static RubyArray/*!*/ MakeRubyArray(MutableString/*!*/ self, MutableString[]/*!*/ elements, int start, int count) {
RubyArray result = new RubyArray(elements.Length);
for (int i = 0; i < count; i++) {
result.Add(self.CreateInstance().Append(elements[start + i]).TaintBy(self));
}
return result;
}
示例15: Chop
public static MutableString/*!*/ Chop(MutableString/*!*/ self) {
return (self.Length == 0) ? self.CreateInstance().TaintBy(self) : ChopInteral(self.Clone());
}