Example #1
0
        // trim(s) and strlen(s) built-in funcs; these are Format options
        public virtual string ToString(object o, string formatString, CultureInfo culture)
        {
            string s = (string)o;

            if (formatString == null)
            {
                return(s);
            }

            if (formatString.Equals("upper"))
            {
                return(culture.TextInfo.ToUpper(s));
            }

            if (formatString.Equals("lower"))
            {
                return(culture.TextInfo.ToLower(s));
            }

            if (formatString.Equals("cap"))
            {
                return(s.Length > 0 ? culture.TextInfo.ToUpper(s[0]) + s.Substring(1) : s);
            }

            if (formatString.Equals("url-encode"))
            {
                return(HttpUtility.UrlEncode(s, Encoding.UTF8));
            }

            if (formatString.Equals("xml-encode"))
            {
#if NETSTANDARD
                return(s.Replace("&", "&")
                       .Replace("<", "&lt;")
                       .Replace(">", "&gt;")
                       .Replace("\"", "&quot;")
                       .Replace("'", "&apos;"));
#else
                return(SecurityElement.Escape(s));
#endif
            }

            return(string.Format(culture, formatString, s));
        }
Example #2
0
        // trim(s) and strlen(s) built-in funcs; these are Format options
        public virtual string ToString(object o, string formatString, CultureInfo culture)
        {
            string s = (string)o;

            if (formatString == null)
            {
                return(s);
            }

            if (formatString.Equals("upper"))
            {
                return(s.ToUpper(culture));
            }

            if (formatString.Equals("lower"))
            {
                return(s.ToLower(culture));
            }

            if (formatString.Equals("cap"))
            {
                return(s.Length > 0 ? char.ToUpper(s[0], culture) + s.Substring(1) : s);
            }

            if (formatString.Equals("url-encode"))
            {
                return(HttpUtility.UrlEncode(s, Encoding.UTF8));
            }

            if (formatString.Equals("xml-encode"))
            {
                return(SecurityElement.Escape(s));
            }

            return(string.Format(culture, formatString, s));
        }