// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tools.DotNETCommon { public static class StringUtils { /// /// Indents a string by a given indent /// /// The text to indent /// The indent to add to each line /// The indented string public static string Indent(string Text, string Indent) { string Result = ""; if(Text.Length > 0) { Result = Indent + Text.Replace("\n", "\n" + Indent); } return Result; } /// /// Extension method to allow formatting a string to a stringbuilder and appending a newline /// /// The string builder /// Format string, as used for StringBuilder.AppendFormat /// Arguments for the format string public static void AppendLine(this StringBuilder Builder, string Format, params object[] Args) { Builder.AppendFormat(Format, Args); Builder.AppendLine(); } /// /// Case-sensitive replacement for String.EndsWith(), which seems to be pathalogically slow on Mono. /// /// String to test /// Suffix to check for /// True if the source string ends with the given suffix public static bool FastEndsWith(string Source, string Suffix) { if(Source.Length < Suffix.Length) { return false; } int SourceBase = Source.Length - Suffix.Length; for(int Idx = 0; Idx < Suffix.Length; Idx++) { if(Source[SourceBase + Idx] != Suffix[Idx]) { return false; } } return true; } } }