Exemplo n.º 1
0
        /// <summary>Gets the ordinal for a given index.</summary>
        public string GetOrdinal(int index, string name, bool prefixed)
        {
            // Try a core counter system:
            Counters.CounterSystem sys = Counters.CounterSystems.Get(name);

            if (sys != null)
            {
                return(sys.Get(index, prefixed));
            }

            // Get the counter system:
            AtRules.CounterStyleRule rule;
            if (CssCounters != null && CssCounters.TryGetValue(name, out rule))
            {
                // Get the system and return the ordinal:
                return(rule.System.Get(index, prefixed));
            }

            // Not found:
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>Gets the counter text for the given value using this system.</summary>
        /// <param name='prefixed'>True if the prefix/ suffix should be added.</param>
        public string Get(int value, bool prefixed)
        {
            // If the value is out of range, fallback:
            if (value < Min || value > Max)
            {
                // Try fallback:
                if (Fallback == null)
                {
                    return("");
                }

                return(Fallback.Get(value, prefixed));
            }
            else if (AdditionalRanges != null)
            {
                // Must fall in one of them (there won't be many):
                bool inRange = false;

                for (int i = 0; i < AdditionalRanges.Length; i++)
                {
                    CounterRange range = AdditionalRanges[i];

                    if (value >= range.Min && value <= range.Max)
                    {
                        inRange = true;
                        break;
                    }
                }

                if (!inRange)
                {
                    // Try fallback:
                    if (Fallback == null)
                    {
                        return("");
                    }

                    return(Fallback.Get(value, prefixed));
                }
            }

            bool negative = false;

            if (value < 0)
            {
                // Ignore the negative:
                value    = -value;
                negative = true;
            }

            // Get it:
            string result = GetPositive(value);

            if (result == null)
            {
                // Try fallback:
                if (Fallback == null)
                {
                    return("");
                }

                return(Fallback.Get(value, prefixed));
            }

            if (result.Length < PadMin)
            {
                // Pad it:
                for (int i = result.Length; i < PadMin; i++)
                {
                    // Prepend:
                    result = PadSymbol + result;
                }
            }

            if (negative)
            {
                // Add the negative pref/suf:
                result = NegativePrefix + result + NegativeSuffix;
            }

            if (!prefixed)
            {
                // Don't add prefix/ suffix.
                return(result);
            }

            return(Prefix + result + Suffix);
        }