// Copyright (c) Microsoft Corporation.// Licensed under the MIT License.using System.Management.Automation.Host;using System.Threading;using Dbg = System.Management.Automation.Diagnostics;namespace System.Management.Automation.Internal{internal staticclass StringUtil{internal staticstringFormat(string formatSpec, object o){return string.Format(System.Globalization.CultureInfo.CurrentCulture, formatSpec, o);}internal staticstringFormat(string formatSpec, object o1, object o2){return string.Format(System.Globalization.CultureInfo.CurrentCulture, formatSpec, o1, o2);}internal staticstringFormat(string formatSpec, params object[] o){return string.Format(System.Globalization.CultureInfo.CurrentCulture, formatSpec, o);}internal staticstringTruncateToBufferCellWidth(PSHostRawUserInterface rawUI, string toTruncate, int maxWidthInBufferCells){Dbg.Assert(rawUI != null, "need a reference");Dbg.Assert(maxWidthInBufferCells >= 0, "maxWidthInBufferCells must be positive");string result;int i = Math.Min(toTruncate.Length, maxWidthInBufferCells);do{result = toTruncate.Substring(0, i);int cellCount = rawUI.LengthInBufferCells(result);if (cellCount <= maxWidthInBufferCells){// the segment from start..i fitsbreak;}else{// The segment does not fit, back off a tad until it does// We need to back off 1 by 1 because there could theoretically// be characters taking more 2 buffer cells--i;}} while (true);return result;}// Typical padding is at most a screen's width, any more than that and we won't bother caching.private const int IndentCacheMax = 120;private static readonly string[] IndentCache = new string[IndentCacheMax];internal static string Padding(int countOfSpaces){if (countOfSpaces >= IndentCacheMax)return new string(' ', countOfSpaces);var result = IndentCache[countOfSpaces];if (result == null){Interlocked.CompareExchange(ref IndentCache[countOfSpaces], new string(' ', countOfSpaces), null);result = IndentCache[countOfSpaces];}return result;}private const int DashCacheMax = 120;private static readonly string[] DashCache = new string[DashCacheMax];internal static string DashPadding(int count){if (count >= DashCacheMax)return new string('-', count);var result = DashCache[count];if (result == null){Interlocked.CompareExchange(ref DashCache[count], new string('-', count), null);result = DashCache[count];}return result;}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。