Beispiel #1
0
		// Turns the ustring into runes, this does not split the 
		// contents on a newline if it is present.
		internal static List<Rune> ToRunes (ustring str)
		{
			List<Rune> runes = new List<Rune> ();
			foreach (var x in str.ToRunes ()) {
				runes.Add (x);
			}
			return runes;
		}
Beispiel #2
0
        static ustring StripCRLF(ustring str)
        {
            var runes = new List <Rune> ();

            foreach (var r in str.ToRunes())
            {
                if (r != '\r' && r != '\n')
                {
                    runes.Add(r);
                }
            }
            return(ustring.Make(runes));;
        }
Beispiel #3
0
        static ustring ClipAndJustify(ustring str, int width, TextAlignment talign)
        {
            // Get rid of any '\r' added by Windows
            str = str.Replace("\r", ustring.Empty);
            int slen = str.RuneCount;

            if (slen > width)
            {
                var uints = str.ToRunes(width);
                var runes = new Rune [uints.Length];
                for (int i = 0; i < uints.Length; i++)
                {
                    runes [i] = uints [i];
                }
                return(ustring.Make(runes));
            }
            else
            {
                if (talign == TextAlignment.Justified)
                {
                    // TODO: ustring needs this
                    var words     = str.ToString().Split(whitespace, StringSplitOptions.RemoveEmptyEntries);
                    int textCount = words.Sum(arg => arg.Length);

                    var spaces = (width - textCount) / (words.Length - 1);
                    var extras = (width - textCount) % words.Length;

                    var s = new System.Text.StringBuilder();
                    //s.Append ($"tc={textCount} sp={spaces},x={extras} - ");
                    for (int w = 0; w < words.Length; w++)
                    {
                        var x = words [w];
                        s.Append(x);
                        if (w + 1 < words.Length)
                        {
                            for (int i = 0; i < spaces; i++)
                            {
                                s.Append(' ');
                            }
                        }
                        if (extras > 0)
                        {
                            //s.Append ('_');
                            extras--;
                        }
                    }
                    return(ustring.Make(s.ToString()));
                }
                return(str);
            }
        }
Beispiel #4
0
        static ustring ReplaceCRLFWithSpace(ustring str)
        {
            var runes = new List <Rune> ();

            foreach (var r in str.ToRunes())
            {
                if (r == '\r' || r == '\n')
                {
                    runes.Add(new Rune(' '));                       // r + 0x2400));         // U+25A1 □ WHITE SQUARE
                }
                else
                {
                    runes.Add(r);
                }
            }
            return(ustring.Make(runes));;
        }
Beispiel #5
0
        static ustring ReplaceNonPrintables(ustring str)
        {
            var runes = new List <Rune> ();

            foreach (var r in str.ToRunes())
            {
                if (r < 0x20)
                {
                    runes.Add(new Rune(r + 0x2400));                               // U+25A1 □ WHITE SQUARE
                }
                else
                {
                    runes.Add(r);
                }
            }
            return(ustring.Make(runes));;
        }