本文整理汇总了C#中MutableString.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# MutableString.GetLength方法的具体用法?C# MutableString.GetLength怎么用?C# MutableString.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableString
的用法示例。
在下文中一共展示了MutableString.GetLength方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Insert
public static MutableString Insert(MutableString/*!*/ self, [DefaultProtocol]int start, [DefaultProtocol, NotNull]MutableString/*!*/ value) {
return self.Insert(NormalizeInsertIndex(start, self.GetLength()), value).TaintBy(value);
}
示例2: AppendReplacementExpression
private static void AppendReplacementExpression(MutableString/*!*/ input, MatchData/*!*/ match, MutableString/*!*/ result,
MutableString/*!*/ replacement) {
int backslashCount = 0;
for (int i = 0; i < replacement.Length; i++) {
char c = replacement.GetChar(i);
if (c == '\\') {
backslashCount++;
} else if (backslashCount == 0) {
result.Append(c);
} else {
AppendBackslashes(backslashCount, result, 0);
// Odd number of \'s + digit means insert replacement expression
if ((backslashCount & 1) == 1) {
if (Char.IsDigit(c)) {
AppendGroupByIndex(match, c - '0', result);
} else if (c == '&') {
AppendGroupByIndex(match, match.GroupCount - 1, result);
} else if (c == '`') {
// Replace with everything in the input string BEFORE the match
result.Append(input, 0, match.Index);
} else if (c == '\'') {
// Replace with everything in the input string AFTER the match
int start = match.Index + match.Length;
// TODO:
result.Append(input, start, input.GetLength() - start);
} else if (c == '+') {
// Replace last character in last successful match group
AppendLastCharOfLastMatchGroup(match, result);
} else {
// unknown escaped replacement char, go ahead and replace untouched
result.Append('\\');
result.Append(c);
}
} else {
// Any other # of \'s or a non-digit character means insert literal \'s and character
AppendBackslashes(backslashCount, result, 1);
result.Append(c);
}
backslashCount = 0;
}
}
AppendBackslashes(backslashCount, result, 1);
}
示例3: InternalSplit
private static RubyArray/*!*/ InternalSplit(MutableString/*!*/ str, MutableString separator, int limit) {
RubyArray result;
if (limit == 1) {
// returns an array with original string
result = new RubyArray(1);
result.Add(str);
return result;
}
if (separator == null || separator.StartsWith(' ') && separator.GetLength() == 1) {
return WhitespaceSplit(str, limit);
}
if (separator.IsEmpty) {
return CharacterSplit(str, limit);
}
if (limit <= 0) {
result = new RubyArray();
} else {
result = new RubyArray(limit + 1);
}
// TODO: invalid characters, k-coding?
str.PrepareForCharacterRead();
separator.PrepareForCharacterRead();
str.RequireCompatibleEncoding(separator);
int separatorLength = separator.GetCharCount();
int i = 0;
int next;
while ((limit <= 0 || result.Count < limit - 1) && (next = str.IndexOf(separator, i)) != -1) {
result.Add(str.CreateInstance().Append(str, i, next - i).TaintBy(str));
i = next + separatorLength;
}
result.Add(str.CreateInstance().Append(str, i).TaintBy(str));
if (limit == 0) {
RemoveTrailingEmptyItems(result);
}
return result;
}
示例4: InternalChomp
private static MutableString InternalChomp(MutableString/*!*/ self, MutableString separator) {
if (separator == null) {
return self.Clone();
}
// Remove multiple trailing CR/LFs
if (separator.Length == 0) {
return ChompTrailingCarriageReturns(self, false).TaintBy(self);
}
// Remove single trailing CR/LFs
MutableString result = self.Clone();
int length = result.GetCharCount();
if (separator.StartsWith('\n') && separator.GetLength() == 1) {
if (length > 1 && result.GetChar(length - 2) == '\r' && result.GetChar(length - 1) == '\n') {
result.Remove(length - 2, 2);
} else if (length > 0 && (self.GetChar(length - 1) == '\n' || result.GetChar(length - 1) == '\r')) {
result.Remove(length - 1, 1);
}
} else if (result.EndsWith(separator)) {
int separatorLength = separator.GetCharCount();
result.Remove(length - separatorLength, separatorLength);
}
return result;
}
示例5: ReadLineOrParagraph
public MutableString ReadLineOrParagraph(MutableString separator, RubyEncoding/*!*/ encoding, bool preserveEndOfLines) {
if (separator == null) {
var result = MutableString.CreateBinary();
return AppendBytes(result, Int32.MaxValue, preserveEndOfLines) == 0 ? null : result;
} else if (separator.StartsWith('\n') && separator.GetLength() == 1) {
return ReadLine(encoding, preserveEndOfLines);
} else if (separator.IsEmpty) {
return ReadParagraph(encoding, preserveEndOfLines);
} else {
return ReadLine(separator, encoding, preserveEndOfLines);
}
}
示例6: ReadLineOrParagraph
public MutableString ReadLineOrParagraph(MutableString separator, RubyEncoding/*!*/ encoding, bool preserveEndOfLines, int limit) {
ContractUtils.Requires(limit >= 0);
if (limit == 0) {
return MutableString.CreateEmpty();
} else if (separator == null) {
var result = MutableString.CreateBinary();
return AppendBytes(result, limit, preserveEndOfLines) == 0 ? null : result;
} else if (separator.StartsWith('\n') && separator.GetLength() == 1) {
return ReadLine(encoding, preserveEndOfLines, limit);
} else if (separator.IsEmpty) {
return ReadParagraph(encoding, preserveEndOfLines, limit);
} else {
return ReadLine(separator, encoding, preserveEndOfLines, limit);
}
}