bool HyphDictionaryList::open(lString16 hyphDirectory, bool clear) { CRLog::info("HyphDictionaryList::open(%s)", LCSTR(hyphDirectory) ); if (clear) { _list.clear(); addDefault(); } if ( hyphDirectory.empty() ) return true; //LVAppendPathDelimiter( hyphDirectory ); LVContainerRef container; LVStreamRef stream; if ( (hyphDirectory.endsWith("/") || hyphDirectory.endsWith("\\")) && LVDirectoryExists(hyphDirectory) ) { container = LVOpenDirectory( hyphDirectory.c_str(), L"*.*" ); } else if ( LVFileExists(hyphDirectory) ) { stream = LVOpenFileStream( hyphDirectory.c_str(), LVOM_READ ); if ( !stream.isNull() ) container = LVOpenArchieve( stream ); } if ( !container.isNull() ) { int len = container->GetObjectCount(); int count = 0; CRLog::info("%d items found in hyph directory", len); for ( int i=0; i<len; i++ ) { const LVContainerItemInfo * item = container->GetObjectInfo( i ); lString16 name = item->GetName(); lString16 suffix; HyphDictType t = HDT_NONE; if ( name.endsWith(".pdb") ) { suffix = "_hyphen_(Alan).pdb"; t = HDT_DICT_ALAN; } else if ( name.endsWith(".pattern") ) { suffix = ".pattern"; t = HDT_DICT_TEX; } else continue; lString16 filename = hyphDirectory + name; lString16 id = name; lString16 title = name; if ( title.endsWith( suffix ) ) title.erase( title.length() - suffix.length(), suffix.length() ); _list.add( new HyphDictionary( t, title, id, filename ) ); count++; } CRLog::info("%d dictionaries added to list", _list.length()); return true; } else { CRLog::info("no hyphenation dictionary items found in hyph directory %s", LCSTR(hyphDirectory)); } return false; }
void CFilterMan::load () { m_Filters.clear (); int count = getInt (szCount); for (int i = 0; i < count; i++) { CString name; name.Format (szFilterName, i); CString filter; filter.Format (szFilter, i); CString name_value = getString (name); CString filter_value = getString (filter); if (!name_value.IsEmpty () && !filter_value.IsEmpty ()) addFilter (name_value, filter_value); } if (m_Filters.size () == 0) addDefault (); }
void ContentTypes::addImageTypes(const QStringList &imageTypes) { foreach (QString type, imageTypes) addDefault(type, QStringLiteral("image/") + type); }
/** * Create a script line from a syntax parser. */ ScriptLine* ScriptLineBlock::createLine(SyntaxParser* parser) { // create an anonymous block auto blockParser = parser->block(); if ( blockParser ) { auto block = new ScriptAnonymousBlock(this); block->addScript( blockParser->match() ); return block; } // create an expression auto exprParser = parser->expression(); if ( exprParser ) { Kernel::EParser expr; expr.parse( exprParser->match() ); if ( expr.name() == ":=" ) { if ( expr.size() != 2 ) { throw std::runtime_error("ScriptLineBlock:: syntax error: " + expr.str() ); } auto e = Expression_ptr(new Expression(m_local_namespace, expr[1]) ); auto setLine = new ScriptLineSet( m_local_namespace, expr[0].name(), e ); return setLine; } else { auto e = Expression_ptr(new Expression(m_local_namespace, expr) ); return new ScriptLineExpression( m_local_namespace, e ); } } // declare a variable auto varParser = parser->defVar(); if ( varParser ) { std::string value = varParser->value() ? varParser->value()->match() : ""; auto line = new ScriptLineDef(m_local_namespace, varParser->type()->match(), varParser->var()->match(), value); return line; } // an if-block auto ifParser = parser->ifBlock(); if ( ifParser ) { auto cond = ifParser->condition(); auto trueBlock = ifParser->trueBlock(); auto elseBlock = ifParser->elseBlock(); std::string condStr(cond->getInnerStart(), cond->getInnerEnd()); std::string trueScript(trueBlock->getInnerStart(), trueBlock->getInnerEnd()); // create the if line instance auto ifLine = new ScriptLineIf(m_local_namespace); // create the first condition expression Kernel::EParser expr; expr.parse( condStr ); auto e = Expression_ptr(new Expression(m_local_namespace, expr) ); // add first condition auto block = new ScriptAnonymousBlock(this); block->addScript( trueScript ); ifLine->addCondition(e, ScriptLine_ptr(block) ); // add the else block std::string elseScript; if ( elseBlock ) { elseScript.assign(elseBlock->getInnerStart(), elseBlock->getInnerEnd()); auto block = new ScriptAnonymousBlock(this); block->addScript( trueScript ); ifLine->addDefault( ScriptLine_ptr(block) ); } return ifLine; } return nullptr; }