private static void AppendDirectoryName(MutableString /*!*/ result, MutableString /*!*/ name) { int resultLength = result.GetCharCount(); int i; for (i = resultLength - 1; i >= 0; i--) { if (!IsDirectorySeparator(result.GetChar(i))) { break; } } if (i == resultLength - 1) { if (!IsDirectorySeparator(name.GetFirstChar())) { result.Append(DirectorySeparatorChar); } result.Append(name); } else if (IsDirectorySeparator(name.GetFirstChar())) { result.Replace(i + 1, resultLength - i - 1, name); } else { result.Append(name); } }
private static MutableString /*!*/ AppendEscapeForwardSlash(MutableString /*!*/ result, MutableString /*!*/ pattern) { int first = 0; int patternLength = pattern.GetCharCount(); int i = SkipToUnescapedForwardSlash(pattern, patternLength, 0); while (i >= 0) { Debug.Assert(i < patternLength); Debug.Assert(pattern.GetChar(i) == '/' && (i == 0 || pattern.GetChar(i - 1) != '\\')); result.Append(pattern, first, i - first); result.Append('\\'); first = i; // include forward slash in the next append i = SkipToUnescapedForwardSlash(pattern, patternLength, i + 1); } result.Append(pattern, first, patternLength - first); return(result); }
public int GetCharCount() { return(_string.GetCharCount()); }
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)); }