using System.IO; using System.Text; using UnityEngine.Localization.SmartFormat.Core.Formatting; using UnityEngine.Localization.SmartFormat.Core.Output; namespace UnityEngine.Localization.SmartFormat { /// /// Extensions to support smart format common use cases. /// public static class SmartExtensions { /// Appends a formatted string, using the same semantics as Smart.Format. /// The StringBuilder that will be used for output /// The template that defines how the arguments are formatted /// A list of arguments to be used in formatting public static void AppendSmart(this StringBuilder sb, string format, params object[] args) { var output = new StringOutput(sb); Smart.Default.FormatInto(output, format, args); } /// AppendLines a formatted string, using the same semantics as Smart.Format. /// The StringBuilder that will be used for output /// The template that defines how the arguments are formatted /// A list of arguments to be used in formatting public static void AppendLineSmart(this StringBuilder sb, string format, params object[] args) { AppendSmart(sb, format, args); sb.AppendLine(); } /// Writes out a formatted string, using the same semantics as Smart.Format. /// The TextWriter that will be used for output /// The template that defines how the arguments are formatted /// A list of arguments to be used in formatting public static void WriteSmart(this TextWriter writer, string format, params object[] args) { var output = new TextWriterOutput(writer); Smart.Default.FormatInto(output, format, args); } /// Writes out a formatted string, using the same semantics as Smart.Format. /// The TextWriter that will be used for output /// The template that defines how the arguments are formatted /// A list of arguments to be used in formatting public static void WriteLineSmart(this TextWriter writer, string format, params object[] args) { WriteSmart(writer, format, args); writer.WriteLine(); } /// Formats the specified arguments using this string as a template. /// The template that defines how the arguments are formatted /// A list of arguments to be used in formatting /// public static string FormatSmart(this string format, params object[] args) { return Smart.Format(format, args); } /// /// Formats the specified arguments using this string as a template. /// Caches the parsing results for increased performance. /// /// The template that defines how the arguments are formatted /// A list of arguments to be used in formatting /// Outputs an object that increases performance if the same format string is used repeatedly. /// public static string FormatSmart(this string format, ref FormatCache cache, params object[] args) { // With cache: return Smart.Default.FormatWithCache(ref cache, format, args); } } }