/////////////////////////////////////////////////////////////////////// #region ToString Methods public ReturnCode ToList( string pattern, bool noCase, bool fullName, bool qualified, ref StringList list, ref Result error ) { StringList inputList = new StringList(); foreach (Type type in this) { if (type != null) { inputList.Add(FormatOps.QualifiedAndOrFullName( type, fullName, qualified, false)); } } if (list == null) { list = new StringList(); } return(GenericOps <string> .FilterList( inputList, list, Index.Invalid, Index.Invalid, ToStringFlags.None, pattern, noCase, ref error)); }
/////////////////////////////////////////////////////////////////////// public string ToString( string pattern, bool noCase, bool qualified ) { if (qualified) { StringList list = new StringList(); foreach (Type type in this) { if (type != null) { list.Add(FormatOps.QualifiedName(type)); } } return(GenericOps <string> .ListToString( list, Index.Invalid, Index.Invalid, ToStringFlags.None, Characters.Space.ToString(), pattern, noCase)); } else { return(GenericOps <Type> .ListToString( this, Index.Invalid, Index.Invalid, ToStringFlags.None, Characters.Space.ToString(), pattern, noCase)); } }
/////////////////////////////////////////////////////////////////////// internal StringList GetWatchpoints() { StringList result = new StringList(); foreach (KeyValuePair <string, IVariable> pair in this) { IVariable variable = pair.Value; if (variable == null) { continue; } VariableFlags flags = EntityOps.GetWatchpointFlags( variable.Flags); if (flags != VariableFlags.None) { // // NOTE: Two element sub-list of name and watch types. // result.Add(new StringList( variable.Name, flags.ToString()).ToString()); } } return(result); }
/////////////////////////////////////////////////////////////////////// internal StringList GetDefined( Interpreter interpreter, string pattern ) { StringList result = new StringList(); foreach (KeyValuePair <string, IVariable> pair in this) { IVariable variable = pair.Value; if (variable == null) { continue; } if (EntityOps.IsUndefined(variable)) { continue; } string name = variable.Name; if ((pattern == null) || StringOps.Match( interpreter, StringOps.DefaultMatchMode, name, pattern, false)) { result.Add(name); } } return(result); }
/////////////////////////////////////////////////////////////////////// public static StringList GetRangeAsStringList( IList list, int firstIndex, int lastIndex, bool dequote ) { StringList range = null; if (list != null) { range = new StringList(); if (firstIndex == Index.Invalid) { firstIndex = 0; } if (lastIndex == Index.Invalid) { lastIndex = list.Count - 1; } for (int index = firstIndex; index <= lastIndex; index++) { object item = list[index]; if (item == null) { range.Add((string)null); continue; } string @string = item.ToString(); if (dequote) { @string = FormatOps.StripOuter( @string, Characters.QuotationMark); } range.Add(@string); } } return(range); }
/////////////////////////////////////////////////////////////////////// internal StringList GetLocals( Interpreter interpreter, string pattern ) { if (pattern != null) { pattern = ScriptOps.MakeVariableName(pattern); } StringList result = new StringList(); foreach (KeyValuePair <string, IVariable> pair in this) { IVariable variable = pair.Value; if (variable == null) { continue; } if (EntityOps.IsUndefined(variable) || EntityOps.IsLink(variable)) { continue; } ICallFrame frame = CallFrameOps.FollowNext(variable.Frame); if (interpreter != null) { if (interpreter.IsGlobalCallFrame(frame)) { continue; } if (Interpreter.IsNamespaceCallFrame(frame)) { continue; } } string name = variable.Name; if ((pattern == null) || StringOps.Match( interpreter, StringOps.DefaultMatchMode, name, pattern, false)) { result.Add(name); } } return(result); }
/////////////////////////////////////////////////////////////////////// public ReturnCode ToList( CommandFlags hasFlags, CommandFlags notHasFlags, bool hasAll, bool notHasAll, string pattern, bool noCase, ref StringList list, ref Result error ) { StringList inputList; // // NOTE: If no flags were supplied, we do not bother filtering on // them. // if ((hasFlags == CommandFlags.None) && (notHasFlags == CommandFlags.None)) { inputList = new StringList(this.Keys); } else { inputList = new StringList(); foreach (KeyValuePair <string, ISubCommand> pair in this) { if (pair.Value != null) { if (((hasFlags == CommandFlags.None) || FlagOps.HasFlags(pair.Value.CommandFlags, hasFlags, hasAll)) && ((notHasFlags == CommandFlags.None) || !FlagOps.HasFlags(pair.Value.CommandFlags, notHasFlags, notHasAll))) { inputList.Add(pair.Key); } } } } if (list == null) { list = new StringList(); } return(GenericOps <string> .FilterList( inputList, list, Index.Invalid, Index.Invalid, ToStringFlags.None, pattern, noCase, ref error)); }
/////////////////////////////////////////////////////////////////////// public IStringList ToList( string pattern, bool empty, bool noCase ) { StringList inputList; StringList outputList = new StringList(); if (empty) { inputList = this; } else { inputList = new StringList(); foreach (string element in this) { if (String.IsNullOrEmpty(element)) { continue; } inputList.Add(element); } } ReturnCode code; Result error = null; code = GenericOps <string> .FilterList( inputList, outputList, Index.Invalid, Index.Invalid, ToStringFlags.None, pattern, noCase, ref error); if (code != ReturnCode.Ok) { DebugOps.Complain(code, error); // // TODO: Return null in the error case here? // outputList = null; } return(outputList); }
/////////////////////////////////////////////////////////////////////// public static StringList GetRange( IList list, int firstIndex, int lastIndex, bool nullIfEmpty ) { if (list == null) { return(null); } StringList range = null; if (firstIndex == Index.Invalid) { firstIndex = 0; } if (lastIndex == Index.Invalid) { lastIndex = list.Count - 1; } if ((!nullIfEmpty || ((list.Count > 0) && ((lastIndex - firstIndex) > 0)))) { range = new StringList(); for (int index = firstIndex; index <= lastIndex; index++) { range.Add(StringOps.GetStringFromObject(list[index])); } } return(range); }
/////////////////////////////////////////////////////////////////////// public string ToString( string separator, string pattern, bool empty, bool noCase ) { #if CACHE_STRINGLIST_TOSTRING bool canUseCachedString = CanUseCachedString( separator, pattern, empty, noCase); if (canUseCachedString && (@string != null)) { #if CACHE_STATISTICS Interlocked.Increment( ref cacheCounts[(int)CacheCountType.Hit]); #endif return(@string); } #if CACHE_STATISTICS Interlocked.Increment( ref cacheCounts[(int)CacheCountType.Miss]); #endif #endif if (empty) { string result = GenericOps <string> .ListToString( this, Index.Invalid, Index.Invalid, ToStringFlags.None, separator, pattern, noCase); #if CACHE_STRINGLIST_TOSTRING if (canUseCachedString) { @string = result; } #endif return(result); } else { StringList result = new StringList(); foreach (string element in this) { if (String.IsNullOrEmpty(element)) { continue; } result.Add(element); } return(GenericOps <string> .ListToString( result, Index.Invalid, Index.Invalid, ToStringFlags.None, separator, pattern, noCase)); } }
/////////////////////////////////////////////////////////////////////// public static ReturnCode TryResolve( OptionDictionary options, string name, bool strict, bool noCase, ref IOption option, ref Result error ) { if (options != null) { if (name != null) { string exactName = null; StringList list = new StringList(); foreach (KeyValuePair <string, IOption> pair in options) { string key = pair.Key; IOption value = pair.Value; bool match; if (noCase || ((value != null) && value.IsNoCase(options))) { match = (String.Compare(key, 0, name, 0, name.Length, StringOps.SystemNoCaseStringComparisonType) == 0); } else { match = (String.Compare(key, 0, name, 0, name.Length, StringOps.SystemStringComparisonType) == 0); } if (match) { // // NOTE: Was the key valid (this should always succeed). // if (key != null) { // // NOTE: It was a match; however, was it an exact match? // if (key.Length == name.Length) { // // NOTE: Preserve match, it may differ in case. // exactName = key; } // // NOTE: Was it an exact match or did we match at least one // character in a partial match? // if ((key.Length == name.Length) || (name.Length > 0)) { // // NOTE: Store the exact or partial match in the results // dictionary. // list.Add(key); } } } } // // NOTE: If there was an exact match, just use it. // if (exactName != null) { // // NOTE: Normal case, an exact option match was found. // option = options[exactName]; return(ReturnCode.Ok); } else if (list.Count == 1) { // // NOTE: Normal case, exactly one option partially matched. // option = options[list[0]]; return(ReturnCode.Ok); } else if (list.Count > 1) { // // NOTE: They specified an ambiguous option. // error = AmbiguousOption(options, name, list); } else if (strict) { // // NOTE: They specified a non-existent option. // error = BadOption(options, name); } else { // // NOTE: Non-strict mode, leave the original option value // unchanged and let the caller deal with it. // return(ReturnCode.Ok); } } else { error = "invalid option name"; } } else { error = "invalid options"; } return(ReturnCode.Error); }