std::string NodeMetadata::getString(const std::string &name, unsigned short recursion) const { StringMap::const_iterator it = m_stringvars.find(name); if (it == m_stringvars.end()) return ""; return resolveString(it->second, recursion); }
std::string TopicTemplate::getString(const std::string& varName) { std::stringstream ss; std::vector<Wt::WString> args; resolveString(varName, args, ss); return ss.str(); }
//returns : ERROR_OK, ERROR_INTEGRITY, ERROR_FREE_SPACE void extractFileToDir(LauncherProperties * props, WCHAR ** resultFile) { WCHAR * fileName = NULL; int64t * fileLength = NULL; DWORD crc = 0; writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "Extracting file ...", 1); readStringWithDebugW( props, & fileName, "file name"); fileLength = newint64_t(0, 0); readBigNumberWithDebug( props, fileLength, "file length "); readNumberWithDebug( props, &crc, "CRC32"); if(!isOK(props)) return; if(fileName!=NULL) { DWORD i=0; WCHAR * dir; resolveString(props, &fileName); for(i=0;i<getLengthW(fileName);i++) { if(fileName[i]==L'/') { fileName[i]=L'\\'; } } dir = getParentDirectory(fileName); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... extract to directory = ", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0, dir, 1); checkFreeSpace(props, dir, fileLength); FREE(dir); if(isOK(props)) { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... starting data extraction", 1); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... output file is ", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0, fileName, 1); extractDataToFile(props, fileName, fileLength, crc); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... extraction finished", 1); *resultFile = fileName; } else { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, " ... data extraction canceled", 1); } } else { writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "Error! File name can`t be null. Seems to be integrity error!", 1); *resultFile = NULL; props -> status = ERROR_INTEGRITY; } FREE(fileLength); return; }
void WTemplate::renderTemplateText(std::ostream& result, const WString& templateText) { std::string text; WApplication *app = WApplication::instance(); if (app && (encodeInternalPaths_ || app->session()->hasSessionIdInUrl())) { WFlags<RefEncoderOption> options; if (encodeInternalPaths_) options |= EncodeInternalPaths; if (app->session()->hasSessionIdInUrl()) options |= EncodeRedirectTrampoline; WString t = templateText; EncodeRefs(t, options); text = t.toUTF8(); } else text = templateText.toUTF8(); std::size_t lastPos = 0; std::vector<WString> args; std::vector<std::string> conditions; int suppressing = 0; for (std::size_t pos = text.find('$'); pos != std::string::npos; pos = text.find('$', pos)) { if (!suppressing) result << text.substr(lastPos, pos - lastPos); lastPos = pos; if (pos + 1 < text.length()) { if (text[pos + 1] == '$') { // $$ -> $ if (!suppressing) result << '$'; lastPos += 2; } else if (text[pos + 1] == '{') { std::size_t startName = pos + 2; std::size_t endName = text.find_first_of(" \r\n\t}", startName); args.clear(); std::size_t endVar = parseArgs(text, endName, args); if (endVar == std::string::npos) { LOG_ERROR("variable syntax error near \"" << text.substr(pos) << "\""); return; } std::string name = text.substr(startName, endName - startName); std::size_t nl = name.length(); if (nl > 2 && name[0] == '<' && name[nl - 1] == '>') { if (name[1] != '/') { std::string cond = name.substr(1, nl - 2); conditions.push_back(cond); if (suppressing || !conditionValue(cond)) ++suppressing; } else { std::string cond = name.substr(2, nl - 3); if (conditions.back() != cond) { LOG_ERROR("mismatching condition block end: " << cond); return; } conditions.pop_back(); if (suppressing) --suppressing; } } else { if (!suppressing) { std::size_t colonPos = name.find(':'); bool handled = false; if (colonPos != std::string::npos) { std::string fname = name.substr(0, colonPos); std::string arg0 = name.substr(colonPos + 1); args.insert(args.begin(), WString::fromUTF8(arg0)); if (resolveFunction(fname, args, result)) handled = true; else args.erase(args.begin()); } if (!handled) resolveString(name, args, result); } } lastPos = endVar + 1; } else { if (!suppressing) result << '$'; // $. -> $. lastPos += 1; } } else { if (!suppressing) result << '$'; // $ at end of template -> $ lastPos += 1; } pos = lastPos; } result << text.substr(lastPos); }
bool WTemplate::renderTemplateText(std::ostream& result, const WString& templateText) { errorText_ = ""; std::string text; if (encodeTemplateText_) text = encode(templateText.toUTF8()); else text = templateText.toUTF8(); std::size_t lastPos = 0; std::vector<WString> args; std::vector<std::string> conditions; int suppressing = 0; for (std::size_t pos = text.find('$'); pos != std::string::npos; pos = text.find('$', pos)) { if (!suppressing) result << text.substr(lastPos, pos - lastPos); lastPos = pos; if (pos + 1 < text.length()) { if (text[pos + 1] == '$') { // $$ -> $ if (!suppressing) result << '$'; lastPos += 2; } else if (text[pos + 1] == '{') { std::size_t startName = pos + 2; std::size_t endName = text.find_first_of(" \r\n\t}", startName); args.clear(); std::size_t endVar = parseArgs(text, endName, args); if (endVar == std::string::npos) { std::stringstream errorStream; errorStream << "variable syntax error near \"" << text.substr(pos) << "\""; errorText_ = errorStream.str(); LOG_ERROR(errorText_); return false; } std::string name = text.substr(startName, endName - startName); std::size_t nl = name.length(); if (nl > 2 && name[0] == '<' && name[nl - 1] == '>') { if (name[1] != '/') { std::string cond = name.substr(1, nl - 2); conditions.push_back(cond); if (suppressing || !conditionValue(cond)) ++suppressing; } else { std::string cond = name.substr(2, nl - 3); if (conditions.empty() || conditions.back() != cond) { std::stringstream errorStream; errorStream << "mismatching condition block end: " << cond; errorText_ = errorStream.str(); LOG_ERROR(errorText_); return false; } conditions.pop_back(); if (suppressing) --suppressing; } } else { if (!suppressing) { std::size_t colonPos = name.find(':'); bool handled = false; if (colonPos != std::string::npos) { std::string fname = name.substr(0, colonPos); std::string arg0 = name.substr(colonPos + 1); args.insert(args.begin(), WString::fromUTF8(arg0)); if (resolveFunction(fname, args, result)) handled = true; else args.erase(args.begin()); } if (!handled) resolveString(name, args, result); } } lastPos = endVar + 1; } else { if (!suppressing) result << '$'; // $. -> $. lastPos += 1; } } else { if (!suppressing) result << '$'; // $ at end of template -> $ lastPos += 1; } pos = lastPos; } result << text.substr(lastPos); return true; }
/** * @brief Creates the StringStorage * **/ StringStorage() { emptyString = resolveString(""); }