public object getMacroNames() { // ****** var array = new NmpArray(); // ****** var list = mp.GetMacros( false ); var names = new NmpStringList(); foreach( IMacro macro in list ) { names.Add( macro.Name ); } array.Add( "unsorted", names ); names.Sort(); array.Add( "sorted", names ); list.Sort( ( a, b ) => string.Compare( a.Name, b.Name ) ); // ****** // Builtin, // Object, // Text, names = new NmpStringList(); foreach( IMacro macro in list ) { if( MacroType.Builtin == macro.MacroType ) { names.Add( macro.Name ); } } array.Add( "builtin", names ); names = new NmpStringList(); foreach( IMacro macro in list ) { if( MacroType.Object == macro.MacroType ) { names.Add( macro.Name ); } } array.Add( "object", names ); names = new NmpStringList(); foreach( IMacro macro in list ) { if( MacroType.Text == macro.MacroType ) { names.Add( macro.Name ); } } array.Add( "text", names ); // ****** return array; }
///////////////////////////////////////////////////////////////////////////// public static string VisualizeArray( NmpArray array, JSONDateFormat dateFormat = JSONDateFormat.ISODate ) { var x = new JSONVisualizer( dateFormat ); return x.Array( array ); }
public object getMacros() { // ****** // // caller needs to initiliaze a macro with a call to us // NmpArray array = new NmpArray(); // ****** foreach( IMacro macro in mp.GetMacros(false) ) { array.Add( macro.Name, macro ); } // ****** return array; }
///////////////////////////////////////////////////////////////////////////// protected void WalkArray( NmpArray array ) { // ****** ++indent; output.Append( '{' ); // ****** var keyList = array.Keys; for( int index = 0; index < keyList.Count; index++ ) { if( index > 0 ) { output.Append( ',' ); } string key = keyList[ index ]; Identifier( key ); Value( array[key] ); } // ****** output.Append( "}" ); --indent; }
///////////////////////////////////////////////////////////////////////////// protected string Array( NmpArray array ) { // ****** indent = 0; output = new StringBuilder(); WalkArray( array ); return output.ToString(); }
public NmpArray ExtractSubexpressions( string regExStr, int maxItems ) { // ****** NmpArray array = new NmpArray(); try { Regex rx = new Regex( regExStr ); MatchCollection mc = rx.Matches( theString ); // // find all matches for a regular expression and for each one return an // array of all subexpression whether captured or no, subexpressions that // are not captured (such as alterations that don't match) will be returned // as the empty string // // so either return a List<string []> or // string [] groupNames = rx.GetGroupNames(); int [] groupIndexes = rx.GetGroupNumbers(); int matchIndex = 0; foreach( Match match in mc ) { NmpArray subExpressions = new NmpArray(); for( int iGroup = 0; iGroup < match.Groups.Count; iGroup++ ) { string key; if( 0 == iGroup ) { key = "match"; } else { if( string.IsNullOrEmpty(groupNames[iGroup]) ) { continue; } key = groupNames[ iGroup ]; } // ****** subExpressions.Add( key, match.Groups[ iGroup ].Value ); } // // match.Value may not be unique // array.AddArray( (matchIndex++).ToString(), subExpressions ); // // note: we are NOT inhibiting Matches from generating as many matches as it // can, only limiting the number we return // if( 0 == --maxItems ) { break; } } } catch ( ArgumentException ex ) { throw ex; } // ****** return array; }
/////////////////////////////////////////////////////////////////////////// public JSONArrayBuilder( WarningCall warning ) { // ****** this.warning = warning; // ****** rootArray = null; }
/////////////////////////////////////////////////////////////////////////// public void EnterObject( JSONParser jp ) { // ****** //Trace.Write( "Enter object\n" ); // ****** if( null == rootArray ) { rootArray = new NmpArray(); arrayStack.Push( rootArray ); } else { // // arrays can have unnamed objects // var array = new NmpArray(); if( string.IsNullOrEmpty(lastIdentifier) ) { CurrentList.Add( array ); } else { CurrentArray.Add( lastIdentifier, array ); lastIdentifier = null; } // ****** arrayStack.Push( array ); } }
///////////////////////////////////////////////////////////////////////////// public TextMacroRunner( IMacroProcessor mp, IMacro macro, IMacroArguments args, object [] objArgsIn ) { // ****** this.mp = mp; this.macro = macro; this.options = args.Options; this.objectArgs = objArgsIn; this.arguments = new NmpStringList( objArgsIn, false ); // ****** expressionNodeTypeName = args.Expression.NodeTypeName; // ****** ///flags = new BitArray( (int)MDIndexes.COUNT_DIRECTIVES, false ); // ****** argsMacro = mp.AddObjectMacro( mp.GenerateArgListName( macro.Name ), this.arguments ); specials = mp.AddObjectMacro( mp.GenerateLocalName( macro.Name + "_specials" ), args.SpecialArgs ); localArrayMacro = mp.AddObjectMacro( mp.GenerateLocalName( macro.Name ), localArray = new NmpArray() ); objArgsMacro = mp.AddObjectMacro( mp.GenerateArgListName( macro.Name + "Objects" ), objArgsIn ); }
public object newArray( params string [] strs ) { // ****** var array = new NmpArray(); var chars = new char [] { ':', '=' }; foreach( string str in strs ) { string s = null; // ****** var arrayResult = CheckForJSON( str ); if( null != arrayResult ) { array.AppendArray( arrayResult ); } else { s = str; int index = s.IndexOfAny( chars ); if( index > 0 && index < s.Length - 1 ) { string strValue = s.Substring( 1 + index ); arrayResult = CheckForJSON( strValue ); array.Add( s.Substring(0, index), null == arrayResult ? (object) strValue : (object) arrayResult ); } else { array.Add( s, string.Empty ); } } } // ****** return array; }