JLDDoc* JLDIO::parseText(std::string rawText) { rawText = findAndUseMacros(stripComments(rawText)); // std::cout << "findAndUseMacros result: \n" << rawText << "\n"; std::istringstream iss(rawText); return parseDoc(iss); }
Properties parseToPropertiesMap(std::istream& file) { Properties properties; std::string line; while (safeGetline(file, line)) { line = stripComments(line); boost::char_separator<char> sep("="); boost::tokenizer<boost::char_separator<char>> tok(line, sep); auto word = tok.begin(); if (word == tok.end()) { continue; } std::string key = stripWhitespace(*word); if (key == "") { continue; } if (++word == tok.end()) { continue; } std::string value = stripWhitespace(*word); properties[key] = value; } return properties; }
//================================================================== void Parser::doParse( DUT::MemFile &file ) { char lineBuff[1024]; Section curSection = SEC_UNDEF; int lineCnt = 0; while ( file.ReadTextLine( lineBuff, sizeof(lineBuff) ) ) { char lineWork[1024]; strcpy_s( lineWork, lineBuff ); stripComments( lineWork ); DUT::StrStripBeginEndWhite( lineWork ); if NOT( lineWork[0] ) { ++lineCnt; continue; } try { if ( handleShaderTypeDef( lineWork, curSection ) ) { ++lineCnt; continue; } if ( 0 == strcasecmp( lineWork, ".data" ) ) curSection = SEC_DATA; else if ( 0 == strcasecmp( lineWork, ".code" ) ) curSection = SEC_CODE; else if ( curSection == SEC_DATA ) { parseDataLine( lineWork, lineCnt ); } else if ( curSection == SEC_CODE ) { parseCodeLine( lineWork, lineCnt ); } } catch ( ... ) { printf( "For shader '%s' at line %i\n%i) %s\n", mpName, lineCnt+1, lineCnt+1, lineBuff ); throw; } ++lineCnt; } if ( mpShader->mType == SVM::Shader::TYPE_UNKNOWN ) onError( "Shader type undefined !" ); }
Dynamic::Var ParserImpl::parseImpl(const std::string& json) { if (_allowComments) { std::string str = json; stripComments(str); handle(str); } else handle(json); return asVarImpl(); }
vector<Mesh*> ModelLoaderOBJ::loadKeyFrame(const FileName &fileName) const { FileText::LINES rawLines = FileText::readLines(fileName); const LINES lines = getLines(rawLines); const LINES nc = stripComments(lines); const vector<vec3> verticesArray = read<vec3>(nc,"v", parseVertex); const vector<vec3> normalsArray = read<vec3>(nc,"vn",parseVertex); const vector<vec2> texcoordsArray = read<vec2>(nc,"vt",parseTexCoord); const vector<Face> facesArray = read<Face>(nc,"f", parseFace); return createKeyFrame(new Mesh(verticesArray, normalsArray, texcoordsArray, facesArray)); }
void WebGLShader::ShaderSource(const nsAString& source) { StripComments stripComments(source); const nsAString& cleanSource = Substring(stripComments.result().Elements(), stripComments.length()); if (!ValidateGLSLString(cleanSource, mContext, "shaderSource")) return; // We checked that the source stripped of comments is in the // 7-bit ASCII range, so we can skip the NS_IsAscii() check. const NS_LossyConvertUTF16toASCII sourceCString(cleanSource); if (mContext->gl->WorkAroundDriverBugs()) { const size_t maxSourceLength = 0x3ffff; if (sourceCString.Length() > maxSourceLength) { mContext->ErrorInvalidValue("shaderSource: Source has more than %d" " characters. (Driver workaround)", maxSourceLength); return; } } if (PR_GetEnv("MOZ_WEBGL_DUMP_SHADERS")) { printf_stderr("////////////////////////////////////////\n"); printf_stderr("// MOZ_WEBGL_DUMP_SHADERS:\n"); // Wow - Roll Your Own Foreach-Lines because printf_stderr has a hard-coded // internal size, so long strings are truncated. int32_t start = 0; int32_t end = sourceCString.Find("\n", false, start, -1); while (end > -1) { const nsCString line(sourceCString.BeginReading() + start, end - start); printf_stderr("%s\n", line.BeginReading()); start = end + 1; end = sourceCString.Find("\n", false, start, -1); } printf_stderr("////////////////////////////////////////\n"); } mSource = source; mCleanSource = sourceCString; }
/* * Tokenize takes a line number and an input string to tokenize. Will return * a vector of tokens with this line number noted in their values. */ void FixieTokenizer::tokenizeLine(int lineNumber, std::string input, std::vector<FixieTokenizer::token> *tokenized) { //Gets the chunks of the string std::vector<std::string> *chunked = chunk(stripComments(input)); //Drops in the line number with the chunks for error reporting for (int i = 0; i < chunked->size(); i++) { FixieTokenizer::token token; token.string = chunked->at(i); token.lineNumber = lineNumber; //Pushes the result into the tokenized array that gets passed in tokenized->push_back(token); } }
void WebGLShader::ShaderSource(const nsAString& source) { StripComments stripComments(source); const nsAString& cleanSource = Substring(stripComments.result().Elements(), stripComments.length()); if (!ValidateGLSLString(cleanSource, mContext, "shaderSource")) return; // We checked that the source stripped of comments is in the // 7-bit ASCII range, so we can skip the NS_IsAscii() check. NS_LossyConvertUTF16toASCII sourceCString(cleanSource); if (mContext->gl->WorkAroundDriverBugs()) { const size_t maxSourceLength = 0x3ffff; if (sourceCString.Length() > maxSourceLength) { mContext->ErrorInvalidValue("shaderSource: Source has more than %d" " characters. (Driver workaround)", maxSourceLength); return; } } // HACK - dump shader source { /* printf_stderr("//-*- glsl -*-\n"); // Wow - Roll Your Own For Each Lines because printf_stderr has a hard-coded internal size, so long strings are truncated. const nsString& src = shader->Source(); int32_t start = 0; int32_t end = src.Find("\n", false, start, -1); while (end > -1) { printf_stderr("%s\n", NS_ConvertUTF16toUTF8(nsDependentSubstring(src, start, end - start)).get()); start = end + 1; end = src.Find("\n", false, start, -1); } printf_stderr("//\n"); */ } // HACK mSource = source; mCleanSource = sourceCString; }
QString SqlUtils::batchExec(const QString& sql, const QString& connectionName/*=QSqlDatabase::defaultConnection*/) { QString errorText; if ( sql.size() > 0 ) { const QStringList stmts = splitQueries(sql); QSqlDatabase db = QSqlDatabase::database(connectionName); if ( stmts.count() == 0 ) return QString(); SqlTransaction transaction( db ); for (int i=0; i < stmts.count(); i++) { QString sqlstmt = stmts.at(i); stripComments(sqlstmt); if (sqlstmt.size() < 3 ) { //SQLDEBUG << "#" << i << ") SKIPPING small statement: " << sqlstmt; break; } //SQLDEBUG << QString("POST # %1 %2").arg(i).arg(sqlstmt); QSqlQuery q = db.exec( sqlstmt ); if (q.lastError().type() != QSqlError::NoError) { errorText = QObject::tr("Error in one of the batch statements. %1").arg(q.lastError().text()); qCritical() << QString::fromLatin1("%1.\nStatement: %2").arg(errorText).arg(sqlstmt); return errorText; } } transaction.commit(); return QString(); } else { errorText = QObject::tr("SQL statement passed was empty!!"); return errorText; } }
ConfigFileReader::ConfigFileReader(std::string fileName) { error = false; errorMessage = ""; keyValueMap = new std::map <std::string,std::string>; configFile.open(fileName.c_str(), ios::in); if (!configFile.is_open()) { error = true; errorMessage = "The config file could not be opened"; configFile.close(); return; } std::string* line; char buff [1024]; while (!configFile.eof()) { memset (buff, 0, 1024); configFile.getline (buff,1024); line = new std::string (buff); stripComments (*line); trimString (*line); if ((*line)!="" && (*line)[0]!='#') { // std::cout <<"debug: "<< *line << std::endl; processLine (*line); } delete line; line =0; } }
int main(int argc, char *argv[]){ /* input / output file defaults */ char * inputFilename = "irdetoexample.c"; char * outputFilename = "irdetoexample-clean.c"; /* Parse arguments, passing references to input / output file */ parseArgs(argc, argv, &inputFilename, &outputFilename); printf("Stripping Comments from File: %s\n\n", inputFilename); /* Get contents of file and put it in a character array */ char * stringToBeParsed = getFileContents(inputFilename); /* Output unstripped filecontents to screen - DEBUG - DELETE THIS*/ printf("File Contents before Stripping\n==============================\n%s", stringToBeParsed); stripComments(stringToBeParsed); saveStrippedContents(outputFilename, stringToBeParsed); return 0; }
int main(int argc, char *argv[]){ char * inputFilename = "cfile.c"; char * outputFilename = "output.c"; parseArgs(argc, argv, &inputFilename, &outputFilename); printf("Stripping Comments from File: %s\n\n", inputFilename); char * stringToBeParsed = getFileContents(inputFilename); printf("File Contents before Stripping\n==============================\n%s", stringToBeParsed); stripComments(stringToBeParsed); saveStrippedContents(outputFilename, stringToBeParsed); return 0; }
xmlFile::xmlFile( string _n ) : buffer( stripComments( stripHeader( ioFile::get( _n ) ) ) ), contents( &( buffer ) ), filename( _n ) { } &xmlFile::operator()()
string strip( string x ) { return stripComments( stripHeader( x ) ); }
/* Strips comments from the input if they are present */ void stripComments(char *input) { if (strstr(input, "//") != 0 || getBlockCommentState() || strstr(input, "/*")) { char *origI = input; LATBool isInSQuotes = false, isInDQuotes = false; LATBool blockedOutThisLine = false; while(*input) { switch(*input) { case '\'': if(!isInDQuotes) isInSQuotes = !isInSQuotes; break; case '"': if(!isInSQuotes) isInDQuotes = !isInDQuotes; break; case '/': if(!isInSQuotes && !isInDQuotes) { if(*(input+1) == '/') { /* Line comment */ *input = '\0'; } else if(*(input+1) == '*') { /* Block comment */ blockedOutThisLine = true; *input = '\0'; setBlockCommentState(1); } } break; case '*': if(!isInSQuotes && !isInDQuotes) { if(getBlockCommentState()) { if(*(input+1) == '/') { setBlockCommentState(0); input+=2; if(*input) { if(blockedOutThisLine) { char *oit = origI+strlen(origI); while(*input) { *oit++ = *input; input++; } /* cap the end */ *oit='\0'; } else { char *oit = origI; while(*input) { *oit++ = *input; input++; } /* cap the end */ *oit='\0'; } /* reset to the beginning, we may have more we need to go over */ input = origI; stripComments(input); return; } else { *origI = '\0'; } } } } } input++; } /* if we did NOT block out in this line, and we ARE blocked out, this line is dead to us, mark it as so */ if(!blockedOutThisLine && getBlockCommentState()) { *origI='\0'; } } }