Updated to use vectors, changed some naming convention, reduced a bit of 
redundant code, updated the example to better display the internal arguments 
and allow minor modification.

Attachments have an additional extension of .txt just to keep them from getting 
stripped.


//
//  public properties
//

//Length of the arrays
length [get]

//Gets or sets all the arguments in a single string.
stringArguments [get, set]


//
//  public methods
//

//Adds a new argument and value or a new argument with no assignment.
public function add(sName:String, sValue:String = null):void

//Remove an argument by its name.
public function remove(sName:String):void

//Update an argument by its name.
public function update(sName:String, sValue:String = null):Boolean


//Return the argument name at the given index.
public function getNameAt(nIndex:int):String

//Return the argument value at the given index.
public function getValueAt(nIndex:int):String

//Find the index of an argument by its name
public function indexOf(sName:String):int

//Remove an argument by its index.
public function removeAt(nIndex:int):void

//Updates the argument value at the given index.
public function setValueAt(nIndex:int, sValue:String = null):Boolean



-----Original Message-----
From: Kessler CTR Mark J [mailto:mark.kessler....@usmc.mil] 
Sent: Monday, August 27, 2012 14:12
To: flex-dev@incubator.apache.org
Subject: RE: Getting Mustella to work.

I'll try the attachments again with txt extensions

>-----Original Message-----
>From: Peter Ent [mailto:p...@adobe.com]
>Sent: Thursday, August 23, 2012 11:56
>To: flex-dev@incubator.apache.org
>Subject: Re: Getting Mustella to work.
>
>Certainly appreciate the help. Here's a typical one when running Mustella:
>
>-debug -define=CONFIG::skaha,false
>-compiler.fonts.managers=flash.fonts.JREFontManager,flash.fonts.AFEFont
>Man
>a
>ger,flash.fonts.BatikFontManager,flash.fonts.CFFFontManager
>-source-path=/Users/pent/apache/flex/mustella/Assets
>-includes=ExcludeFileLocation -includes=SetShowRTE 
>-includes=SaveBitmapFailures 
>-includes=datagrid_properties_lockedColumnCount_mxml
>-source-path=/Users/pent/apache/flex/mustella/tests/components/DataGrid
>/Da
>t
>aGrid_SparkSkin/Properties --allow-source-path-overlap=true 
>-includes=SendResultsToRunner  -includes=ExitWhenDone -source-path=.
>-source-path=/Users/pent/apache/flex/mustella/../frameworks/
>-source-path=/Users/pent/apache/flex/mustella/as3/src/mustella
>
>Try changing my path, "/Users/pent/apache/" to something like 
>"/Users/pent/apache with spaces/" to get a better example.
>
>What happens in the code is that groups of these options may be coming 
>from the environment, so you might find "-debug 
>-define=CONFIG::skaha,false" being added as a single entity. Then code 
>turns what it has at the moment into a String[] and passes that to 
>another function that might add more arguments. If that function does, 
>it will turn the String[] back into a String, add the arguments, then 
>turn it back into String[].
>
>But if you can make something that will convert the args into an 
>acceptable String[] it would be super-helpful.
>
>Thanks!
>--peter
/***************************************
public Variables.
----------------------------------------
--none--


public Properties.
----------------------------------------

//Length of the arrays
length [get]

//Gets or sets all the arguments in a single string.
stringArguments [get, set]


public Methods.
----------------------------------------
//Resets the class.
public function reset():void



//Adds a new argument and value or just a new argument with no assignment.
public function add(sName:String, sValue:String = null):void

//Remove an argument by it's name.
public function remove(sName:String):void

//Update an argument by it's name.
public function update(sName:String, sValue:String = null):Boolean



//Return the argument name at the given index.
public function getNameAt(nIndex:int):String

//Return the argument value at the given index.
public function getValueAt(nIndex:int):String

//Find the index of an argument by it's name
public function indexOf(sName:String):int

//Remove an argument by it's index.
public function removeAt(nIndex:int):void

//Updates the argument value at the given index.
public function setValueAt(nIndex:int, sValue:String = null):Boolean

//Creates an arraylist of all the names/values and returns it.
public function toArrayList():ArrayList


Events.
----------------------------------------


Author: Mark Kessler
Last Updated: 2012-08-29

***************************************/

//Setup the package
package
{
   import mx.collections.ArrayList;

   //Declare class
   public class ArgManage
   {
      //--------------------------------------
      //  Constants
      //--------------------------------------
      public static const REGEX_INITIAL_SPLIT:RegExp = /\s(?=[\+\-])/;
      public static const REGEX_NAME_VALUE_SPLIT:RegExp = /=/;
      public static const REGEX_WHITESPACE_TRIM:RegExp = /^\s+|\s+$/g;


      //--------------------------------------
      //  Variables
      //--------------------------------------
      protected var saNames:Vector.<String> = new Vector.<String>();
      protected var saValues:Vector.<String> = new Vector.<String>();
      protected var sGivenSource:String = "";


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

      //Getter for argument array length.
      public function get length():int
      {
         return this.saNames.length;
      }

      //Getter for stringArguments.
      public function get stringArguments():String
      {
         return this.CombineArguments();
      }

      //Setter for stringArguments.
      public function set stringArguments(value:String):void
      {
         //Reset the arrays/strings
         this.reset();

         //Store the new source argument string.
         this.sGivenSource = value;

         //Seperate the arguments.
         this.SeperateArguments();
      }


      //--------------------------------------
      //  Methods
      //--------------------------------------

      //Constructor.
      public function ArgManage():void
      {
      }

      //Resets the class back to default.
      public function reset():void
      {
         this.saNames.length = 0;
         this.saValues.length = 0;
         this.sGivenSource = "";
      }

      //Adds a new argument and value or just a new argument with no assignment.
      public function add(sName:String, sValue:String = null):void
      {
         var nIndex:int = -1;

         //Make sure the name isn't empty.
         if (sName == "")
         {
            return;
         }

         //Find the arguments index.
         nIndex = this.indexOf(sName);

         //Check if the argument was not found.
         if (nIndex == -1)
         {
             //
             // Add new item
             //

             //Add an element for the current name.
             this.saNames.push(sName);

             //Check if the value is null.
             if (sValue == null)
             {
                //Add the null as the value to make a difference in empty 
string and no assignment at all.
                this.saValues.push(null);
             }
             else
             {
                //Trim the value before processing it. 
                sValue = this.Trim(sValue);

                //Check if the given value is empty.
                if (sValue == "")
                {
                   //Add an empty value.
                   this.saValues.push("");
                }
                else
                {
                   //Check if the first and last character are double quotes.
                   if (sValue.charAt(0) == "\"" && 
sValue.charAt(sValue.length-1) == "\"")
                   {
                      //Grab all but a starting and ending characters, trim any 
outside spaces, and add the new element.
                      this.saValues.push(this.Trim(sValue.substr(1, 
sValue.length-2)));
                   }
                   else
                   {
                      //Add an element for the current value and trim any 
outside spaces.
                      this.saValues.push(sValue);
                   }
                }
             }
         }
         else
         {
             //
             // Update an existing item
             //

            //Update the value for the argument with the givin one and trim any 
outer spaces.
            this.saValues[nIndex] = this.Trim(sValue);
         }
      }

      //Combine the arguments back into a single string.
      protected function CombineArguments():String
      {
         var sCombined:String = "";
         var sTempValue:String = "";
         var nTotal:int = 0;
         var nCount:int = 0;

         //Get the totla number of elements.
         nTotal = this.saNames.length;

         //Loop through all the elements of the names array.
         for (nCount = 0; nCount < nTotal; nCount++)
         {
            //Start the name.
            sCombined += this.saNames[nCount];

            //Check if the current item has a varying argument value.
            if (this.saValues[nCount] != null)
            {
               //Get the current value.
               sTempValue = this.saValues[nCount];

               //Check if there are spaces in the value.
               if (sTempValue.indexOf(" ") == -1)
               {
                  //Append the argument value.
                  sCombined += "=" + sTempValue;
               }
               else
               {
                  //Append the argument value while wrapping it in quotes.
                  sCombined += "=\"" + sTempValue + "\"";
               }
            }

            //Check for the last item to avoid a trailing space on the last 
item.
            if (nCount < this.saNames.length -1)
            {
               //Add a trailing space.
               sCombined += " ";
            }
         }

         //Return the combined string.
         return sCombined;
      }

      //Return the argument name at the given index.
      public function getNameAt(nIndex:int):String
      {
         //Check for out of bounds index.
         if (nIndex >= this.saNames.length)
         {
            //Return null for a psuedo error.
            return null;
         }

         //Return the argument name at the given index.
         return this.saNames[nIndex];
      }

      //Return the argument value at the given index.
      public function getValueAt(nIndex:int):String
      {
         //Check for out of bounds index.
         if (nIndex >= this.saValues.length)
         {
            //Return null for a psuedo error.
            return null;
         }

         //Return the argument value at the given index.
         return this.saValues[nIndex];
      }

      //Find the index of an argument by it's name and return its index.
      public function indexOf(sName:String):int
      {
         return this.saNames.indexOf(sName);
      }

      //Remove an argument by it's name.
      public function remove(sName:String):void
      {
         var nIndex:int = -1;

         //Find the arguments index.
         nIndex = this.indexOf(sName);

         //Check if the argument was not found.
         if (nIndex == -1)
         {
            return;
         }

         //Remove the argument from all the arrays.
         this.saNames.splice(nIndex, 1);
         this.saValues.splice(nIndex, 1);
      }

      //Remove an argument by it's index.
      public function removeAt(nIndex:int):void
      {
         //Check for out of bounds index.
         if (nIndex >= this.saValues.length)
         {
            //Return out, out of bounds.
            return;
         }

         //Remove the argument from all the arrays.
         this.saNames.splice(nIndex, 1);
         this.saValues.splice(nIndex, 1);
      }

      //Updates the argument value at the given index.
      public function setValueAt(nIndex:int, sValue:String = null):Boolean
      {
         //Check for out of bounds index.
         if (nIndex >= this.saNames.length)
         {
            //Return failure.
            return false;
         }

         //Update the value for the argument with the givin one and trim any 
outer spaces.
         this.saValues[nIndex] = this.Trim(sValue);

         //Return success.
         return true;
      }

      //Creates an arraylist of all the names/values and returns it.
      public function toArrayList():ArrayList
      {
         var oaCombined:ArrayList = new ArrayList();
         var nTotal:int = 0;
         var nCount:int = 0;

         //Get the totla number of elements.
         nTotal = this.saNames.length;

         //Loop through all the names
         for (nCount = 0; nCount < nTotal; nCount++)
         {
            //Check if the value is null, which would represent no assignment.
            if (this.saValues[nCount] == null)
            {
               //Add another element to the array with the current argument 
name and value.
               oaCombined.addItem({name:this.saNames[nCount], 
value:this.saValues[nCount], hasAssignment:false});
            }
            else
            {
               //Add another element to the array with the current argument 
name and value.
               oaCombined.addItem({name:this.saNames[nCount], 
value:this.saValues[nCount], hasAssignment:true});
            }
         }

         //Return the new arraylist.
         return oaCombined;
      }

      //Update an argument by it's name.
      public function update(sName:String, sValue:String = null):Boolean
      {
         var nIndex:int = -1;

         //Find the arguments index.
         nIndex = this.indexOf(sName);

         //Check if the argument name is missing.
         if (nIndex == -1)
         {
            //Returning false, not found, unable to update.
            return false;
         }

         //Update the value for the argument with the givin one and trim any 
outer spaces.
         this.saValues[nIndex] = this.Trim(sValue);

         //Updated successfully.
         return true;
      }

      //Seperate the arugments.
      protected function SeperateArguments():void
      {
         var saTempArgList:Array = null;
         var saTempItem:Array = null;
         var sTemp:String = "";
         var nTotal:int = 0;
         var nCount:int = 0;

         //Perform the initial split to create an argument string array. Looks 
for the " +/-" and retains the characters.
         saTempArgList = this.sGivenSource.split(REGEX_INITIAL_SPLIT);

         //Get the totla number of elements.
         nTotal = saTempArgList.length;

         //Loop through all the temp argument list elements.
         for (nCount = 0; nCount < nTotal; nCount++)
         {
            //Split out the single argument item and value into a temp array 
using the "=".  would store the equals too, but cannot use lookback.
            saTempItem = saTempArgList[nCount].split(REGEX_NAME_VALUE_SPLIT);

            //Add an element for the current name.
            this.saNames.push(String(saTempItem[0]));

            //Check if there is a value.
            if (saTempItem.length > 1)
            {
               //Convert the the value to a string for processing.
               sTemp = String(saTempItem[1]);

               //Check if the first and last character are double quotes.
               if (sTemp.charAt(0) == "\"" && sTemp.charAt(sTemp.length-1) == 
"\"")
               {
                  //Grab all but a starting and ending characters, trim any 
outside spaces, and add a new element with it.
                  this.saValues.push(this.Trim(sTemp.substr(1, 
sTemp.length-2)));
               }
               else
               {
                  //Add an element for the current value and trim any outside 
spaces.
                  this.saValues.push(this.Trim(sTemp));
               }
            }
            else
            {
               //Add an empty node.
               this.saValues.push(null);
            }
         }
      }

      //Trim the leading and trailing whitespace characters from the given 
string.
      public function Trim(sSource:String):String
      {
         //Check if the source is a null.
         if (sSource == null)
         {
            //Pass the null through.
            return null;
         }

         //Return the modified string... stripped of leading and trailing 
whitespace characters.
         return sSource.replace(REGEX_WHITESPACE_TRIM, "");
      }


      //--------------------------------------
      //  Events
      //--------------------------------------


   }
}
<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009";
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               height="100%" width="100%"
               creationPolicy="all"
               initialize="Application_OnInitialize();" >

   <fx:Script>
      <![CDATA[
         //Import class file.
         import ArgManage;


         ////////////////////////////////////////
         //              Variables             //
         ////////////////////////////////////////
         protected var oArgs:ArgManage = new ArgManage();
         protected var sStartingString:String = '-debug 
-define=CONFIG::skaha,false 
-compiler.fonts.managers=flash.fonts.JREFontManager,flash.fonts.AFEFontManager,flash.fonts.BatikFontManager,flash.fonts.CFFFontManager
 -source-path=/Users/pent/apache/flex/mustella/Assets 
-includes=ExcludeFileLocation -includes=SetShowRTE -includes=SaveBitmapFailures 
-includes=datagrid_properties_lockedColumnCount_mxml 
-source-path=/Users/pent/apache/flex/mustella/tests/components/DataGrid/DataGrid_SparkSkin/Properties
 --allow-source-path-overlap=true -includes=SendResultsToRunner  
-includes=ExitWhenDone -source-path=. -source-path="/Users/long user 
name/apache/flex/mustella/../frameworks/" -source-path=/Users/test 
space/apache/flex/mustella/as3/src/mustella -empty=';


         ////////////////////////////////////////
         //              Methods               //
         ////////////////////////////////////////

         //Updates the datagrid and output controls.
         protected function UpdateControls():void
         {
            //Update the dataProvider with an arraylist version of the 
arguments class.
            dgSourceContents.dataProvider = oArgs.toArrayList();

            //Get the new string of arguments.
            txtOutput.text = oArgs.stringArguments;
         }


         ////////////////////////////////////////
         //               Events               //
         ////////////////////////////////////////

         //The Application OnInitialize event handler.
         protected function Application_OnInitialize():void
         {
            //Set the starting text.
            txtInput.text = sStartingString;
         }

         //Click event handler for the cmdRun Button.
         protected function cmdRun_OnClick():void
         {
            //Set the new string arguments list from the source textarea and 
have it processed into arrays.
            oArgs.stringArguments = txtInput.text;

            //Update the controls data.
            UpdateControls();
         }

         //Click event for the cmdAdd button.
         protected function cmdAdd_OnClick():void
         {
            //Check if the current selection is with an assignment.
            if (chkToggleAssignment.selected == true)
            {
               //Add a new argument name and value combination.
               oArgs.add(txtName.text, txtValue.text);
            }
            else
            {
               //Add a new argument name that does not have an assignment/value.
               oArgs.add(txtName.text);
            }

            //Update the controls data.
            UpdateControls();
         }

         //Click event handler for the cmdRemove Button.
         protected function cmdRemove_OnClick():void
         {
            //Check if the datagrid has an item selected.
            if (dgSourceContents.selectedIndex < 0)
            {
               return;
            }

            //Remove the selected item.
            oArgs.removeAt(dgSourceContents.selectedIndex);

            //Update the controls data.
            UpdateControls();
         }

         //Click event for the cmdUpdate button.
         protected function cmdUpdate_OnClick():void
         {
            //Check if the current selection is with an assignment.
            if (chkToggleAssignment.selected == true)
            {
               //Update an existing argument name and value combination.
               oArgs.update(txtName.text, txtValue.text);
            }
            else
            {
               //Update an existing argument name that does not have an 
assignment/value.
               oArgs.update(txtName.text);
            }

            //Update the controls data.
            UpdateControls();
         }


      ]]>
   </fx:Script>

   <!-- Layout -->
   <s:layout>
      <s:VerticalLayout horizontalAlign="left" verticalAlign="middle" gap="0" />
   </s:layout>

   <!-- Input -->
   <s:Label text="Input" />
   <s:TextArea id="txtInput" width="100%" height="100" />

   <!-- Spacer-->
   <s:Rect height="20" />

   <!-- Run -->
   <s:Button id="cmdRun" label="Process the Source String" 
click="cmdRun_OnClick();" />

   <!-- Spacer-->
   <s:Rect height="20" />

   <!-- Source Contents DataGrid -->
   <s:Label text="Contents of Source String" />
   <s:DataGrid id="dgSourceContents" width="100%" requestedRowCount="5" 
sortableColumns="false">
      <s:columns>
         <s:ArrayList>
            <s:GridColumn dataField="name" headerText="Name" width="200" />
            <s:GridColumn dataField="value" headerText="Value" />
            <s:GridColumn dataField="hasAssignment" headerText="Assignment" 
width="80" />
         </s:ArrayList>
      </s:columns>
   </s:DataGrid>

   <!-- Spacer-->
   <s:Rect height="1" />

   <!-- Second Element Count -->
   <s:Label text="Total: {dgSourceContents.dataProvider.length}" />

   <!-- Spacer-->
   <s:Rect height="20" />

   <!-- Start argument controls -->
   <s:HGroup width="100%" verticalAlign="middle">

      <!-- Argument Name-->
      <s:VGroup gap="0">
         <s:Label text="Name" />
         <s:TextInput id="txtName" text="{dgSourceContents.selectedItem.name}" 
width="200" />
      </s:VGroup>

      <!-- Argument Value-->
      <s:VGroup gap="0">
         <s:Label text="Value" />
         <s:TextInput id="txtValue" 
text="{dgSourceContents.selectedItem.value}" width="500" />
      </s:VGroup>

      <!-- Argument has Assignment -->
      <s:CheckBox id="chkToggleAssignment" label="Has Assignment" 
selected="{dgSourceContents.selectedItem.hasAssignment}" />

   </s:HGroup>
   <!-- End argument controls -->

   <!-- Spacer-->
   <s:Rect height="10" />

   <!-- Start pile o buttons -->
   <s:HGroup width="100%" verticalAlign="middle">

      <!-- Remove button -->
      <s:Button id="cmdRemove" label="Remove selected" 
click="cmdRemove_OnClick();" />
      <s:Button id="cmdAdd" label="Add Item" click="cmdAdd_OnClick();" />
      <s:Button id="cmdUpdate" label="Update Item" click="cmdUpdate_OnClick();" 
/>

   </s:HGroup>
   <!-- End pile o buttons -->

   <!-- Spacer-->
   <s:Rect height="20" />

   <!-- Input -->
   <s:Label text="Output" />
   <s:TextArea id="txtOutput" editable="false" width="100%" height="100" />

</s:Application>

Reply via email to