cur() public static method

public static cur ( ) : Locale
return Locale
Example #1
0
        public static String toLocale(long self, string pattern)
        {
            // if pattern is "B" format as bytes
            if (pattern != null && pattern.Length == 1 && pattern[0] == 'B')
            {
                return(toLocaleBytes(self));
            }

            // get current locale
            Locale           locale = Locale.cur();
            NumberFormatInfo df     = locale.dec();

            // get default pattern if necessary
            if (pattern == null)
            {
                pattern = Env.cur().locale(Sys.m_sysPod, "int", "#,###");
            }

            // parse pattern and get digits
            NumPattern p = NumPattern.parse(pattern);
            NumDigits  d = new NumDigits(self);

            // route to common FanNum method
            return(FanNum.toLocale(p, d, df));
        }
Example #2
0
        //////////////////////////////////////////////////////////////////////////
        // Utils
        //////////////////////////////////////////////////////////////////////////

        private Locale locale()
        {
            if (m_locale == null)
            {
                m_locale = Locale.cur();
            }
            return(m_locale);
        }
Example #3
0
        //////////////////////////////////////////////////////////////////////////
        // Locale
        //////////////////////////////////////////////////////////////////////////

        public static long localeCompare(string self, string x)
        {
            int cmp = String.Compare(self, x, true, Locale.cur().dotnet());

            if (cmp < 0)
            {
                return(-1);
            }
            return(cmp == 0 ? 0 : +1);
        }
Example #4
0
        public static string toLocale(double self, string pattern)
        {
            try
            {
                // get current locale
                Locale           locale = Locale.cur();
                NumberFormatInfo df     = locale.dec();

                // handle special values
                if (System.Double.IsNaN(self))
                {
                    return(df.NaNSymbol);
                }
                if (self == System.Double.PositiveInfinity)
                {
                    return(df.PositiveInfinitySymbol);
                }
                if (self == System.Double.NegativeInfinity)
                {
                    return(df.NegativeInfinitySymbol);
                }

                // get default pattern if necessary
                if (pattern == null)
                {
                    pattern = Env.cur().locale(Sys.m_sysPod, "float", "#,###.0##");
                }

                // TODO: if value is < 10^-3 or > 10^7 it will be
                // converted to exponent string, so just bail on that
                string str = Double.toString(self);
                if (str.IndexOf('E') > 0)
                {
                    str = self.ToString("0.#########");
                }

                // parse pattern and get digits
                NumPattern p = NumPattern.parse(pattern);
                NumDigits  d = new NumDigits(str);

                // route to common FanNum method
                return(FanNum.toLocale(p, d, df));
            }
            catch (Exception e)
            {
                Err.dumpStack(e);
                return(self.ToString());
            }
        }
Example #5
0
 public static string localeDecapitalize(string self)
 {
     if (self.Length > 0)
     {
         int ch = self[0];
         if (Char.IsUpper((char)ch))
         {
             StringBuilder s = new StringBuilder(self.Length);
             s.Append(Char.ToLower((char)ch, Locale.cur().dotnet()));
             s.Append(self, 1, self.Length - 1);
             return(s.ToString());
         }
     }
     return(self);
 }
Example #6
0
        public string toLocale(string pattern)
        {
            // locale specific default
            Locale locale = null;

            if (pattern == null)
            {
                if (locale == null)
                {
                    locale = Locale.cur();
                }
                pattern = Env.cur().locale(Sys.m_sysPod, m_localeKey, "D-MMM-YYYY", locale);
            }

            return(new DateTimeStr(pattern, locale, this).format());
        }
Example #7
0
        public static string toLocale(BigDecimal self, string pattern)
        {
            // get current locale
            Locale           locale = Locale.cur();
            NumberFormatInfo df     = locale.dec();

            // get default pattern if necessary
            if (pattern == null)
            {
                pattern = Env.cur().locale(Sys.m_sysPod, "decimal", "#,###.0##");
            }

            // parse pattern and get digits
            NumPattern p = NumPattern.parse(pattern);
            NumDigits  d = new NumDigits(self);

            // route to common FanNum method
            return(FanNum.toLocale(p, d, df));
        }
Example #8
0
        public void _work()
        {
            // set locals for this actor
            m_locals = m_context.m_locals;
            Locale.setCur(m_context.m_locale);

            // process up to 100 messages before yielding the thread
            for (int count = 0; count < 100; count++)
            {
                // get next message, or if none pending we are done
                Future future = null;
                lock (m_lock) { future = m_queue.get(); }
                if (future == null)
                {
                    break;
                }

                // dispatch the messge
                _dispatch(future);
            }

            // flush locals back to context
            m_context.m_locale = Locale.cur();

            // done dispatching, either clear the submitted
            // flag or resubmit to the thread pool
            lock (m_lock)
            {
                if (m_queue.size == 0)
                {
                    m_submitted = false;
                }
                else
                {
                    m_submitted = true;
                    m_pool.submit(this);
                }
            }
        }
Example #9
0
 public static String localePosInf()
 {
     return(Locale.cur().dec().PositiveInfinitySymbol);
 }
Example #10
0
        //////////////////////////////////////////////////////////////////////////
        // Locale
        //////////////////////////////////////////////////////////////////////////

        public string toLocale()
        {
            long          ticks  = this.m_ticks;
            Pod           pod    = Sys.m_sysPod;
            Env           env    = Env.cur();
            Locale        locale = Locale.cur();
            StringBuilder s;

            // less than 1000ns Xns
            if (ticks < 1000L)
            {
                return(ticks + env.locale(pod, "nsAbbr", "ns", locale));
            }

            // less than 2ms X.XXXms
            if (ticks < 2 * nsPerMilli)
            {
                s = new StringBuilder();
                long ms = ticks / nsPerMilli;
                long us = (ticks - ms * nsPerMilli) / 1000L;
                s.Append(ms);
                s.Append('.');
                if (us < 100)
                {
                    s.Append('0');
                }
                if (us < 10)
                {
                    s.Append('0');
                }
                s.Append(us);
                if (s[s.Length - 1] == '0')
                {
                    s.Length = s.Length - 1;
                }
                if (s[s.Length - 1] == '0')
                {
                    s.Length = s.Length - 1;
                }
                s.Append(env.locale(pod, "msAbbr", "ms", locale));
                return(s.ToString());
            }

            // less than 2sec Xms
            if (ticks < 2L * nsPerSec)
            {
                return((ticks / nsPerMilli) + env.locale(pod, "msAbbr", "ms", locale));
            }

            // less than 2min Xsec
            if (ticks < 1L * nsPerMin)
            {
                return((ticks / nsPerSec) + env.locale(pod, "secAbbr", "sec", locale));
            }

            // [Xdays] [Xhr] Xmin Xsec
            long days = ticks / nsPerDay; ticks -= days * nsPerDay;
            long hr   = ticks / nsPerHr;    ticks -= hr * nsPerHr;
            long min  = ticks / nsPerMin;   ticks -= min * nsPerMin;
            long sec  = ticks / nsPerSec;

            s = new StringBuilder();
            if (days > 0)
            {
                s.Append(days).Append(days == 1 ? env.locale(pod, "dayAbbr", "day", locale) : env.locale(pod, "daysAbbr", "days", locale)).Append(" ");
            }
            if (hr > 0)
            {
                s.Append(hr).Append(env.locale(pod, "hourAbbr", "hr", locale)).Append(" ");
            }
            if (min > 0)
            {
                s.Append(min).Append(env.locale(pod, "minAbbr", "min", locale)).Append(" ");
            }
            if (sec > 0)
            {
                s.Append(sec).Append(env.locale(pod, "secAbbr", "sec", locale)).Append(" ");
            }
            s.Length = s.Length - 1;
            return(s.ToString());
        }
Example #11
0
        public static long localeLower(long self)
        {
            long val = self;

            return(Char.ToLower((char)val, Locale.cur().dotnet()));
        }
Example #12
0
 public static string localeUpper(string self)
 {
     return(self.ToUpper(Locale.cur().dotnet()));
 }
Example #13
0
 public virtual string locale(Pod pod, string key, string def)
 {
     return(locale(pod, key, def, Locale.cur()));
 }
Example #14
0
 public static String localeNaN()
 {
     return(Locale.cur().dec().NaNSymbol);
 }
Example #15
0
 public virtual string locale(Pod pod, string key)
 {
     return(locale(pod, key, m_noDef, Locale.cur()));
 }
Example #16
0
 public static String localeNegInf()
 {
     return(Locale.cur().dec().NegativeInfinitySymbol);
 }
Example #17
0
        //////////////////////////////////////////////////////////////////////////
        // Locale
        //////////////////////////////////////////////////////////////////////////

        public static string localeDecimal()
        {
            return(Locale.cur().dec().NumberDecimalSeparator);
        }
Example #18
0
 public static string localePercent()
 {
     return(Locale.cur().dec().PercentSymbol);
 }
Example #19
0
 public static string localeMinus()
 {
     return(Locale.cur().dec().NegativeSign);
 }
Example #20
0
 public static string localeGrouping()
 {
     return(Locale.cur().dec().NumberGroupSeparator);
 }