int CfgFile::getKeyValue(std::string &sLine, const size_t startPos) { // we found the key now get the value size_t valueBegin = sLine.find_first_not_of(" =\t", startPos); if (valueBegin == std::string::npos) return 1; // syntax error, we ignore the block (comment or end of line) size_t valueEnd; if (sLine[valueBegin] == '\"') { // find a second '"' which is not escaped valueBegin++; valueEnd = findFirstNotEscapedOf(sLine, "\"", valueBegin); if (valueEnd == std::string::npos) return 1; // syntax error, we ignore the block (comment or end of line) sLine = sLine.substr(valueBegin, valueEnd - valueBegin); unescapeString(sLine); } else { valueEnd = sLine.find_last_not_of(" \t"); if (valueEnd == std::string::npos) return 1; // syntax error, we ignore the block (comment or end of line) valueEnd++; sLine = sLine.substr(valueBegin, valueEnd - valueBegin); removeWhite(sLine); unescapeString(sLine); } return 0; }
Sexp* parse() { Sexp* ret; int t = yylex(); if(t == TOKEN) { ret = new Sexp; ret->val = copyString(yytext); ret->next = NULL; ret->list = NULL; } else if(t == STRING) { ret = new Sexp; ret->val = unescapeString(yytext); ret->next = NULL; ret->list = NULL; } else if(t == LPAREN) { ret = parseList(); } else { ret = NULL; } return ret; }
void LocalisedStrings::loadFromText (const String& fileContents, bool ignoreCase) { translations.setIgnoresCase (ignoreCase); StringArray lines; lines.addLines (fileContents); for (int i = 0; i < lines.size(); ++i) { String line (lines[i].trim()); if (line.startsWithChar ('"')) { int closeQuote = findCloseQuote (line, 1); const String originalText (unescapeString (line.substring (1, closeQuote))); if (originalText.isNotEmpty()) { const int openingQuote = findCloseQuote (line, closeQuote + 1); closeQuote = findCloseQuote (line, openingQuote + 1); const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote))); if (newText.isNotEmpty()) translations.set (originalText, newText); } } else if (line.startsWithIgnoreCase ("language:")) { languageName = line.substring (9).trim(); } else if (line.startsWithIgnoreCase ("countries:")) { countryCodes.addTokens (line.substring (10).trim(), true); countryCodes.trim(); countryCodes.removeEmptyStrings(); } } translations.minimiseStorageOverheads(); }
static std::string extractString(std::string str, std::string filename, int lineNum) { size_t firstQuote = str.find_first_of('\"'); size_t lastQuote = str.find_last_of('\"'); if(firstQuote == std::string::npos || lastQuote == std::string::npos) { fprintf(stderr, "%s:%d: Missing opening or closing quotes!\n", filename.c_str(), lineNum); return ""; } return convertUTF8ToISO8859_1(unescapeString(str.substr(firstQuote+1, lastQuote-firstQuote-1))); }
Sexp* parseList() { Sexp* ret = new Sexp; ret->val = NULL; ret->list = NULL; ret->next = NULL; Sexp* last = NULL; Sexp* next = NULL; int t = yylex(); while(true) { if(t == RPAREN || t == END) { return ret; } if(t == TOKEN) { next = new Sexp; next->val = copyString(yytext); next->next = NULL; next->list = NULL; } if(t == STRING) { next = new Sexp; next->val = unescapeString(yytext); next->next = NULL; next->list = NULL; } if(t == LPAREN) { next = parseList(); } if(!last) { ret->list = next; } else { last->next = next; } last = next; t = yylex(); } }
/** * Get compile error info from CodeForces * @param bott Result bott file * @return Compile error info */ string CFJudger::getCEinfo(Bott * bott) { string csrf = getCsrfParams("http://codeforces.com/problemset/submit"); prepareCurl(); curl_easy_setopt(curl, CURLOPT_URL, "http://codeforces.com/data/judgeProtocol"); string post = (string) "submissionId=" + bott->Getremote_runid() + "&csrf_token=" + csrf; curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str()); performCurl(); string info = loadAllFromFile(tmpfilename); string result; if (!RE2::FullMatch(info, "\"(.*)\"", &result)) { return ""; } return unescapeString(result); }
/** * From idl/base.php:get_serialized_default() */ fbstring PhpParam::getDefaultSerialized() const { auto valIt = m_param.find("value"); if (valIt == m_param.items().end()) { return ""; // No default } auto dval = valIt->second; if (!dval.isString()) { throw std::logic_error( folly::format("Parameter '{0}' default value is non-string", m_name).str() ); } auto val = dval.asString(); if (!val.size()) { throw std::logic_error( folly::format("Parameter '{0}' default value malformed (empty string), " "specify \"\" as default value for actual empty string", m_name).str() ); } // Function calls "foo()" or "foo::bar()" to C/C++ functions/static methods, // a constant, or a bitmask of constants // // Used by ext_reflection to resolve the value at runtime or // represent the function/method call. if ((val.size() > 2) && (!strncmp(val.c_str(), "k_", 2) || !strncmp(val.c_str(), "q_", 2) || !strcmp(val.c_str() + val.size() - 2, "()"))) { return "\x01"; } // Fixed substitutions auto it = g_serializedDefaults.find(val); if (it != g_serializedDefaults.end()) { return it->second; } if (val == "RAND_MAX") { return folly::to<fbstring>("i:", RAND_MAX, ";"); } // Quoted string: "foo" if ((val.size() >= 2) && (val[0] == '"') && (val[val.size()-1] == '"')) { auto s = unescapeString(val.substr(1, val.size() - 2)); return phpSerialize(s); } // Integers and Floats if (strchr(val.c_str(), '.')) { // Decimal float? char *e = nullptr; double dval = strtod(val.c_str(), &e); if (e && !*e) { return folly::to<fbstring>("d:", dval, ";"); } } if (val[0] == '0') { if ((val.size() > 1) && (val[1] == 'x')) { // Hex? char *e = nullptr; long lval = strtol(val.c_str() + 2, &e, 16); if (e && !*e) { return folly::to<fbstring>("i:", lval, ";"); } } else { // Octal? char *e = nullptr; long lval = strtol(val.c_str() + 1, &e, 8); if (e && !*e) { return folly::to<fbstring>("i:", lval, ";"); } } } // Decimal? char *e = nullptr; long lval = strtol(val.c_str(), &e, 10); if (e && !*e) { return folly::to<fbstring>("i:", lval, ";"); } throw std::logic_error( folly::format("'{0}' is not a valid default arg value", val).str() ); }
static llvm::Value* codegenImmediateLLVM(Immediate* i) { GenInfo* info = gGenInfo; llvm::Value* ret = NULL; switch(i->const_kind) { case NUM_KIND_BOOL: switch(i->num_index) { case BOOL_SIZE_1: case BOOL_SIZE_SYS: case BOOL_SIZE_8: ret = llvm::ConstantInt::get( llvm::Type::getInt8Ty(info->module->getContext()), i->bool_value()); break; case BOOL_SIZE_16: ret = llvm::ConstantInt::get( llvm::Type::getInt16Ty(info->module->getContext()), i->bool_value()); break; case BOOL_SIZE_32: ret = llvm::ConstantInt::get( llvm::Type::getInt32Ty(info->module->getContext()), i->bool_value()); break; case BOOL_SIZE_64: ret = llvm::ConstantInt::get( llvm::Type::getInt64Ty(info->module->getContext()), i->bool_value()); break; } break; case NUM_KIND_UINT: switch(i->num_index) { case INT_SIZE_8: ret = llvm::ConstantInt::get( llvm::Type::getInt8Ty(info->module->getContext()), i->uint_value()); break; case INT_SIZE_16: ret = llvm::ConstantInt::get( llvm::Type::getInt16Ty(info->module->getContext()), i->uint_value()); break; case INT_SIZE_32: ret = llvm::ConstantInt::get( llvm::Type::getInt32Ty(info->module->getContext()), i->uint_value()); break; case INT_SIZE_64: ret = llvm::ConstantInt::get( llvm::Type::getInt64Ty(info->module->getContext()), i->uint_value()); break; } break; case NUM_KIND_INT: switch(i->num_index) { case INT_SIZE_8: ret = llvm::ConstantInt::get( llvm::Type::getInt8Ty(info->module->getContext()), i->int_value(), true); break; case INT_SIZE_16: ret = llvm::ConstantInt::get( llvm::Type::getInt16Ty(info->module->getContext()), i->int_value(), true); break; case INT_SIZE_32: ret = llvm::ConstantInt::get( llvm::Type::getInt32Ty(info->module->getContext()), i->int_value(), true); break; case INT_SIZE_64: ret = llvm::ConstantInt::get( llvm::Type::getInt64Ty(info->module->getContext()), i->int_value(), true); break; } break; case NUM_KIND_REAL: case NUM_KIND_IMAG: switch(i->num_index) { case FLOAT_SIZE_32: ret = llvm::ConstantFP::get( llvm::Type::getFloatTy(info->module->getContext()), i->v_float32); break; case FLOAT_SIZE_64: ret = llvm::ConstantFP::get( llvm::Type::getDoubleTy(info->module->getContext()), i->v_float64); break; } break; case NUM_KIND_COMPLEX: switch(i->num_index) { case COMPLEX_SIZE_64: { std::vector<llvm::Constant *> elements(2); elements[0] = llvm::ConstantFP::get( llvm::Type::getFloatTy(info->module->getContext()), i->v_complex64.r); elements[1] = llvm::ConstantFP::get( llvm::Type::getFloatTy(info->module->getContext()), i->v_complex64.i); ret = llvm::ConstantStruct::get( llvm::cast<llvm::StructType>(getTypeLLVM("_complex64")), elements); break; } case COMPLEX_SIZE_128: { std::vector<llvm::Constant *> elements(2); elements[0] = llvm::ConstantFP::get( llvm::Type::getDoubleTy(info->module->getContext()), i->v_complex128.r); elements[1] = llvm::ConstantFP::get( llvm::Type::getDoubleTy(info->module->getContext()), i->v_complex128.i); ret = llvm::ConstantStruct::get( llvm::cast<llvm::StructType>(getTypeLLVM("_complex128")), elements); break; } } break; case CONST_KIND_STRING: // Note that string immediate values are stored // with C escapes - that is newline is 2 chars \ n // so we have to convert to a sequence of bytes // for LLVM (the C backend can just print it out). std::string newString = unescapeString(i->v_string, NULL); ret = info->builder->CreateGlobalString(newString); break; } return ret; }