std::string const & Field::value() const { if (! theTextValue) { if (isNumeric()) { theTextValue.reset(boost::lexical_cast<std::string>(*theNumericValue)); } else { theTextValue.reset(std::string()); } } return *theTextValue; }
bool FileRecordTypeChecker::isBedFormat() { //test that the file has at least three fields. //2nd and 3rd fields of first valid data line must be integers. 3rd must not be less than 2nd. if (_numFields < 3) { return false; } //the 2nd and 3rd fields must be numeric. if (!isNumeric(_tokenizer.getElem(1)) || !isNumeric(_tokenizer.getElem(2))) { return false; } int start = str2chrPos(_tokenizer.getElem(1)); int end = str2chrPos(_tokenizer.getElem(2)); if (end < start) { return false; } return true; }
bool isIDString(const char *s) { if (!isAlpha(*s)) return false; while (*s) { if (!(isAlpha(*s) || isNumeric(*s))) return false; s++; } return true; }
// ====================测试代码==================== void Test(const char* testName, const char* str, bool expected) { if(testName != nullptr) printf("%s begins: ", testName); if(isNumeric(str) == expected) printf("Passed.\n"); else printf("FAILED.\n"); }
Aggregate::Aggregate(const std::string& url, const std::string& destination, const std::string& purgatory, unsigned txns,uintmax_t split): m_chunks(txns), m_url(url), m_filesize(0), m_failed(false), m_thread(NULL), m_splittable_size( (split>100*1024) ? split : 100*1024), m_speed_thread(NULL), m_hashedUrl(purgatory+"/"+md5(m_url)), m_prettyUrl(destination+"/"+prettify(m_url)), m_avgSpeed(0), m_instSpeed(0), m_hifiSpeed(0) { // Directory session is used to find out about // previous download information std::vector<std::string> files; Directory session(m_hashedUrl); if ( session.exists() && !session.isEmpty() ) { files = session.list(Node::FILE,true); // Remove non-numeric names for(unsigned i=0;i<files.size();i++){ if(!isNumeric(files[i])) files.erase(files.begin()+i); } // sort the files numerically sort(files.begin(),files.end(),numerically); } if( files.size()==0) { // If no numeric files are found! // It means there is no previous session File* newfile = new File(chunkName(0)); BasicTransaction* newtxn = BasicTransaction::factory(m_url); Chunk* researcher = new Chunk(newtxn,newfile); m_chunk.push_back(researcher); } else { // Get the file size from the last file m_filesize = std::atoi(files.back().c_str()); // the last file must not be with name "0" if(m_filesize==0) Throw(ex::filesystem::ZeroSize); // limiter file should be of zero size if( File(chunkName(m_filesize)).size() != 0 ) Throw(ex::filesystem::NonZeroSize,"limiter"); // '0' could be missing, error correction if(files[0]!="0") files.insert(files.begin(),"0"); // Populate all the Chunks for(unsigned i=0; i < files.size()-1; i++){ File* f = new File(chunkName(std::atoi(files[i].c_str()))); Range r(std::atoi(files[i+1].c_str()),std::atoi(files[i].c_str())+f->size()); BasicTransaction* t= BasicTransaction::factory(m_url,r); Chunk* c = new Chunk(t,f); m_chunk.push_back(c); } } }
bool FileRecordTypeChecker::handleTextFormat(const char *buffer, size_t len) { if (isVCFformat(buffer)) { return isTextDelimtedFormat(buffer, len); } else if (isTextDelimtedFormat(buffer, len)) { //At this point, _isText and _isDelimited are set. _numFields and _delimChar are //set. _fileType = SINGLE_LINE_DELIM_TEXT_FILE_TYPE; //Tokenize the first line of valid data into fields. //Need to make a copy so next call to tokenizer doesn't overwrite the line. QuickString line(_tokenizer.getElem(_firstValidDataLineIdx)); _tokenizer.setKeepFinalIncompleteElem(Tokenizer::USE_NOW); _tokenizer.setNumExpectedItems(_numFields); if (_tokenizer.tokenize(line, _delimChar) != _numFields) { cerr << "Error: Type checker found wrong number of fields while tokenizing data line." << endl; exit(1); } if (isBedFormat()) { _isBed = true; if (_numFields == 3) { _recordType = BED3_RECORD_TYPE; } else if (_numFields == 4) { if (isNumeric(_tokenizer.getElem(3))) { _recordType = BEDGRAPH_RECORD_TYPE; _fourthFieldNumeric = true; } else { _fourthFieldNumeric = false; _recordType = BED4_RECORD_TYPE; } } else if (_numFields == 5) { _recordType = BED5_RECORD_TYPE; } else if (_numFields == 6) { _recordType = BED6_RECORD_TYPE; } else if (_numFields == 12) { _recordType = BED12_RECORD_TYPE; } else if (_numFields >6) { _recordType = BED_PLUS_RECORD_TYPE; } return true; } if (isGFFformat()) { _isGFF = true; _recordType = GFF_RECORD_TYPE; return true; } return false; } return false; }
SEXP c_check_numeric(SEXP x, SEXP lower, SEXP upper, SEXP finite, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isNumeric(x) && !all_missing_atomic(x)) return make_type_error(x, "numeric"); assert(check_vector_len(x, len, min_len, max_len)); assert(check_vector_names(x, names)); assert(check_vector_missings(x, any_missing, all_missing)); assert(check_bounds(x, lower, upper)); assert(check_vector_finite(x, finite)); assert(check_vector_unique(x, unique)); return ScalarLogical(TRUE); }
bool TextField::wantedMinus() const { if(isNumeric()) { return wantNegetive; } else { return false; } }
Expression::ExpressionType Expression::getExpressionType(string token) { if (token == "true" || token == "false") return Boolean; if (isNumeric(token)) return Rational; if (token[0] == '"') return String; if (token[0] == '(') return List; return Symbol; }
cv::Range MxArray::toRange() const { cv::Range r; if (isNumeric() && numel()==2) r = cv::Range(at<int>(0), at<int>(1)); else if (isChar() && toString()==":") r = cv::Range::all(); else mexErrMsgIdAndTxt("mexopencv:error", "Invalid range value"); return r; }
/** * \brief Returns TRUE/FALSE whether line is foldable. * * In cases where line has not spaces that separate alphanumeric text, then * line cannot be split. * \param[in] s Current line * \return Returns TRUE if line is foldable, otherwise FALSE. */ int canFoldLine(char s[]) { int i, len; len = strLen(s); for (i = 0; i < len && !isAlpha(s[i]) && !isNumeric(s[i]); i++) ; for ( ; i < len; i++) if (isBlank(s, i)) return TRUE; return FALSE; }
SEXP colOrderStats(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP which) { SEXP ans = NILSXP; R_xlen_t nrow, ncol, qq; /* Argument 'x' and 'dim': */ assertArgMatrix(x, dim, (R_TYPE_INT | R_TYPE_REAL), "x"); nrow = asR_xlen_t(dim, 0); ncol = asR_xlen_t(dim, 1); /* Argument 'which': */ if (length(which) != 1) error("Argument 'which' must be a single number."); if (!isNumeric(which)) error("Argument 'which' must be a numeric number."); /* Argument 'rows' and 'cols': */ R_xlen_t nrows, ncols; int rowsType, colsType; int rowsHasna, colsHasna; void *crows = validateIndicesCheckNA(rows, nrow, 0, &nrows, &rowsType, &rowsHasna); void *ccols = validateIndicesCheckNA(cols, ncol, 0, &ncols, &colsType, &colsHasna); // Check missing rows if (rowsHasna && ncols > 0) { error("Argument 'rows' must not contain missing value"); } // Check missing cols if (colsHasna && nrows > 0) { error("Argument 'cols' must not contain missing value"); } /* Subtract one here, since rPsort does zero based addressing */ qq = asInteger(which) - 1; /* Assert that 'qq' is a valid index */ if (qq < 0 || qq >= nrows) { error("Argument 'which' is out of range."); } /* Double matrices are more common to use. */ if (isReal(x)) { PROTECT(ans = allocVector(REALSXP, ncols)); colOrderStats_dbl[rowsType][colsType](REAL(x), nrow, ncol, crows, nrows, ccols, ncols, qq, REAL(ans)); UNPROTECT(1); } else if (isInteger(x)) { PROTECT(ans = allocVector(INTSXP, ncols)); colOrderStats_int[rowsType][colsType](INTEGER(x), nrow, ncol, crows, nrows, ccols, ncols, qq, INTEGER(ans)); UNPROTECT(1); } return(ans); } // colOrderStats()
SEXP rowMads(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP constant, SEXP naRm, SEXP hasNA, SEXP byRow) { int narm, hasna, byrow; SEXP ans; R_xlen_t nrow, ncol; double scale; /* Argument 'x' and 'dim': */ assertArgMatrix(x, dim, (R_TYPE_INT | R_TYPE_REAL), "x"); nrow = asR_xlen_t(dim, 0); ncol = asR_xlen_t(dim, 1); /* Argument 'constant': */ if (!isNumeric(constant)) error("Argument 'constant' must be a numeric scale."); scale = asReal(constant); /* Argument 'naRm': */ narm = asLogicalNoNA(naRm, "na.rm"); /* Argument 'hasNA': */ hasna = asLogicalNoNA(hasNA, "hasNA"); /* Argument 'rows' and 'cols': */ R_xlen_t nrows, ncols; int rowsType, colsType; void *crows = validateIndices(rows, nrow, 0, &nrows, &rowsType); void *ccols = validateIndices(cols, ncol, 0, &ncols, &colsType); /* Argument 'byRow': */ byrow = asLogical(byRow); if (!byrow) { SWAP(R_xlen_t, nrow, ncol); SWAP(void*, crows, ccols); SWAP(R_xlen_t, nrows, ncols); SWAP(int, rowsType, colsType); } /* R allocate a double vector of length 'nrow' Note that 'nrow' means 'ncol' if byrow=FALSE. */ PROTECT(ans = allocVector(REALSXP, nrows)); /* Double matrices are more common to use. */ if (isReal(x)) { rowMads_dbl[rowsType][colsType](REAL(x), nrow, ncol, crows, nrows, ccols, ncols, scale, narm, hasna, byrow, REAL(ans)); } else if (isInteger(x)) { rowMads_int[rowsType][colsType](INTEGER(x), nrow, ncol, crows, nrows, ccols, ncols, scale, narm, hasna, byrow, REAL(ans)); } UNPROTECT(1); return(ans); } /* rowMads() */
bool xbnode::getBool() { if( isBool() ) return (this->getText()=="true"); if( isNumeric() ) return getNumeric()!=0; if( isText() ) return !getText().empty(); raiseError( "getBool() cant convert", __FILE__,__LINE__); return false; }
void OSGConverter::invoke(const InvokeRequest& req) { int nrThreads = 1; if (req.params.find("threads") != req.params.end() && isNumeric(req.params.find("threads")->second.atom.c_str(), 10)) { nrThreads = strTo<int>(req.params.find("threads")->second); } _isRunning = true; for (int i = 0; i < nrThreads; i++) { _threads.insert(new tthread::thread(OSGConverter::run, this)); } }
/** * Collects all GUIDs (and related info) from deleted characters which are still in the database. * * @param foundList a reference to an std::list which will be filled with info data * @param searchString the search string which either contains a player GUID or a part fo the character-name * @return returns false if there was a problem while selecting the characters (e.g. player name not normalizeable) */ static bool GetDeletedCharacterInfoList(DeletedInfoList& foundList, std::string searchString) { PreparedQueryResult result; PreparedStatement* stmt; if (!searchString.empty()) { // search by GUID if (isNumeric(searchString.c_str())) { stmt = CharacterDatabase.GetPreparedStatement(CHARACTER_SELECT_CHARACTER_DELETE_INFO_BY_GUID); stmt->setUInt32(0, uint32(atoi(searchString.c_str()))); result = CharacterDatabase.Query(stmt); } // search by name else { if (!normalizePlayerName(searchString)) return false; stmt = CharacterDatabase.GetPreparedStatement(CHARACTER_SELECT_CHARACTER_DELETE_INFO_BY_NAME); stmt->setString(0, searchString); result = CharacterDatabase.Query(stmt); } } else { stmt = CharacterDatabase.GetPreparedStatement(CHARACTER_SELECT_CHARACTER_DELETE_INFO); result = CharacterDatabase.Query(stmt); } if (result) { do { Field* fields = result->Fetch(); DeletedInfo info; info.lowGuid = fields[0].GetUInt32(); info.name = fields[1].GetString(); info.accountId = fields[2].GetUInt32(); // account name will be empty for not existed account AccountMgr::GetName(info.accountId, info.accountName); info.deleteDate = time_t(fields[3].GetUInt32()); foundList.push_back(info); } while (result->NextRow()); } return true; }
double KeyListOpsMethods::getColValNum() { const QuickString &strVal = (*_iter)->getField(_column); if (!isNumeric(strVal)) { _nonNumErrFlag = true; _errMsg = " ***** WARNING: Non numeric value "; _errMsg.append(strVal); _errMsg.append(" in "); _errMsg.append(_column); _errMsg.append("."); return NAN; } return atof(strVal.c_str()); }
// Set the value of an item in a list, in-place SEXP C_set_list_item(SEXP x, SEXP idx, SEXP value) { if (!isNewList(x)) error("x must be a list"); if (!isNumeric(idx)) error("idx must be a numeric"); int i = asInteger(idx); if (i < 1 || i > length(x)) error("i must a number between 1 and the length of the list"); SET_VECTOR_ELT(x, i-1, value); return x; }
void loadVar(VarType type, uint16_t localId, uint16_t context, Bytecode* bc) { assert(isNumeric(type)); bool isInt = type == VT_INT; if (context != 0) { bc->addInsn(isInt ? BC_LOADCTXIVAR : BC_LOADCTXDVAR); bc->addUInt16(context); } else { bc->addInsn(isInt ? BC_LOADIVAR : BC_LOADDVAR); } bc->addUInt16(localId); }
double getScalarReal(SEXP foo) { if (! isNumeric(foo)) error("argument must be numeric"); if (LENGTH(foo) != 1) error("argument must be scalar"); if (isReal(foo)) { return REAL(foo)[0]; } else { SEXP bar = coerceVector(foo, REALSXP); return REAL(bar)[0]; } }
// Validate the IMSI string "IMSI"+digits; return pointer to digits or NULL if invalid. const char* extractIMSI(const char *IMSI) { // Form of the name is IMSI<digits>, and it should always be 18 or 19 char. // IMSIs are 14 or 15 char + "IMSI" prefix unsigned namelen = strlen(IMSI); if (strncmp(IMSI,"IMSI",4) || (namelen>19) || (namelen<18) || !isNumeric(IMSI+4)) { // Note that if you use this on a non-INVITE it will fail, because it may have fields like "222-0123" which are not IMSIs. // Dont warn here. We print a better warning just once in newCheckInvite. // LOG(WARNING) << "INVITE with malformed username \"" << IMSI << "\""; return ""; } // Skip first 4 char "IMSI". return IMSI+4; }
void IdMatch(char * buf, int * ppos){ FILE * fp = globalFile(SCAN_GET, ""); int pos = *ppos; char c;// = readNext(fp); do{ pos++; c = readNext(fp); buf[pos] = c; }while(isAlpha(c) || isNumeric(c)); buf[pos] = ' '; pos--; ungetc(c, fp); *ppos = pos; }
static double statement_list(){ printf("Inside statement_list \n"); if ( isNumeric(global_current->val) != 0 ){ double temp = statement(); return temp; } if (strcmp(global_current->val,"(") == 0){ double temp = statement(); return temp; } }
const DynamicAny DynamicAny::operator * (const DynamicAny& other) const { if (isInteger()) { if(isSigned()) return multiply<Poco::Int64>(other); else return multiply<Poco::UInt64>(other); } else if (isNumeric()) return multiply<double>(other); else throw InvalidArgumentException("Invalid operation for this data type."); }
DynamicAny& DynamicAny::operator /= (const DynamicAny& other) { if (isInteger()) { if(isSigned()) return *this = divide<Poco::Int64>(other); else return *this = divide<Poco::UInt64>(other); } else if (isNumeric()) return *this = divide<double>(other); else throw InvalidArgumentException("Invalid operation for this data type."); }
SEXP rowCounts(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP value, SEXP what, SEXP naRm, SEXP hasNA) { SEXP ans; int narm, hasna, what2; R_xlen_t nrow, ncol; /* Argument 'x' & 'dim': */ assertArgMatrix(x, dim, (R_TYPE_LGL | R_TYPE_INT | R_TYPE_REAL), "x"); nrow = asR_xlen_t(dim, 0); ncol = asR_xlen_t(dim, 1); /* Argument 'value': */ if (length(value) != 1) error("Argument 'value' must be a single value."); if (!isNumeric(value)) error("Argument 'value' must be a numeric value."); /* Argument 'what': */ what2 = asInteger(what); if (what2 < 0 || what2 > 2) error("INTERNAL ERROR: Unknown value of 'what' for rowCounts: %d", what2); /* Argument 'naRm': */ narm = asLogicalNoNA(naRm, "na.rm"); /* Argument 'hasNA': */ hasna = asLogicalNoNA(hasNA, "hasNA"); /* Argument 'rows' and 'cols': */ R_xlen_t nrows, ncols; int rowsType, colsType; void *crows = validateIndices(rows, nrow, 0, &nrows, &rowsType); void *ccols = validateIndices(cols, ncol, 0, &ncols, &colsType); /* R allocate a double vector of length 'nrow' */ PROTECT(ans = allocVector(INTSXP, nrows)); /* Double matrices are more common to use. */ if (isReal(x)) { rowCounts_Real[rowsType][colsType](REAL(x), nrow, ncol, crows, nrows, ccols, ncols, asReal(value), what2, narm, hasna, INTEGER(ans)); } else if (isInteger(x)) { rowCounts_Integer[rowsType][colsType](INTEGER(x), nrow, ncol, crows, nrows, ccols, ncols, asInteger(value), what2, narm, hasna, INTEGER(ans)); } else if (isLogical(x)) { rowCounts_Logical[rowsType][colsType](LOGICAL(x), nrow, ncol, crows, nrows, ccols, ncols, asLogical(value), what2, narm, hasna, INTEGER(ans)); } UNPROTECT(1); return(ans); } // rowCounts()
float DexCalc::bind(std::string a, char op, std::string b) { float numA; float numB; bool assign; std::string name; float value; if (a != "var" && a != "kill") if (isNumeric(b)) numB = val(b); else numB = this->getVar(b); if (op == '@') { if (a == "var") this->defVar(b); else if (a == "kill") this->undefVar(b); else return TS_Util::bind(a, numB); return 0; } if (op != OP_SET) if (isNumeric(a)) numA = val(a); else numA = this->getVar(a); assign = true; switch (op) { case OP_INC: if (!isNumeric(a)) this->setVar(name = a, (value = numA) + 1); if (!isNumeric(b)) this->setVar(name = b, value = (numB + 1)); break; case OP_DEC: if (!isNumeric(a)) this->setVar(name = a, (value = numA) - 1); if (!isNumeric(b)) this->setVar(name = b, value = (numB - 1)); break; case OP_SET: this->setVar(name = a, value = numB); break; case OP_ADD_SET: this->setVar(name = a, value = numA + numB); break; case OP_SUB_SET: this->setVar(name = a, value = numA - numB); break; case OP_MUL_SET: this->setVar(name = a, value = numA * numB); break; case OP_DIV_SET: this->setVar(name = a, value = TS_Util::safeDiv2(numA, numB)); break; case OP_POW_SET: this->setVar(name = a, value = (float) pow(numA, numB)); break; default: assign = false; } if (assign) return value; return TS_Util::bind(numA, op, numB); }
bool tvCanBeCoercedToNumber(TypedValue* tv) { switch (tv->m_type) { case KindOfUninit: case KindOfBoolean: case KindOfInt64: case KindOfDouble: return true; case KindOfNull: // In PHP 7 mode handling of null types is stricter return !RuntimeOption::PHP7_ScalarTypes; case KindOfPersistentString: case KindOfString: { // Simplified version of is_numeric_string // which also allows for non-numeric garbage // Because PHP auto str = tv->m_data.pstr; auto p = str->data(); auto l = tv->m_data.pstr->size(); while (l && isspace(*p)) { ++p; --l; } if (l && (*p == '+' || *p == '-')) { ++p; --l; } if (l && *p == '.') { ++p; --l; } bool okay = l && isdigit(*p); // In PHP7 garbage at the end of a numeric string will trigger a notice if (RuntimeOption::PHP7_ScalarTypes && okay && !str->isNumeric()) { raise_notice("A non well formed numeric value encountered"); } return okay; } case KindOfPersistentVec: case KindOfVec: case KindOfPersistentDict: case KindOfDict: case KindOfPersistentKeyset: case KindOfKeyset: case KindOfPersistentArray: case KindOfArray: case KindOfObject: case KindOfResource: return false; case KindOfRef: case KindOfClass: break; } not_reached(); }
std::vector<cv::Rect> MxArray::toVector() const { if (isNumeric()) { std::vector<cv::Rect> vr; if (numel() == 4) vr.push_back(toRect()); else toMat(CV_32S).reshape(4, 0).copyTo(vr); return vr; } else { return toVector( std::const_mem_fun_ref_t<cv::Rect, MxArray>(&MxArray::toRect)); } }
double KeyListOpsMethods::getColValNum() { const string &strVal = (*_iter)->getField(_column); if (!isNumeric(strVal)) { _nonNumErrFlag = true; ostringstream s; _errMsg = " ***** WARNING: Non numeric value "; s << strVal; s << " in "; s << _column; s << "."; _errMsg.append(s.str()); return NAN; } return atof(strVal.c_str()); }