public static string Format(string text, ETextFormat format)
        {
            if (string.IsNullOrEmpty(text) || format == 0)
            {
                return(text);
            }
            var buf = GetBuilder(text);

            Format(buf, format);
            return(ReleaseBuilder(buf));
        }
Ejemplo n.º 2
0
        internal string _hlnk => _d + @"Hlnk\s*\(.+?\)" + _d;   //Function "Hyperlink"

        #endregion

        internal Parser(ETextFormat format, string delimiter = "#", bool preprocessText = true)
        {
            _preprocessText = preprocessText;
            _d          = delimiter;
            TextFormat  = format;
            DataManager = new DataManager(this);

            KeywordsRegExString = @"\b*(" + _scan + "|"
                                  + _endscan + "|"
                                  + _scanfor + "|"
                                  + _if + "|"
                                  + _else + "|"
                                  + _endif +
                                  ")\\b*";

            FunctionsRegexString = @"\b*(" + _dtfmt + "|" + _dbfmt + "|" + _hlnk + ")\\b*";
        }
        public static void Format(StringBuilder buf, ETextFormat format)
        {
            switch (format)
            {
            case ETextFormat.Lower:
                for (int i = 0; i < buf.Length; i++)
                {
                    buf[i] = ToLower(buf[i]);
                }
                break;

            case ETextFormat.Upper:
                for (int i = 0; i < buf.Length; i++)
                {
                    buf[i] = ToUpper(buf[i]);
                }
                break;

            case ETextFormat.FirstUpper:
                if (buf.Length > 0)
                {
                    buf[0] = ToUpper(buf[0]);
                }
                break;

            case ETextFormat.EachFirstUpper:
                bool trans = true;
                for (int i = 0; i < buf.Length; i++)
                {
                    var c = buf[i];
                    if (c == ' ' || c == '\t' || c == '\n')
                    {
                        trans = true;
                    }
                    else if (trans)
                    {
                        buf[i] = ToUpper(c);
                        trans  = false;
                    }
                }
                break;

            default:
                break;
            }
        }