StringList Include::Evaluate(EvaluationContext& context) { // check include depth size_t includeDepth = context.IncludeDepth(); if (includeDepth >= util::kIncludeDepthLimit) { std::stringstream message; message << "Reached include depth limit (" << util::kIncludeDepthLimit << ")"; throw EvaluationException(message.str()); } context.SetIncludeDepth(includeDepth + 1); StringList fileNames = fFileNames->Evaluate(context); if (!fileNames.IsEmpty()) { // Only the file referred to by the first element is included. // bind the target data::Target* target = context.Targets().LookupOrCreate(fileNames.ElementAt(0)); String filePath; data::FileStatus fileStatus; data::TargetBinder::Bind(*context.GlobalVariables(), target, filePath, fileStatus); // open the file std::ifstream file(filePath.ToCString()); if (file.fail()) { if (target->IsIgnoreIfMissing()) return StringList::False(); throw EvaluationException( std::string("include: Failed to open file \"") + filePath.ToCString() + "\""); } // parse and evaluate it parser::Parser parser; parser.SetFileName(filePath.ToStlString()); util::Reference<code::Block> block(parser.Parse(file), true); block->Evaluate(context); if (context.GetJumpCondition() == JUMP_CONDITION_JUMP_TO_EOF) context.SetJumpCondition(JUMP_CONDITION_NONE); } // reset include depth context.SetIncludeDepth(includeDepth); return StringList::False(); }
void LoadFiltersFromGlobalString( const IsoString& globalKey ) { filters.Clear(); String s = PixInsightSettings::GlobalString( globalKey ); if ( !s.IsEmpty() ) { for ( size_type p = 0; ; ) { size_type p1 = s.Find( '(', p ); if ( p1 == String::notFound ) break; size_type p2 = s.Find( ')', p1 ); if ( p2 == String::notFound ) break; String extStr = s.Substring( p1, p2-p1 ); if ( !extStr.IsEmpty() ) { StringList extLst; extStr.Break( extLst, ' ', true ); if ( !extLst.IsEmpty() ) { FileFilter filter; for ( StringList::const_iterator i = extLst.Begin(); i != extLst.End(); ++i ) { size_type d = i->Find( '.' ); if ( d != String::notFound ) filter.AddExtension( i->Substring( d ) ); } if ( !filter.Extensions().IsEmpty() ) { String desc = s.Substring( p, p1-p ); desc.Trim(); filter.SetDescription( desc ); filters.Add( filter ); } } } p = p2 + 1; } } }
StringList StringListOperations::Apply(const StringList& inputList, size_t maxSize, const behavior::Behavior& behavior) const { if (!HasOperations()) return inputList.SubList(0, maxSize); uint32_t operations = fOperations; bool hasSelectorOperation = (operations & PATH_PART_SELECTOR_MASK) != 0; bool hasPathPartOperation = hasSelectorOperation || (operations & (PATH_PART_REPLACER_MASK | TO_PARENT_DIRECTORY)) != 0; if (hasPathPartOperation && !hasSelectorOperation) { // Only replacer operations. Continue as if all path parts are selected. operations |= PATH_PART_SELECTOR_MASK; } // If a join shall be performed before to-upper/to-lower, we simply convert // the join parameter first and join as usual afterwards. String joinParameterBuffer; StringPart joinParameter = fJoinParameter; if (!joinParameter.IsEmpty() && (operations & (TO_UPPER | TO_LOWER)) != 0 && behavior.GetJoinCaseOperator() == behavior::Behavior::JOIN_BEFORE_CASE_OPERATOR) { joinParameterBuffer = joinParameter; if ((operations & TO_UPPER) != 0) joinParameterBuffer.ToUpper(); else joinParameterBuffer.ToLower(); joinParameter = joinParameterBuffer; } StringList resultList; StringBuffer buffer; const StringList& list = inputList.IsEmpty() && (operations & REPLACE_EMPTY) != 0 ? StringList(String(fEmptyParameter)) : inputList; size_t count = std::min(list.Size(), maxSize); for (size_t i = 0; i < count; i++) { String string = list.ElementAt(i); size_t bufferSizeBeforeElement = buffer.Length(); // If any of the file name/path part selectors/replacers need to be // applied, we disassemble the string, make the modifications, and // reassemble it. if (hasPathPartOperation) { Path::Parts parts(string); if ((operations & REPLACE_GRIST) != 0) parts.SetGrist(fGristParameter); else if ((operations & SELECT_GRIST) == 0) parts.UnsetGrist(); if ((operations & REPLACE_ROOT) != 0) parts.SetRoot(fRootParameter); else if ((operations & SELECT_ROOT) == 0) parts.UnsetRoot(); if ((operations & REPLACE_DIRECTORY) != 0) parts.SetDirectory(fDirectoryParameter); else if ((operations & SELECT_DIRECTORY) == 0) parts.UnsetDirectory(); if ((operations & REPLACE_BASE_NAME) != 0) parts.SetBaseName(fBaseNameParameter); else if ((operations & SELECT_BASE_NAME) == 0) parts.UnsetBaseName(); if ((operations & REPLACE_SUFFIX) != 0) parts.SetSuffix(fSuffixParameter); else if ((operations & SELECT_SUFFIX) == 0) parts.UnsetSuffix(); if ((operations & REPLACE_ARCHIVE_MEMBER) != 0) parts.SetArchiveMember(fArchiveMemberParameter); else if ((operations & SELECT_ARCHIVE_MEMBER) == 0) parts.UnsetArchiveMember(); if ((operations & TO_PARENT_DIRECTORY) != 0) { parts.UnsetBaseName(); parts.UnsetSuffix(); parts.UnsetArchiveMember(); } parts.GetPath(buffer, behavior); } else buffer += string; if ((operations & TO_UPPER) != 0) { char* toConvert = buffer.Data() + bufferSizeBeforeElement; char* end = buffer.Data() + buffer.Length(); std::transform(toConvert, end, toConvert, ::toupper); } else if ((operations & TO_LOWER) != 0) { char* toConvert = buffer.Data() + bufferSizeBeforeElement; char* end = buffer.Data() + buffer.Length(); std::transform(toConvert, end, toConvert, ::tolower); } if ((operations & JOIN) != 0) { if (i + 1 < count) buffer += joinParameter; } else { resultList.Append(buffer); buffer = StringPart(); } } if ((operations & JOIN) != 0 && count > 0) { // Append the joined value, if we're not emulating the broken behavior // of jam. if (behavior.GetBrokenSubscriptJoin() == behavior::Behavior::NO_BROKEN_SUBSCRIPT_JOIN || count == list.Size()) { resultList.Append(buffer); } } return resultList; }