do string replacements in the right order

metadata
Wenzel Jakob 2012-04-24 23:55:28 -04:00
parent f6c999525f
commit d7066893c8
6 changed files with 15 additions and 7 deletions

View File

@ -21,7 +21,7 @@ would like to experiment with such techniques that haven't yet found
their way into mainstream renderers, and it also provides a solid
foundation for research in this domain.
Other design considerations are are:
Other design considerations are:
\parheader{Performance:}
Mitsuba provides optimized implementations of the most commonly

View File

@ -76,6 +76,15 @@ template<class Iterator> std::string containerToString(const Iterator &start, co
return oss.str();
}
/// Simple functor for sorting string parameters by length and content
struct SimpleStringOrdering {
bool operator()(const std::string &a, const std::string &b) const {
if (a.length() == b.length())
return a < b;
return a.length() < b.length();
}
};
//! @}
// -----------------------------------------------------------------------

View File

@ -60,7 +60,7 @@ private:
class MTS_EXPORT_RENDER SceneHandler : public HandlerBase {
public:
typedef std::map<std::string, ConfigurableObject *> NamedObjectMap;
typedef std::map<std::string, std::string> ParameterMap;
typedef std::map<std::string, std::string, SimpleStringOrdering> ParameterMap;
SceneHandler(const SAXParser *parser, const ParameterMap &params,
NamedObjectMap *objects = NULL, bool isIncludedFile = false);

View File

@ -41,7 +41,7 @@ public:
MTS_DECLARE_CLASS()
protected:
typedef std::map<std::string, std::string> ParameterMap;
typedef std::map<std::string, std::string, SimpleStringOrdering> ParameterMap;
/// Virtual destructor
virtual ~Utility() { }

View File

@ -105,11 +105,10 @@ void SceneHandler::startElement(const XMLCh* const xmlName,
ParseContext context((name == "scene") ? NULL : &m_context.top());
/* Convert attributes to ISO-8859-1 */
for (unsigned int i=0; i<xmlAttributes.getLength(); i++) {
for (size_t i=0; i<xmlAttributes.getLength(); i++) {
std::string attrValue = transcode(xmlAttributes.getValue(i));
if (attrValue.length() > 0 && attrValue.find('$') != attrValue.npos) {
for (std::map<std::string, std::string>::const_iterator it = m_params.begin();
it != m_params.end(); ++it) {
for (ParameterMap::const_reverse_iterator it = m_params.rbegin(); it != m_params.rend(); ++it) {
std::string::size_type pos = 0;
std::string searchString = "$" + it->first;
while ((pos = attrValue.find(searchString, pos)) != std::string::npos) {

View File

@ -127,7 +127,7 @@ int mts_main(int argc, char **argv) {
ELogLevel logLevel = EInfo;
ref<FileResolver> fileResolver = Thread::getThread()->getFileResolver();
bool testCaseMode = false, treatWarningsAsErrors = false;
std::map<std::string, std::string> parameters;
std::map<std::string, std::string, SimpleStringOrdering> parameters;
int blockSize = 32;
int flushTimer = -1;