public static string StripAccelerators(string input, char accessSpecifier) { if (string.IsNullOrEmpty(input) || input.IndexOf(accessSpecifier) < 0) { return(input); } using (ReusableResourceHolder <StringBuilder> reusableResourceHolder = ReusableStringBuilder.AcquireDefault(input.Length)) { StringBuilder resource = reusableResourceHolder.Resource; for (int index1 = 0; index1 < input.Length; ++index1) { if (input[index1] == accessSpecifier) { ++index1; } else if (input[index1] == 40) { bool flag = false; int num = -1; for (int index2 = index1 + 1; index2 < input.Length; ++index2) { if (input[index2] == 41) { num = index2; break; } if (input[index2] == accessSpecifier) { if (index2 == input.Length - 1 || input[index2 + 1] == accessSpecifier) { ++index2; } else { flag = true; } } } if (flag && num >= 0) { index1 = num; continue; } } if (index1 < input.Length) { resource.Append(input[index1]); } } return(resource.ToString().TrimEnd(Array.Empty <char>())); } }
public static string GetCommonPathPrefix(string path1, string path2) { Validate.IsNotNull(path1, "path1"); Validate.IsNotNull(path2, "path2"); if (path1.Length == 0 || path2.Length == 0) { return(string.Empty); } if (ArePathsEqual(path1, path2)) { return(path1); } bool flag = path1.StartsWith("\\\\"); if (flag != path2.StartsWith("\\\\")) { return(string.Empty); } using (ReusableResourceHolder <StringBuilder> reusableResourceHolder = ReusableStringBuilder.AcquireDefault(260)) { StringBuilder resource = reusableResourceHolder.Resource; PathParser pathParser = new PathParser(path1); PathParser other = new PathParser(path2); while (pathParser.MoveNext() && other.MoveNext() && (pathParser.CurrentLength == other.CurrentLength && pathParser.CompareCurrentSegment(other) == 0)) { if (resource.Length == 0 & flag) { resource.Append("\\\\"); } else if (resource.Length > 0) { resource.Append(Path.DirectorySeparatorChar); } resource.Append(path1, pathParser.CurrentStartIndex, pathParser.CurrentLength); } if (resource.Length == 2 && resource[1] == Path.VolumeSeparatorChar) { resource.Append('\\'); } return(resource.ToString()); } }