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 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 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; }
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; }