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)); } }
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)); } }
public static CharacterMap /*!*/ Create(MutableString /*!*/ from, MutableString /*!*/ to) { Debug.Assert(!from.IsEmpty); int fromLength = from.GetCharCount(); bool complemental = from.StartsWith('^') && fromLength > 1; // TODO: kcodings // TODO: surrogates // TODO: max - min > threshold int min, max; if (from.DetectByteCharacters()) { min = 0; max = 255; } else { min = Int32.MaxValue; max = -1; for (int i = (complemental ? 1 : 0); i < fromLength; i++) { int c = from.GetChar(i); if (c < min) { min = c; } if (c > max) { max = c; } } } BitArray map; char[] image; if (complemental || to.IsEmpty) { image = null; map = MakeBitmap(from, fromLength, complemental, min, max); } else { map = null; image = new char[max - min + 1]; // no need to initialize the array: Debug.Assert(Unmapped == 0); bool needMap = false; var toEnum = ExpandRanges(to, 0, to.GetCharCount(), true).GetEnumerator(); foreach (var f in ExpandRanges(from, 0, fromLength, false)) { toEnum.MoveNext(); needMap |= (image[f - min] = toEnum.Current) == Unmapped; } if (needMap) { map = MakeBitmap(from, fromLength, false, min, max); } } return(new CharacterMap(map, image, complemental ? to.GetLastChar() : -1, complemental, min, max)); }