<commit_before>////////////////////////////////////////////////////////////////////////////////
//
//  ADOBE SYSTEMS INCORPORATED
//  Copyright 2010 Adobe Systems Incorporated
//  All Rights Reserved.
//
//  NOTICE: Adobe permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package spark.formatters
{

import flash.globalization.CurrencyFormatter;
import flash.globalization.CurrencyParseResult;
import flash.globalization.NationalDigitsType;

import mx.core.mx_internal;
import mx.formatters.IFormatter;

import spark.formatters.supportClasses.NumberFormatterBase;
import spark.globalization.LastOperationStatus;
import mx.resources.ResourceManager;
import mx.resources.IResourceManager;

use namespace mx_internal;

[ResourceBundle("core")]

/**
 *  The CurrencyFormatter class provides locale-sensitive formatting
 *  and parsing of currency values. 
 *
 *  <p>This class is a wrapper class around the
 *  <code>flash.globalization.CurrencyFormatter</code>. Therefore,
 *  the locale-specific formatting
 *  is provided by the <code>flash.globalization.CurrencyFormatter</code>.
 *  However, this CurrencyFormatter class can be used in MXML declarations,
 *  uses the locale style for the requested Locale ID name, and has
 *  methods and properties that are bindable.
 *  </p><p>
 *  The flash.globalization.CurrencyFormatter class uses the underlying
 *  operating system for the formatting functionality and
 *  to supply the locale specific data. On some operating systems,
 *  the flash.globalization classes are unsupported, on these systems this
 *  wrapper class provides fallback functionality.
 *  </p>
 *
 *  @mxml <p>The <code>&lt;s:CurrencyFormatter&gt;</code> tag inherits all of the tag 
 *  attributes of its superclass and adds the following tag attributes:</p>
 *
 *  <pre>
 *  &lt;s:CurrencyFormatter 
 *    <strong>Properties</strong>
 *    currencyISOCode="<i>locale and OS dependent</i>"
 *    currencySymbol="<i>locale and OS dependent</i>"
 *    negativeCurrencyFormat="<i>locale and OS dependent</i>"
 *    positiveCurrencyFormat="<i>locale and OS dependent</i>"
 *    useCurrencySymbol="false"
 *  /&gt;
 *  </pre>
 *
 *  @includeExample examples/CurrencyFormatterExample1.mxml
 *  @includeExample examples/CurrencyFormatterExample2.mxml
 *
 *  @see flash.globalization.CurrencyFormatter
 *  @see NumberFormatter
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.1
 *  @playerversion AIR 2.5
 *  @productversion Flex 4.5
 */
public class CurrencyFormatter extends NumberFormatterBase implements IFormatter
{
    include "../core/Version.as";

    //--------------------------------------------------------------------------
    //
    //  Class Constants
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    private static const CURRENCY_ISOCODE:String = "currencyISOCode";
    private static const CURRENCY_SYMBOL:String = "currencySymbol";
    private static const NEGATIVE_CURRENCY_FORMAT:String
                                                    = "negativeCurrencyFormat";
    private static const POSITIVE_CURRENCY_FORMAT:String
                                                    = "positiveCurrencyFormat";

    //--------------------------------------------------------------------------
    //
    //  Constructor
    //
    //--------------------------------------------------------------------------

    /**
     *  Constructs a new <code>CurrencyFormatter</code> object to format numbers
     *  representing currency amounts according to
     *  the conventions of a given locale.
     *  <p>
     *  The locale for this class is supplied by the <code>locale</code> style. The
     *  <code>locale</code> style can be set in several ways:
     *  </p>
     *  <ul>
     *  <li>
     *  By using the class in an MXML declaration and inheriting the
     *  locale from the document that contains the declaration.
     *  </li>
     *  Example:
     *  <pre>
     *  &lt;fx:Declarations&gt; <br>
     *         &lt;s:CurrencyFormatter id="cf" /&gt; <br>
     *  &lt;/fx:Declarations&gt;
     *  </pre>
     *  <li>
     *  By using an MXML declaration and specifying the locale value
     *  in the list of assignments.
     *  </li>
     *  Example:
     *  <pre>
     *  &lt;fx:Declarations&gt; <br>
     *      &lt;s:CurrencyFormatter id="cf_Japanese" locale="ja-JP" /&gt; <br>
     *  &lt;/fx:Declarations&gt;
     *  </pre>
     *  <li>
     *  Calling the <code>setStyle()</code> method,
     *  e.g. <code>cf.setStyle("locale", "ja-JP")</code>
     *  </li>
     *  <li> 
     *  Inheriting the style from a <code>UIComponent</code> by calling the
     *  UIComponent's <code>addStyleClient()</code> method.
     *  </li>
     *  </ul>
     *  <p>
     *  If the <code>locale</code> style is not set by one of the above 
     *  techniques, the instance of this class will be added as a 
     *  <code>StyleClient</code> to the <code>topLevelApplication</code> and 
     *  will therefore inherit the <code>locale</code> style from the 
     *  <code>topLevelApplication</code> object when the <code>locale</code> 
     *  dependent property getter or <code>locale</code> dependent method is 
     *  called.
     *  </p>   
     * 
     *  <p>Most of the properties of 
     *  this class are automatically set based on the <code>locale</code> style.
     *  If the <code>locale</code> style is changed, any properties that have 
     *  not been explicitly set will also be updated based on the new locale. 
     *  Note that the actual locale that is used is specified by the 
     *  <code>actualLocaleIDName</code> property.</p>
     *
     *  <p><strong>NOTE: When a fallback locale is used, the currency
     *  properties are set to default values,
     *  and therefore the <code>currencySymbol</code> or
     *  <code>currencyISOCode</code> properties might be given unexpected
     *  values. It is a good idea to examine the
     *  <code>currencySymbol</code> and <code>currencyISOCode</code>
     *  property values before formatting a currency amount.
     *  </strong></p>
     *
     *  @see #actualLocaleIDName
     *  @see #lastOperationsStatus
     * 
     *  @langversion 3.0
     *  @playerversion Flash 10.1
     *  @playerversion AIR 2.5
     *  @productversion Flex 4.5
     */
    public function CurrencyFormatter()
    {
        super();
    }

    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    private var resourceManager:IResourceManager =
        ResourceManager.getInstance();
    
    /**
     *  @private
     */
    private var currencySymbolOverride:String = null;

    /**
     *  @private
     */
    private var currencyISOCodeOverride:String = null;

    //--------------------------------------------------------------------------
    //
    //  Overridden Properties
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  actualLocaleIDName
    //----------------------------------

    [Bindable("change")]

    /**
     *  @inheritDoc
     *
     *  @see flash.globalization.CurrencyFormatter#actualLocaleIDName
     *  @see #CurrencyFormatter()
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.1
     *  @playerversion AIR 2.5
     *  @productversion Flex 4.5
     */
    override public function get actualLocaleIDName():String
    {
        if (g11nWorkingInstance)
            return (g11nWorkingInstance
                as flash.globalization.CurrencyFormatter).actualLocaleIDName;

        if ((localeStyle === undefined) || (localeStyle === null))
        {
            fallbackLastOperationStatus
                                = LastOperationStatus.LOCALE_UNDEFINED_ERROR;
            return undefined;
        }

        fallbackLastOperationStatus = LastOperationStatus.NO_ERROR;

        return "en-US";
    }

    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  currencyISOCode
    //----------------------------------

    [Bindable("change")]

    /**
     *  The three letter ISO 4217 currency code for the actual locale
     *  being used (e.g. USD, EUR, JPY, CNY).
     *
     *  <p>When the <code>useCurrencySymbol</code> property is set to
     *  <code>false</code>, this code will be used to indicate the currency
     *  type when formatting currency amounts
     *  using the <code>format()</code> method. </p>
     *
     *  <p>This property is initialized when the locale style is set
     *  based on the actual locale that is used. When a fallback
     *  locale is used, this property reflects the preferred/default
     *  currency code for the fallback locale.</p>
     * 
     *  <p>The default value is dependent on the actual locale and operating 
     *  system.</p>
     *
     *  @throws TypeError if this property is assigned a null value. 
     *
     *  @see #actualLocaleIDName
     *  @see #format()
     *  @see #currencySymbol
     *  @see #formattingWithCurrencySymbolIsSafe()
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.1
     *  @playerversion AIR 2.5
     *  @productversion Flex 4.5
     */
    public function get currencyISOCode():String
    {
        if (g11nWorkingInstance)
            return g11nWorkingInstance.currencyISOCode;

        if ((localeStyle === undefined) || (localeStyle === null))
        {
            fallbackLastOperationStatus
                                = LastOperationStatus.LOCALE_UNDEFINED_ERROR;
            return undefined;
        }

        return properties.currencyISOCode;
    }

    public function set currencyISOCode(value:String):void
    {
        if (currencyISOCodeOverride && (currencyISOCodeOverride == value))
            return;

        currencyISOCodeOverride = value;

        if (g11nWorkingInstance)
        {
            g11nWorkingInstance.setCurrency(
                                    value, g11nWorkingInstance.currencySymbol);
        }
        else
        {
            if (!value)
            {
                const message:String = 
                    resourceManager.getString("core","nullParameter", 
                        [ currencyISOCode ]);
                throw new TypeError(message);
            }

            if (properties)
                properties.currencyISOCode = value;
            fallbackLastOperationStatus = LastOperationStatus.NO_ERROR;
        }

        update();
    }

    //----------------------------------
    //  currencySymbol
    //----------------------------------

    [Bindable("change")]

    /**
     *  The currency symbol or string for the actual locale being used.
     *
     *  <p>This property is used as the currency symbol when formatting
     *  currency amounts using the <code>format()</code> method with
     *  the <code>withCurrencySymbol</code> parameter set to
     *  <code>true</code>.</p>
     *
     *  <p>This property is initialized when the locale style is set based on
     *  the actual locale that is used. When a fallback
     *  locale is used, this property reflects the preferred/default
     *  currency symbol for the fallback locale which may be different
     *  then the locale style.</p>
     * 
     *  <p>The default value is dependent on the actual locale and operating 
     *  system.</p>
     *
     *  @throws TypeError if this property is assigned a null value. 
     *
     *  @see #actualLocaleIDName
     *  @see #format()
     *  @see #formattingWithCurrencySymbolIsSafe()
     *  @see #currencyISOCode
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.1
     *  @playerversion AIR 2.5
     *  @productversion Flex 4.5
     */
    public function get currencySymbol():String
    {
        if (g11nWorkingInstance)
            return g11nWorkingInstance.currencySymbol;

        if ((localeStyle === undefined) || (localeStyle === null))
        {
            fallbackLastOperationStatus
                                  = LastOperationStatus.LOCALE_UNDEFINED_ERROR;
            return undefined;
        }

        return properties.currencySymbol;
    }

    public function set currencySymbol(value:String):void
    {
        if (currencySymbolOverride && (currencySymbolOverride == value))
            return;

        currencySymbolOverride = value;

        if (g11nWorkingInstance)
        {
            g11nWorkingInstance.setCurrency(
                                g11nWorkingInstance.currencyISOCode, value);
        }
        else
        {
            if (!value)
            {
                const message:String = 
                    resourceManager.getString("core","nullParameter", 
                        [ currencySymbol ]);
                throw new TypeError(message);
            }

            if (properties)
                properties.currencySymbol = value;
            fallbackLastOperationStatus = LastOperationStatus.NO_ERROR;
        }

        update();
    }

    //----------------------------------
    //  negativeCurrencyFormat
    //----------------------------------

    [Bindable("change")]
    [Inspectable(category="General",
                        enumeration="0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15")]

    /**
     *  A numeric value that indicates a formatting pattern for negative
     *  currency amounts. This pattern defines the location of the
     *  currency symbol and the negative symbol or parentheses in
     *  relation to the numeric portion of the currency
     *  amount.
     *
     *   <p>The value of this property must be one of the constants
     *  defined in the table below.
     *  </p>
     *
     *  <p>The table below summarizes the possible formatting patterns
     *  for negative currency amounts. When a currency amount is formatted
     *  with the <code>format()</code> method:</p>
     *
     *  <ul>
     *   <li>The '&#164;' symbol is replaced with the value of the
     *       <code>currencyISOCode</code> or
     *       the <code>currencySymbol</code> property, depending on
     *       the value of the <code>withCurrencySymbol</code> parameter
     *       passed to the <code>format()</code> method;</li>
     *   <li>The '-' character is replaced with the value of the
     *       <code>negativeNumberSymbol</code> property;</li>
     *   <li>The 'n' character is replaced with the currency amount
     *       value that is passed to the <code>format()</code> method.</li>
     *  </ul>
     *
     *    <table class="innertable" border="0">
     *        <tr>
     *            <td>Negative currency format type</td>
     *            <td>Formatting pattern</td>
     *        </tr>
     *        <tr>
     *            <td>0</td>
     *            <td>(&#164;n)</td>
     *        </tr>
     *        <tr>
     *            <td>1</td>
     *            <td>-&#164;n</td>
     *        </tr>
     *        <tr>
     *            <td>2</td>
     *            <td>&#164;-n</td>
     *        </tr>
     *        <tr>
     *            <td>3</td>
     *            <td>&#164;n-</td>
     *        </tr>
     *        <tr>
     *            <td>4</td>
     *            <td>(n&#164;)</td>
     *        </tr>
     *        <tr>
     *            <td>5</td>
     *            <td>-n&#164;</td>
     *        </tr>
     *        <tr>
     *            <td>6</td>
     *            <td>n-&#164;</td>
     *        </tr>
     *        <tr>
     *            <td>7</td>
     *            <td>n&#164;-</td>
     *        </tr>
     *        <tr>
     *            <td>8</td>
     *            <td>-n &#164;</td>
     *        </tr>
     *        <tr>
     *            <td>9</td>
     *            <td>-&#164; n</td>
     *        </tr>
     *        <tr>
     *            <td>10</td>
     *            <td>n &#164;-</td>
     *        </tr>
     *        <tr>
     *            <td>11</td>
     *            <td>&#164; n-</td>
     *        </tr>
     *        <tr>
     *            <td>12</td>
     *            <td>&#164; -n</td>
     *        </tr>
     *        <tr>
     *            <td>13</td>
     *            <td>n- &#164;</td>
     *        </tr>
     *        <tr>
     *            <td>14</td>
     *            <td>(&#164; n)</td>
     *        </tr>
     *        <tr>
     *            <td>15</td>
     *            <td>(n &#164;)</td>
     *        </tr>
     *    </table>
     * 
     *  <p>The default value is dependent on the actual locale and operating 
     *  system.</p>
     *
     *  @throws ArgumentError if the assigned value is not between 0 and 15.
     * 
     *  @see #format()
     *  @see #currencySymbol
     *  @see #negativeSymbol
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.1
     *  @playerversion AIR 2.5
     *  @productversion Flex 4.5
     */
    public function get negativeCurrencyFormat():uint
    {
        return getBasicProperty(properties, NEGATIVE_CURRENCY_FORMAT);
    }

    public function set negativeCurrencyFormat(value:uint):void
    {
        if (!g11nWorkingInstance)
        {
            if ((value < 0) || (15 < value))
            {
                const message:String = 
                    resourceManager.getString("core","badIndex");
                throw new ArgumentError(message);
            }
        }

        setBasicProperty(properties, NEGATIVE_CURRENCY_FORMAT, value);
    }

    //----------------------------------
    //  positiveCurrencyFormat
    //----------------------------------

    [Bindable("change")]
    [Inspectable(category="General", enumeration="0,1,2,3")]

    /**
     *  A numeric value that indicates a formatting pattern for positive
     *  currency amounts. This format defines the location of the currency
     *  symbol relative to the numeric portion of the currency amount.
     *
     *  <p>The value of this property must be one of the constants
     *  defined in the table below.
     *  </p>
     *
     *  <p>The table below summarizes the possible formatting patterns
     *  for positive currency amounts.
     *  When a currency amount is formatted with the <code>format()</code>
     *  method:</p>
     *
     *  <ul>
     *   <li>The '&#164;' symbol is replaced with the value of the
     *       <code>currencyISOCode</code> or
     *       the <code>currencySymbol</code> property, depending on the
     *       value of the <code>withCurrencySymbol</code> parameter
     *       passed to the <code>format()</code> method;</li>
     *   <li>The 'n' character is replaced with the currency amount value
     *       that is passed to the <code>format()</code> method.</li>
     *  </ul>
     *
     *    <table class="innertable" border="0">
     *        <tr>
     *            <td>Positive currency format type</td>
     *            <td>Formatting pattern</td>
     *        </tr>
     *        <tr>
     *            <td>0</td>
     *            <td>&#164;n</td>
     *        </tr>
     *        <tr>
     *            <td>1</td>
     *            <td>n&#164;</td>
     *        </tr>
     *        <tr>
     *            <td>2</td>
     *            <td>&#164; n</td>
     *        </tr>
     *        <tr>
     *            <td>3</td>
     *            <td>n &#164;</td>
     *        </tr>
     *    </table>
     *
     *  <p>The default value is dependent on the actual locale and operating 
     *  system.</p>
     *
     *  @throws ArgumentError if the assigned value is not between 0 and 3.
     *
     *  @see #currencySymbol
     *  @see #format()
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.1
     *  @playerversion AIR 2.5
     *  @productversion Flex 4.5
     */
    public function get positiveCurrencyFormat():uint
    {
        return getBasicProperty(properties, POSITIVE_CURRENCY_FORMAT);
    }

    public function set positiveCurrencyFormat(value:uint):void
    {
        if (!g11nWorkingInstance)
        {
            if ((value < 0) || (4 < value))
            {
                const message:String = 
                    resourceManager.getString("core","badIndex");
                throw new ArgumentError(message);
            }
        }

        setBasicProperty(properties, POSITIVE_CURRENCY_FORMAT, value);
    }

    //----------------------------------
    //  useCurrencySymbol
    //----------------------------------

    /**
     *  @private
     */
    private var _useCurrencySymbol:Boolean = false;

    [Bindable("change")]

    /**
     *  Enables the use of the currencySymbol when formatting
     *  currency amounts.
     *
     *  <p>When the <code>withCurrencySymbol</code> property is
     *  set to <code>true</code>, the value of the
     *  <code>currencySymbol</code> property is used
     *  in the string returned by the format method.
     *  For example: <code>$ 123,456,789.22</code></p>
     *
     *  <p>When the <code>withCurrencySymbol</code> property is set to
     *  <code>false</code>, the value of the <code>currencyISOCode</code>
     *  property is used in the string returned by the <code>format</code>
     *  method. For example: <code>USD 123,456,789.22</code></p>
     *<commit_msg>Transferred from the Adobe Open Source Subversion Repository<commit_after>////////////////////////////////////////////////////////////////////////////////
//
//  ADOBE SYSTEMS INCORPORATED
//  Copyright 2010 Adobe Systems Incorporated
//  All Rights Reserved.
//
//  NOTICE: Adobe permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package spark.formatters
{

import flash.globalization.CurrencyFormatter;
import flash.globalization.CurrencyParseResult;
import flash.globalization.NationalDigitsType;

import mx.core.mx_internal;
import mx.formatters.IFormatter;

import spark.formatters.supportClasses.NumberFormatterBase;
import spark.globalization.LastOperationStatus;
import mx.resources.ResourceManager;
import mx.resources.IResourceManager;

use namespace mx_internal;

[ResourceBundle("core")]

/**
 *  The CurrencyFormatter class provides locale-sensitive formatting
 *  and parsing of currency values. 
 *
 *  <p>This class is a wrapper class around the
 *  <code>flash.globalization.CurrencyFormatter</code>. Therefore,
 *  the locale-specific formatting
 *  is provided by the <code>flash.globalization.CurrencyFormatter</code>.
 *  However, this CurrencyFormatter class can be used in MXML declarations,
 *  uses the locale style for the requested Locale ID name, and has
 *  methods and properties that are bindable.
 *  </p><p>
 *  The flash.globalization.CurrencyFormatter class uses the underlying
 *  operating system for the formatting functionality and
 *  to supply the locale specific data. On some operating systems,
 *  the flash.globalization classes are unsupported, on these systems this
 *  wrapper class provides fallback functionality.
 *  </p>
 *
 *  @mxml <p>The <code>&lt;s:CurrencyFormatter&gt;</code> tag inherits all of the tag 
 *  attributes of its superclass and adds the following tag attributes:</p>
 *
 *  <pre>
 *  &lt;s:CurrencyFormatter 
 *    <strong>Properties</strong>
 *    currencyISOCode="<i>locale and OS dependent</i>"
 *    currencySymbol="<i>locale and OS dependent</i>"
 *    negativeCurrencyFormat="<i>locale and OS dependent</i>"
 *    positiveCurrencyFormat="<i>locale and OS dependent</i>"
 *    useCurrencySymbol="false"
 *  /&gt;
 *  </pre>
 *
 *  @includeExample examples/CurrencyFormatterExample1.mxml
 *  @includeExample examples/CurrencyFormatterExample2.mxml
 *
 *  @see flash.globalization.CurrencyFormatter
 *  @see NumberFormatter
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.1
 *  @playerversion AIR 2.5
 *  @productversion Flex 4.5
 */
public class CurrencyFormatter extends NumberFormatterBase implements IFormatter
{
    include "../core/Version.as";

    //--------------------------------------------------------------------------
    //
    //  Class Constants
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    private static const CURRENCY_ISOCODE:String = "currencyISOCode";
    private static const CURRENCY_SYMBOL:String = "currencySymbol";
    private static const NEGATIVE_CURRENCY_FORMAT:String
                                                    = "negativeCurrencyFormat";
    private static const POSITIVE_CURRENCY_FORMAT:String
                                                    = "positiveCurrencyFormat";

    //--------------------------------------------------------------------------
    //
    //  Constructor
    //
    //--------------------------------------------------------------------------

    /**
     *  Constructs a new <code>CurrencyFormatter</code> object to format numbers
     *  representing currency amounts according to
     *  the conventions of a given locale.
     *  <p>
     *  The locale for this class is supplied by the <code>locale</code> style. The
     *  <code>locale</code> style can be set in several ways:
     *  </p>
     *  <ul>
     *  <li>
     *  By using the class in an MXML declaration and inheriting the
     *  locale from the document that contains the declaration.
     *  </li>
     *  Example:
     *  <pre>
     *  &lt;fx:Declarations&gt; <br>
     *         &lt;s:CurrencyFormatter id="cf" /&gt; <br>
     *  &lt;/fx:Declarations&gt;
     *  </pre>
     *  <li>
     *  By using an MXML declaration and specifying the locale value
     *  in the list of assignments.
     *  </li>
     *  Example:
     *  <pre>
     *  &lt;fx:Declarations&gt; <br>
     *      &lt;s:CurrencyFormatter id="cf_Japanese" locale="ja-JP" /&gt; <br>
     *  &lt;/fx:Declarations&gt;
     *  </pre>
     *  <li>
     *  Calling the <code>setStyle()</code> method,
     *  e.g. <code>cf.setStyle("locale", "ja-JP")</code>
     *  </li>
     *  <li> 
     *  Inheriting the style from a <code>UIComponent</code> by calling the
     *  UIComponent's <code>addStyleClient()</code> method.
     *  </li>
     *  </ul>
     *  <p>
     *  If the <code>locale</code> style is not set by one of the above 
     *  techniques, the instance of this class will be added as a 
     *  <code>StyleClient</code> to the <code>topLevelApplication</code> and 
     *  will therefore inherit the <code>locale</code> style from the 
     *  <code>topLevelApplication</code> object when the <code>locale</code> 
     *  dependent property getter or <code>locale</code> dependent method is 
     *  called.
     *  </p>   
     * 
     *  <p>Most of the properties of 
     *  this class are automatically set based on the <code>locale</code> style.
     *  If the <code>locale</code> style is changed, any properties that have 
     *  not been explicitly set will also be updated based on the new locale. 
     *  Note that the actual locale that is used is specified by the 
     *  <code>actualLocaleIDName</code> property.</p>
     *
     *  <p><strong>NOTE:</strong> When a fallback locale is used, the currency
     *  properties are set to default values,
     *  and therefore the <code>currencySymbol</code> or
     *  <code>currencyISOCode</code> properties might be given unexpected
     *  values. It is a good idea to examine the
     *  <code>currencySymbol</code> and <code>currencyISOCode</code>
     *  property values before formatting a currency amount.
     *  </p>
     *
     *  @see #actualLocaleIDName
     *  @see #lastOperationsStatus
     * 
     *  @langversion 3.0
     *  @playerversion Flash 10.1
     *  @playerversion AIR 2.5
     *  @productversion Flex 4.5
     */
    public function CurrencyFormatter()
    {
        super();
    }

    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    private var resourceManager:IResourceManager =
        ResourceManager.getInstance();
    
    /**
     *  @private
     */
    private var currencySymbolOverride:String = null;

    /**
     *  @private
     */
    private var currencyISOCodeOverride:String = null;

    //--------------------------------------------------------------------------
    //
    //  Overridden Properties
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  actualLocaleIDName
    //----------------------------------

    [Bindable("change")]

    /**
     *  @inheritDoc
     *
     *  @see flash.globalization.CurrencyFormatter#actualLocaleIDName
     *  @see #CurrencyFormatter()
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.1
     *  @playerversion AIR 2.5
     *  @productversion Flex 4.5
     */
    override public function get actualLocaleIDName():String
    {
        if (g11nWorkingInstance)
            return (g11nWorkingInstance
                as flash.globalization.CurrencyFormatter).actualLocaleIDName;

        if ((localeStyle === undefined) || (localeStyle === null))
        {
            fallbackLastOperationStatus
                                = LastOperationStatus.LOCALE_UNDEFINED_ERROR;
            return undefined;
        }

        fallbackLastOperationStatus = LastOperationStatus.NO_ERROR;

        return "en-US";
    }

    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  currencyISOCode
    //----------------------------------

    [Bindable("change")]

    /**
     *  The three letter ISO 4217 currency code for the actual locale
     *  being used (e.g. USD, EUR, JPY, CNY).
     *
     *  <p>When the <code>useCurrencySymbol</code> property is set to
     *  <code>false</code>, this code is used to indicate the currency
     *  type when formatting currency amounts
     *  using the <code>format()</code> method. </p>
     *
     *  <p>This property is initialized when the locale style is set
     *  based on the actual locale that is used. When a fallback
     *  locale is used, this property reflects the preferred/default
     *  currency code for the fallback locale.</p>
     * 
     *  <p>The default value is dependent on the actual locale and operating 
     *  system.</p>
     *
     *  @throws TypeError if this property is assigned a null value. 
     *
     *  @see #actualLocaleIDName
     *  @see #format()
     *  @see #currencySymbol
     *  @see #formattingWithCurrencySymbolIsSafe()
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.1
     *  @playerversion AIR 2.5
     *  @productversion Flex 4.5
     */
    public function get currencyISOCode():String
    {
        if (g11nWorkingInstance)
            return g11nWorkingInstance.currencyISOCode;

        if ((localeStyle === undefined) || (localeStyle === null))
        {
            fallbackLastOperationStatus
                                = LastOperationStatus.LOCALE_UNDEFINED_ERROR;
            return undefined;
        }

        return properties.currencyISOCode;
    }

    public function set currencyISOCode(value:String):void
    {
        if (currencyISOCodeOverride && (currencyISOCodeOverride == value))
            return;

        currencyISOCodeOverride = value;

        if (g11nWorkingInstance)
        {
            g11nWorkingInstance.setCurrency(
                                    value, g11nWorkingInstance.currencySymbol);
        }
        else
        {
            if (!value)
            {
                const message:String = 
                    resourceManager.getString("core","nullParameter", 
                        [ currencyISOCode ]);
                throw new TypeError(message);
            }

            if (properties)
                properties.currencyISOCode = value;
            fallbackLastOperationStatus = LastOperationStatus.NO_ERROR;
        }

        update();
    }

    //----------------------------------
    //  currencySymbol
    //----------------------------------

    [Bindable("change")]

    /**
     *  The currency symbol or string for the actual locale being used.
     *
     *  <p>This property is used as the currency symbol when formatting
     *  currency amounts using the <code>format()</code> method with
     *  the <code>withCurrencySymbol</code> parameter set to
     *  <code>true</code>.</p>
     *
     *  <p>This property is initialized when the locale style is set based on
     *  the actual locale that is used. When a fallback
     *  locale is used, this property reflects the preferred/default
     *  currency symbol for the fallback locale which may be different
     *  then the locale style.</p>
     * 
     *  <p>The default value is dependent on the actual locale and operating 
     *  system.</p>
     *
     *  @throws TypeError if this property is assigned a null value. 
     *
     *  @see #actualLocaleIDName
     *  @see #format()
     *  @see #formattingWithCurrencySymbolIsSafe()
     *  @see #currencyISOCode
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.1
     *  @playerversion AIR 2.5
     *  @productversion Flex 4.5
     */
    public function get currencySymbol():String
    {
        if (g11nWorkingInstance)
            return g11nWorkingInstance.currencySymbol;

        if ((localeStyle === undefined) || (localeStyle === null))
        {
            fallbackLastOperationStatus
                                  = LastOperationStatus.LOCALE_UNDEFINED_ERROR;
            return undefined;
        }

        return properties.currencySymbol;
    }

    public function set currencySymbol(value:String):void
    {
        if (currencySymbolOverride && (currencySymbolOverride == value))
            return;

        currencySymbolOverride = value;

        if (g11nWorkingInstance)
        {
            g11nWorkingInstance.setCurrency(
                                g11nWorkingInstance.currencyISOCode, value);
        }
        else
        {
            if (!value)
            {
                const message:String = 
                    resourceManager.getString("core","nullParameter", 
                        [ currencySymbol ]);
                throw new TypeError(message);
            }

            if (properties)
                properties.currencySymbol = value;
            fallbackLastOperationStatus = LastOperationStatus.NO_ERROR;
        }

        update();
    }

    //----------------------------------
    //  negativeCurrencyFormat
    //----------------------------------

    [Bindable("change")]
    [Inspectable(category="General",
                        enumeration="0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15")]

    /**
     *  A numeric value that indicates a formatting pattern for negative
     *  currency amounts. This pattern defines the location of the
     *  currency symbol and the negative symbol or parentheses in
     *  relation to the numeric portion of the currency
     *  amount.
     *
     *   <p>The value of this property must be one of the constants
     *  defined in the table below.
     *  </p>
     *
     *  <p>The table below summarizes the possible formatting patterns
     *  for negative currency amounts. When a currency amount is formatted
     *  with the <code>format()</code> method:</p>
     *
     *  <ul>
     *   <li>The '&#164;' symbol is replaced with the value of the
     *       <code>currencyISOCode</code> or
     *       the <code>currencySymbol</code> property, depending on
     *       the value of the <code>withCurrencySymbol</code> parameter
     *       passed to the <code>format()</code> method;</li>
     *   <li>The '-' character is replaced with the value of the
     *       <code>negativeNumberSymbol</code> property;</li>
     *   <li>The 'n' character is replaced with the currency amount
     *       value that is passed to the <code>format()</code> method.</li>
     *  </ul>
     *
     *    <table class="innertable" border="0">
     *        <tr>
     *            <td>Negative currency format type</td>
     *            <td>Formatting pattern</td>
     *        </tr>
     *        <tr>
     *            <td>0</td>
     *            <td>(&#164;n)</td>
     *        </tr>
     *        <tr>
     *            <td>1</td>
     *            <td>-&#164;n</td>
     *        </tr>
     *        <tr>
     *            <td>2</td>
     *            <td>&#164;-n</td>
     *        </tr>
     *        <tr>
     *            <td>3</td>
     *            <td>&#164;n-</td>
     *        </tr>
     *        <tr>
     *            <td>4</td>
     *            <td>(n&#164;)</td>
     *        </tr>
     *        <tr>
     *            <td>5</td>
     *            <td>-n&#164;</td>
     *        </tr>
     *        <tr>
     *            <td>6</td>
     *            <td>n-&#164;</td>
     *        </tr>
     *        <tr>
     *            <td>7</td>
     *            <td>n&#164;-</td>
     *        </tr>
     *        <tr>
     *            <td>8</td>
     *            <td>-n &#164;</td>
     *        </tr>
     *        <tr>
     *            <td>9</td>
     *            <td>-&#164; n</td>
     *        </tr>
     *        <tr>
     *            <td>10</td>
     *            <td>n &#164;-</td>
     *        </tr>
     *        <tr>
     *            <td>11</td>
     *            <td>&#164; n-</td>
     *        </tr>
     *        <tr>
     *            <td>12</td>
     *            <td>&#164; -n</td>
     *        </tr>
     *        <tr>
     *            <td>13</td>
     *            <td>n- &#164;</td>
     *        </tr>
     *        <tr>
     *            <td>14</td>
     *            <td>(&#164; n)</td>
     *        </tr>
     *        <tr>
     *            <td>15</td>
     *            <td>(n &#164;)</td>
     *        </tr>
     *    </table>
     * 
     *  <p>The default value is dependent on the actual locale and operating 
     *  system.</p>
     *
     *  @throws ArgumentError if the assigned value is not between 0 and 15.
     * 
     *  @see #format()
     *  @see #currencySymbol
     *  @see #negativeSymbol
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.1
     *  @playerversion AIR 2.5
     *  @productversion Flex 4.5
     */
    public function get negativeCurrencyFormat():uint
    {
        return getBasicProperty(properties, NEGATIVE_CURRENCY_FORMAT);
    }

    public function set negativeCurrencyFormat(value:uint):void
    {
        if (!g11nWorkingInstance)
        {
            if ((value < 0) || (15 < value))
            {
                const message:String = 
                    resourceManager.getString("core","badIndex");
                throw new ArgumentError(message);
            }
        }

        setBasicProperty(properties, NEGATIVE_CURRENCY_FORMAT, value);
    }

    //----------------------------------
    //  positiveCurrencyFormat
    //----------------------------------

    [Bindable("change")]
    [Inspectable(category="General", enumeration="0,1,2,3")]

    /**
     *  A numeric value that indicates a formatting pattern for positive
     *  currency amounts. This format defines the location of the currency
     *  symbol relative to the numeric portion of the currency amount.
     *
     *  <p>The value of this property must be one of the constants
     *  defined in the table below.
     *  </p>
     *
     *  <p>The table below summarizes the possible formatting patterns
     *  for positive currency amounts.
     *  When a currency amount is formatted with the <code>format()</code>
     *  method:</p>
     *
     *  <ul>
     *   <li>The '&#164;' symbol is replaced with the value of the
     *       <code>currencyISOCode</code> or
     *       the <code>currencySymbol</code> property, depending on the
     *       value of the <code>withCurrencySymbol</code> parameter
     *       passed to the <code>format()</code> method;</li>
     *   <li>The 'n' character is replaced with the currency amount value
     *       that is passed to the <code>format()</code> method.</li>
     *  </ul>
     *
     *    <table class="innertable" border="0">
     *        <tr>
     *            <td>Positive currency format type</td>
     *            <td>Formatting pattern</td>
     *        </tr>
     *        <tr>
     *            <td>0</td>
     *            <td>&#164;n</td>
     *        </tr>
     *        <tr>
     *            <td>1</td>
     *            <td>n&#164;</td>
     *        </tr>
     *        <tr>
     *            <td>2</td>
     *            <td>&#164; n</td>
     *        </tr>
     *        <tr>
     *            <td>3</td>
     *            <td>n &#164;</td>
     *        </tr>
     *    </table>
     *
     *  <p>The default value is dependent on the actual locale and operating 
     *  system.</p>
     *
     *  @throws ArgumentError if the assigned value is not between 0 and 3.
     *
     *  @see #currencySymbol
     *  @see #format()
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.1
     *  @playerversion AIR 2.5
     *  @productversion Flex 4.5
     */
    public function get positiveCurrencyFormat():uint
    {
        return getBasicProperty(properties, POSITIVE_CURRENCY_FORMAT);
    }

    public function set positiveCurrencyFormat(value:uint):void
    {
        if (!g11nWorkingInstance)
        {
            if ((value < 0) || (4 < value))
            {
                const message:String = 
                    resourceManager.getString("core","badIndex");
                throw new ArgumentError(message);
            }
        }

        setBasicProperty(properties, POSITIVE_CURRENCY_FORMAT, value);
    }

    //----------------------------------
    //  useCurrencySymbol
    //----------------------------------

    /**
     *  @private
     */
    private var _useCurrencySymbol:Boolean = false;

    [Bindable("change")]

    /**
     *  Enables the use of the <code>currencySymbol</code> property 
     *  when formatting currency amounts.
     *
     *  <p>When the <code>useCurrencySymbol</code> property is
     *  set to <code>true</code>, the value of the
     *  <code>currencySymbol</code> property is used
     *  in the string returned by the format method.
     *  For example: <code>$123,456,789.22</code></p>
     *
     *  <p>When the <code>useCurrencySymbol</code> property is set to
     *  <code>false</code>, the value of the <code>currencyISOCode</code>
     *  property is used in the string returned by the <code>format</code>
     *  method. For example: <code>USD123,456,789.22</code></p>
     *
{'fraction_non_alphanumeric': 0.1664390063204686, 'fraction_numerical': 0.011714861204361817, 'mean_word_length': 1.546816037735849, 'pattern_counts': {'":': 0, '<': 669, '<?xml version=': 0, '>': 661, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6541493', 'n_tokens_mistral': 12365, 'n_tokens_neox': 11830, 'n_words': 3061}