コード例 #1
0
        private static IEnumerable <GetWordsResult> GetWords(string s)
        {
            StringBuilder  iteratorVariable0 = new StringBuilder();
            GetWordsResult iteratorVariable1 = new GetWordsResult();

            for (int i = 0; i < s.Length; i++)
            {
                if (((s[i] == ' ') || (s[i] == '\t')) || (s[i] == SoftHyphen))
                {
                    iteratorVariable1.Word = iteratorVariable0.ToString();
                    iteratorVariable0.Clear();
                    iteratorVariable1.Delim = new string(s[i], 1);
                    yield return(iteratorVariable1);
                }
                else if ((s[i] == HardHyphen) || (s[i] == NonBreakingSpace))
                {
                    iteratorVariable1.Word = iteratorVariable0.ToString();
                    iteratorVariable0.Clear();
                    iteratorVariable1.Delim = string.Empty;
                    yield return(iteratorVariable1);
                }
                else
                {
                    iteratorVariable0.Append(s[i]);
                }
            }
            iteratorVariable1.Word  = iteratorVariable0.ToString();
            iteratorVariable1.Delim = string.Empty;
            yield return(iteratorVariable1);
        }
コード例 #2
0
ファイル: ComplexWriter.cs プロジェクト: powercode/PowerShell
        /// <summary>
        /// Breaks a string into a collection of words
        /// TODO: we might be able to improve this function in the future
        /// so that we do not break paths etc.
        /// </summary>
        /// <param name="s">Input string.</param>
        /// <returns>A collection of words.</returns>
        private static IEnumerable <GetWordsResult> GetWords(string s)
        {
            StringBuilder  sb     = new StringBuilder();
            GetWordsResult result = new GetWordsResult();

            for (int i = 0; i < s.Length; i++)
            {
                // Soft hyphen = \u00AD - Should break, and add a hyphen if needed. If not needed for a break, hyphen should be absent
                if (s[i] == ' ' || s[i] == '\t' || s[i] == s_softHyphen)
                {
                    result.Word = sb.ToString();
                    sb.Clear();
                    result.Delim = new string(s[i], 1);

                    yield return(result);
                }
                // Non-breaking space = \u00A0 - ideally shouldn't wrap
                // Hard hyphen = \u2011 - Should not break
                else if (s[i] == s_hardHyphen || s[i] == s_nonBreakingSpace)
                {
                    result.Word = sb.ToString();
                    sb.Clear();
                    result.Delim = string.Empty;

                    yield return(result);
                }
                else
                {
                    sb.Append(s[i]);
                }
            }

            result.Word  = sb.ToString();
            result.Delim = string.Empty;

            yield return(result);
        }
コード例 #3
0
 private static IEnumerable<GetWordsResult> GetWords(string s)
 {
     StringBuilder iteratorVariable0 = new StringBuilder();
     GetWordsResult iteratorVariable1 = new GetWordsResult();
     for (int i = 0; i < s.Length; i++)
     {
         if (((s[i] == ' ') || (s[i] == '\t')) || (s[i] == SoftHyphen))
         {
             iteratorVariable1.Word = iteratorVariable0.ToString();
             iteratorVariable0.Clear();
             iteratorVariable1.Delim = new string(s[i], 1);
             yield return iteratorVariable1;
         }
         else if ((s[i] == HardHyphen) || (s[i] == NonBreakingSpace))
         {
             iteratorVariable1.Word = iteratorVariable0.ToString();
             iteratorVariable0.Clear();
             iteratorVariable1.Delim = string.Empty;
             yield return iteratorVariable1;
         }
         else
         {
             iteratorVariable0.Append(s[i]);
         }
     }
     iteratorVariable1.Word = iteratorVariable0.ToString();
     iteratorVariable1.Delim = string.Empty;
     yield return iteratorVariable1;
 }
コード例 #4
0
ファイル: ComplexWriter.cs プロジェクト: sdwheeler/PowerShell
        /// <summary>
        /// Breaks a string into a collection of words
        /// TODO: we might be able to improve this function in the future
        /// so that we do not break paths etc.
        /// </summary>
        /// <param name="s">Input string.</param>
        /// <returns>A collection of words.</returns>
        private static IEnumerable <GetWordsResult> GetWords(string s)
        {
            StringBuilder         sb       = new StringBuilder();
            StringBuilder         vtSeqs   = null;
            Dictionary <int, int> vtRanges = null;

            var valueStrDec = new ValueStringDecorated(s);

            if (valueStrDec.IsDecorated)
            {
                vtSeqs   = new StringBuilder();
                vtRanges = valueStrDec.EscapeSequenceRanges;
            }

            bool wordHasVtSeqs = false;

            for (int i = 0; i < s.Length; i++)
            {
                if (vtRanges?.TryGetValue(i, out int len) == true)
                {
                    var vtSpan = s.AsSpan(i, len);
                    sb.Append(vtSpan);
                    vtSeqs.Append(vtSpan);

                    wordHasVtSeqs = true;
                    i            += len - 1;
                    continue;
                }

                string delimiter = null;
                if (s[i] == ' ' || s[i] == '\t' || s[i] == s_softHyphen)
                {
                    // Soft hyphen = \u00AD - Should break, and add a hyphen if needed.
                    // If not needed for a break, hyphen should be absent.
                    delimiter = new string(s[i], 1);
                }
                else if (s[i] == s_hardHyphen || s[i] == s_nonBreakingSpace)
                {
                    // Non-breaking space = \u00A0 - ideally shouldn't wrap.
                    // Hard hyphen = \u2011 - Should not break.
                    delimiter = string.Empty;
                }

                if (delimiter is not null)
                {
                    if (wordHasVtSeqs && !sb.EndsWith(PSStyle.Instance.Reset))
                    {
                        sb.Append(PSStyle.Instance.Reset);
                    }

                    var result = new GetWordsResult()
                    {
                        Word  = sb.ToString(),
                        Delim = delimiter
                    };

                    sb.Clear().Append(vtSeqs);
                    yield return(result);
                }
                else
                {
                    sb.Append(s[i]);
                }
            }

            if (wordHasVtSeqs)
            {
                if (sb.Length == vtSeqs.Length)
                {
                    // This indicates 'sb' only contains all VT sequences, which may happen when the string ends with a word delimiter.
                    // For a word that contains VT sequence only, it's the same as an empty string to the formatting system,
                    // because nothing will actually be rendered.
                    // So, we use an empty string in this case to avoid unneeded string allocations.
                    sb.Clear();
                }
                else if (!sb.EndsWith(PSStyle.Instance.Reset))
                {
                    sb.Append(PSStyle.Instance.Reset);
                }
            }

            yield return(new GetWordsResult()
            {
                Word = sb.ToString(), Delim = string.Empty
            });
        }
コード例 #5
0
ファイル: ComplexWriter.cs プロジェクト: dfinke/powershell
        /// <summary>
        /// Breaks a string into a collection of words
        /// TODO: we might be able to improve this function in the future
        /// so that we do not break paths etc.
        /// </summary>
        /// <param name="s">input string</param>
        /// <returns>a collection of words</returns>
        private static IEnumerable<GetWordsResult> GetWords(string s)
        {
            StringBuilder sb = new StringBuilder();
            GetWordsResult result = new GetWordsResult();

            for (int i = 0; i < s.Length; i++)
            {
                // Soft hyphen = \u00AD - Should break, and add a hyphen if needed. If not needed for a break, hyphen should be absent
                if (s[i] == ' ' || s[i] == '\t' || s[i] == s_softHyphen)
                {
                    result.Word = sb.ToString();
                    sb.Clear();
                    result.Delim = new String(s[i], 1);

                    yield return result;
                }
                // Non-breaking space = \u00A0 - ideally shouldn't wrap
                // Hard hyphen = \u2011 - Should not break
                else if (s[i] == s_hardHyphen || s[i] == s_nonBreakingSpace)
                {
                    result.Word = sb.ToString();
                    sb.Clear();
                    result.Delim = String.Empty;

                    yield return result;
                }
                else
                {
                    sb.Append(s[i]);
                }
            }

            result.Word = sb.ToString();
            result.Delim = String.Empty;

            yield return result;
        }