// Shared implementation used by test and exec. MatchResult RegExpObject::match(ExecState* exec, JSString* string) { RegExp* regExp = this->regExp(); RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor(); String input = string->value(exec); VM& vm = exec->vm(); if (!regExp->global()) return regExpConstructor->performMatch(vm, regExp, string, input, 0); JSValue jsLastIndex = getLastIndex(); unsigned lastIndex; if (LIKELY(jsLastIndex.isUInt32())) { lastIndex = jsLastIndex.asUInt32(); if (lastIndex > input.length()) { setLastIndex(exec, 0); return MatchResult::failed(); } } else { double doubleLastIndex = jsLastIndex.toInteger(exec); if (doubleLastIndex < 0 || doubleLastIndex > input.length()) { setLastIndex(exec, 0); return MatchResult::failed(); } lastIndex = static_cast<unsigned>(doubleLastIndex); } MatchResult result = regExpConstructor->performMatch(vm, regExp, string, input, lastIndex); setLastIndex(exec, result.end); return result; }
returnValue VariablesGrid::appendTimes( const VariablesGrid& arg, MergeMethod _mergeMethod ) { // nothing to do for empty grids if ( arg.getNumPoints( ) == 0 ) return SUCCESSFUL_RETURN; if ( getNumPoints( ) == 0 ) { *this = arg; return SUCCESSFUL_RETURN; } // consistency check if ( acadoIsGreater( arg.getFirstTime( ),getLastTime( ) ) == BT_FALSE ) return ACADOERROR( RET_INVALID_ARGUMENTS ); if ( acadoIsEqual( getLastTime( ),arg.getFirstTime( ) ) == BT_FALSE ) { // simply append for( uint i=0; i<arg.getNumPoints( ); ++i ) addMatrix( *(arg.values[i]),arg.getTime( i ) ); } else { // if last and first time point coincide, merge as specified switch ( _mergeMethod ) { case MM_KEEP: break; case MM_REPLACE: setVector( getLastIndex(),arg.getFirstVector( ) ); break; case MM_DUPLICATE: addMatrix( *(arg.values[0]),arg.getTime( 0 ) ); break; } // simply append all remaining points for( uint i=1; i<arg.getNumPoints( ); ++i ) addMatrix( *(arg.values[i]),arg.getTime( i ) ); } return SUCCESSFUL_RETURN; }
// Shared implementation used by test and exec. bool RegExpObject::match(ExecState* exec) { RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor(); UString input = exec->argument(0).toString(exec); JSGlobalData* globalData = &exec->globalData(); if (!regExp()->global()) { int position; int length; regExpConstructor->performMatch(*globalData, d->regExp.get(), input, 0, position, length); return position >= 0; } JSValue jsLastIndex = getLastIndex(); unsigned lastIndex; if (LIKELY(jsLastIndex.isUInt32())) { lastIndex = jsLastIndex.asUInt32(); if (lastIndex > input.length()) { setLastIndex(0); return false; } } else { double doubleLastIndex = jsLastIndex.toInteger(exec); if (doubleLastIndex < 0 || doubleLastIndex > input.length()) { setLastIndex(0); return false; } lastIndex = static_cast<unsigned>(doubleLastIndex); } int position; int length = 0; regExpConstructor->performMatch(*globalData, d->regExp.get(), input, lastIndex, position, length); if (position < 0) { setLastIndex(0); return false; } setLastIndex(position + length); return true; }
GLvoid CLogger::setEntryEnd(const char *text, ...) { GLint ref = getLastIndex(); static bool first_line=true; if (first_line) { SYSTEMTIME systime; GetSystemTime(&systime); char date[100]; sprintf(date,"%d.%d.%d - %d:%d:%d",systime.wDay,systime.wMonth,systime.wYear,systime.wHour,systime.wMinute,systime.wSecond); FILE *log_file=fopen("logger.log","wc"); if (!log_file) { return; } first_line=false; char string[100]; sprintf(string,"New entry: %s\n------------------------------\n",date); fwrite(string,1,strlen(string),log_file); fclose(log_file); } char string[256]; va_list ap; if (text == NULL) { return; } va_start(ap,text); GLint string_length=vsprintf(string,text,ap); va_end(ap); FILE *log_file=fopen("logger.log","a"); if (!log_file) { return; } if (ref==-1) { string[string_length]='\n'; } if (ref!=-1) { char line[256]; for (int i=0; i<256; i++) { line[i] = ' '; } for (int i=0; i<string_length; i++) { line[i] = string[i]; } string_length=sprintf(string,"Time taken: %d ms\n",timeGetTime()-st[ref]); memcpy(line+64,string,string_length); fwrite(line,1,string_length+64,log_file); } fclose(log_file); }
//This function construct an INSERT SQL and execute it againts the database. QList<TfieldDef > createSQL(QSqlDatabase db,QVariantMap jsonData,QString table,QList< TfieldDef> fields,QList< TfieldDef> parentkeys,bool mTable = false, QVariantMap jsonData2 = emptyMap) { QString sqlHeader; QString sqlValues; QString sql; QVariant variantValue; int pos; QList<TfieldDef > resKeys; QString fieldValue; int tblIndex; //log("Table:" + table); tblIndex = getLastIndex(table); sqlHeader = "INSERT INTO " + table + "("; sqlValues = " VALUES ("; for (pos = 0; pos <= parentkeys.count()-1;pos++) { sqlHeader = sqlHeader + parentkeys[pos].name + ","; sqlValues = sqlValues + "'" + parentkeys[pos].value + "',"; } for (pos = 0; pos <= fields.count()-1;pos++) { // If a new key is found in the list of fields // then we added to the result of keys that will be passes to any possible child table if (fields[pos].key == true) { TfieldDef key; key.key = true; key.name = fields[pos].name; key.xmlCode = fields[pos].xmlCode; key.value = extractNumber(jsonData[fields[pos].xmlCode].toString()); key.value = key.value.simplified(); // If its empty. The try to find it in jsonData2 // This happens when the cover information is stored in a repeat of one // so part of the information for the main table must be searched in jsonData // and part in jsonData2 if (key.value.isEmpty()) { key.value = jsonData2[fields[pos].xmlCode].toString(); key.value = key.value.simplified(); } //If the key is empty (Normal as in the JSON such key does not exist) set the key value to tblIndex if (key.value.isEmpty()) { if (!mTable) { key.value = QString::number(tblIndex); sqlHeader = sqlHeader + key.name + ","; sqlValues = sqlValues + "'" + QString::number(tblIndex) + "',"; } else { key.value = ""; sqlHeader = sqlHeader + key.name + ","; sqlValues = sqlValues + "'',"; } } else { sqlHeader = sqlHeader + key.name + ","; sqlValues = sqlValues + "'" + fixString(key.value) + "',"; } //Append the key to the list of returned keys key.value = key.value; resKeys.append(key); } else { sqlHeader = sqlHeader + fields[pos].name + ","; if (mainTable == table) { if (fields[pos].name == "surveyid") sqlValues = sqlValues + "'" + fileID + "',"; else { if (fields[pos].name == "originid") sqlValues = sqlValues + "'FORMHUB-JSON',"; else { fieldValue = fixString(jsonData[fields[pos].xmlCode].toString()); if (fieldValue.isEmpty()) { // This happens when the cover information is stored in a repeat of one // so part of the information for the main table must be searched in jsonData // and part in jsonData2 fieldValue = fixString(jsonData2[fields[pos].xmlCode].toString()); } sqlValues = sqlValues + "'" + fieldValue + "',"; } } } else { variantValue = jsonData[fields[pos].xmlCode]; fieldValue = QString::fromUtf8(variantValue.toByteArray()); if (fieldValue.isEmpty()) { // This happens when the cover information is stored in a repeat of one // so part of the information for the main table must be searched in jsonData // and part in jsonData2 variantValue = jsonData2[fields[pos].xmlCode]; fieldValue = QString::fromUtf8(variantValue.toByteArray()); } sqlValues = sqlValues + "'" + fixString(fieldValue) + "',"; } } } //Removing final , and appending ) sqlHeader = sqlHeader.left(sqlHeader.length()-1) + ")"; sqlValues = sqlValues.left(sqlValues.length()-1) + ")"; //Create the final sql sql = sqlHeader + " " + sqlValues; //Change all empty valued to NULL. This minimize foreign key errors in skips sql = sql.replace("''","NULL"); //Execute the SQL to the database if (outSQL) { sqlStream << sql + ";\n"; } if (!mTable) { QSqlQuery query(db); if (!query.exec(sql)) { SQLError = true; //An error occurred. This will trigger a rollback logError(db,query.lastError().databaseText(),table,tblIndex,jsonData,fields,sql); //Write the error to the log } } else { if (!ignorePKError) { QSqlQuery query(db); if (!query.exec(sql)) { SQLError = true; //An error occurred. This will trigger a rollback logError(db,query.lastError().databaseText(),table,tblIndex,jsonData,fields,sql); //Write the error to the log } } } return resKeys; }