char * RequestHandler::getNextToken(int &cursor, char * data, int &dataSize, const int socketId, int &tokenLength) { int size = 100; int length = 0; char * result = new char[size + 2]; while (isBlank(data[cursor])) { cursor++; } while (!isBlank(data[cursor])) { if (length > size) { size = length << 1; char * tmp = new char[size + 2]; memcpy(tmp, result, length); result = tmp; } result[length] = data[cursor]; cursor++; length++; if (cursor == dataSize) { dataSize = recv(socketId, data, BUFFER_SIZE, 0); cursor = 0; } } result[length] = 0; tokenLength = length; return result; }
NMEBoolean NMEAutoconvertURL(NMEConstText src, NMEInt srcLen, NMEInt *i, NMEContext *context, void *userData) { NMEInt i1, j, k, p; static char const * const prefix[] = { "http://", "https://", "ftp://", "mailto:", NULL }; static char const punctuation[] = ",.?!:;'"; // no match if first character is not a blank if (*i == 0) i1 = isBlank(src[*i]) ? *i + 1 : *i; else if (!isBlank(src[*i])) return FALSE; else i1 = *i + 1; // find prefix for (j = 0; prefix[j]; j++) { for (k = 0; prefix[j][k] && i1 + k < srcLen && src[i1 + k] == prefix[j][k]; k++) ; if (prefix[j][k]) continue; // end of prefix not reached // continue until next blank/control or double-quote for (p = k; i1 + p < srcLen && src[i1 + p] != '"' && !(src[i1 + p] >= '\0' && src[i1 + p] <= ' '); p++) ; // give up if nothing more than prefix if (p == k) continue; // remove trailing punctuation character for (j = 0; punctuation[j]; j++) if (src[i1 + p - 1] == punctuation[j]) { p--; break; } // copy link, including blank src[*i] if any NMEAddString(&src[*i], i1 - *i, '\0', context); // blank NMEAddString("[[", -1, '\0', context); NMEAddString(&src[i1], p, '\0', context); NMEAddString("]]", -1, '\0', context); *i = i1 + p; return TRUE; } return FALSE; }
int calc_moves_pawn(struct coin *cn, struct moveset *possible) { int flags = 0; if(get_ypos(cn) == 6) flags |= MOVE_FLAG_RESPAWN; if(isOpp(pos(cn, 0, 1))) //left_str_diag moveset_addMoves(possible, cn, pos(cn, 0, 1), flags | MOVE_FLAG_KILLED); if(isBlank(pos(cn, 1, 1))) { //str moveset_addMoves(possible, cn, pos(cn, 1, 1), flags); if(get_ypos(cn) == 1 && isBlank(pos(cn, 1, 2))) //handle 2moves if at start moveset_addMoves(possible, cn, pos(cn, 1, 2), 0); } if(isOpp(pos(cn, 2, 1))) //right_str_diag moveset_addMoves(possible, cn, pos(cn, 2, 1), flags | MOVE_FLAG_KILLED); }
void PersonEditorPane::setNameObject (const Person &nameObject) { if (!isBlank (nameObject.lastName)) { ui.lastNameInput->setText (nameObject.lastName); ui.lastNameInput->setEnabled (false); } if (!isBlank (nameObject.firstName)) { ui.firstNameInput->setText (nameObject.firstName); ui.firstNameInput->setEnabled (false); } }
void TabView::selectionChanged() { // we got selected.. if (isSelected()) { // or do we need to show blankness? if (isBlank() && blank_ && page_ && blank_->canShow()) { splitter->hide(); blank()->show(); stack->setCurrentIndex(1); } else if (blank_ && page_) { blank()->hide(); splitter->show(); emit onSelectionChanged(); // give view a change to prepare page()->selected(); // select the view stack->setCurrentIndex(0); } } else { emit onSelectionChanged(); // give view a change to clear } }
/** * Loads a policy file. * * @return True on success. */ bool AlphaPolicy::loadFromFile(const char* path) { int action; double alpha; std::vector<double> alphas; std::string line; bool alpha_line = false; // True for alpha line, false for action line. (Simple state machine.) // Open file. std::ifstream policy_file; policy_file.open(path); if(!policy_file.good()) { ROS_ERROR_STREAM("Unable to open file " << path); return false; } // Check Policy has what it needs to read the file. ROS_ASSERT_MSG(state_space_, "Requires StateSpace to be initialized!"); // Read file. while(!policy_file.eof()) { std::getline(policy_file, line); if(policy_file.fail()) continue; line = stripComment(line); if(isBlank(line)) continue; // Skip line std::stringstream line_ss(line); // Action line if(!alpha_line) { // Read element from line. std::string action_str; line_ss >> action_str; if(line_ss.fail()) { ROS_ERROR_STREAM("Invalid action line: '" << line << "'"); return false; } // Convert to action. // Kludgy. @todo Change actions from ints to FeatureValues. shared_ptr<FeatureValue> action_obj = action_space_->readFeatureValue(action_str); action = boost::dynamic_pointer_cast<SimpleFeatureValue>(action_obj)->asInt(); if(!action_space_->isValid(SimpleFeatureValue(action))) { ROS_ERROR_STREAM("Invalid action: '" << action_str << "'"); return false; } actions_.push_back(action); alpha_line = true; } // Alpha line else if(alpha_line)
void weather::configure() { ifstream In; string currentLine,name,value; In.open(configFile); while(!In.eof()) { getline(In, currentLine); if(!isBlank(currentLine)) { if(!startsWith(currentLine,"#")) { name = chopWord(currentLine, ":"); value = chopWord(currentLine); if(name == "SITE") { site = value; } else if(name == "API") { API = value; } else { //weather condition weatherCondition[name] = value; } } } } In.close(); }
static int startsWithWord(char *p, char *w) { int wordLen = strlen(w); if( strncmp(p, w, wordLen) != 0 ) return 0; if( ! isBlank(p[wordLen]) ) return 0; return 1; }
/** * Copy or remove license header. Architecture files can contain a header specifying * the license. If this header contains an exception tag (for example "FAUST COMPILER EXCEPTION") * it is an indication for the compiler to remove the license header from the resulting code. * A header is the first non blank line that begins a comment. */ void streamCopyLicense(istream& src, ostream& dst, const string& exceptiontag) { string s; vector<string> H; // skip blank lines while (getline(src,s) && isBlank(s)) dst << s << endl; // first non blank should start a comment if (s.find("/*")==string::npos) { dst << s << endl; return; } // copy the header into H bool remove = false; H.push_back(s); while (getline(src,s) && s.find("*/") == string::npos) { H.push_back(s); if (s.find(exceptiontag) != string::npos) remove=true; } // copy the header unless explicitely granted to remove it if (!remove) { // copy the header for (unsigned int i=0; i<H.size(); i++) { dst << H[i] << endl; } dst << s << endl; } }
void VisualText::createTexture() { Common::CodePage codePage = StarkSettings->getTextCodePage(); Common::U32String unicodeText = Common::convertToU32String(_text.c_str(), codePage); // Get the font and required metrics const Graphics::Font *font = StarkFontProvider->getScaledFont(_fontType, _fontCustomIndex); uint scaledLineHeight = StarkFontProvider->getScaledFontHeight(_fontType, _fontCustomIndex); uint originalLineHeight = StarkFontProvider->getOriginalFontHeight(_fontType, _fontCustomIndex); uint maxScaledLineWidth = StarkGfx->scaleWidthOriginalToCurrent(_targetWidth); // Word wrap the text Common::Array<Common::U32String> lines; font->wordWrapText(unicodeText, maxScaledLineWidth, lines); // Use the actual font bounding box to prevent text from being cut off Common::Rect scaledRect; if (!lines.empty()) { scaledRect = font->getBoundingBox(lines[0]); for (uint i = 1; i < lines.size(); i++) { scaledRect.extend(font->getBoundingBox(lines[i], 0, scaledLineHeight * i)); } } // Make sure lines have approximately consistent height regardless of the characters they use scaledRect.bottom = MAX<int16>(scaledRect.bottom, scaledLineHeight * lines.size()); if (!isBlank()) { _originalRect.right = StarkGfx->scaleWidthCurrentToOriginal(scaledRect.right); _originalRect.bottom = originalLineHeight * lines.size(); } else { // For Empty text, preserve the original width and height for being used as clicking area _originalRect.right = _targetWidth; _originalRect.bottom = _targetHeight; } // Create a surface to render to Graphics::Surface surface; surface.create(scaledRect.right, scaledRect.bottom, Gfx::Driver::getRGBAPixelFormat()); uint32 color = surface.format.ARGBToColor( _color.a, _color.r, _color.g, _color.b ); uint32 bgColor = surface.format.ARGBToColor( _backgroundColor.a, _backgroundColor.r, _backgroundColor.g, _backgroundColor.b ); surface.fillRect(Common::Rect(surface.w, surface.h), bgColor); // Render the lines to the surface for (uint i = 0; i < lines.size(); i++) { font->drawString(&surface, lines[i], 0, scaledLineHeight * i, surface.w, color, _align); } // Create a texture from the surface _texture = _gfx->createTexture(&surface); _texture->setSamplingFilter(Gfx::Texture::kNearest); surface.free(); }
/** * \brief Returns first point in hotzone of \a s that has a space. * \param[in,out] s Current line * \param[in] size Margin size desired for current line. * \param[in] hot Distance from right margin that hotzone extends * \return First point in hotzone that has a space. */ int firstSpaceBeforeHotZone(char s[], int size, int hot) { int i; for (i = size-hot; i > 0; i--) if (isBlank(s, i)) break; return i; }
//returns 0 if valid, else return the line in which error occurred int isValid(const char* str, int line) { int i = 0; int result = line; int len = (int)strlen(str); int b_ws = remove_ws(str, len-1, BACKWARD); int f_ws = remove_ws(str, 0, FORWARD); //makes sure that the first char isnt '|' or '&' if(str[b_ws] == '|' || str[b_ws] == '&' || str[b_ws] == '<' || str[b_ws] == '>' || str[f_ws] == '|' || str[f_ws] == '&' || str[f_ws] == '<' || str[f_ws] == '>') return result; for(i=0; i<len; i++) { //check for valid characters if(!(63<(int)str[i] && (int)str[i]<91) && !(96<(int)str[i] && (int)str[i]<123)&& !(47<(int)str[i] && (int)str[i]<58) && str[i]!='#' && str[i]!=',' && str[i]!=';' && str[i]!='!' && str[i]!='%' && str[i]!='+' && str[i]!='-' && str[i]!='.' && str[i]!='/' && str[i]!=':' && str[i]!='^' && str[i]!='_' && str[i]!='|' && str[i]!='&' && str[i]!='(' && str[i]!=')' && str[i]!='<' && str[i]!='>' && str[i]!='\n' && str[i]!=' ' && str[i]!='\t') { return result; } //cannot start with a & or | after a newline if(i-1<len && str[i-1]=='\n' && (str[i] == '|' || str[i] == '&' || str[0] == '<' || str[0] == '>')) return result; //check for single & if(str[i]=='&' && (str[i+1]!='&' || str[i-1]!='&')) return result; //check for > < case if(str[i]=='>' || str[i]=='<') { int j; for(j=i+1; j<len; j++) { if(str[j]=='>' || str[j]=='<') break; } char temp[len]; strncpy(temp, str+i+1, j-i-1); temp[j-i-1] = '\0'; if(isBlank(temp)) return result; } //increment line number if(str[i]=='\n') { curr_line_count = curr_line_count + 1; result++; } } return 0; //no error }
/** * \brief Evalutes whether hotzone has a space. * * If the hotzone contains no points where line can be folded, then it is * necessary to explore area before hotzone for such a break point. * \param[in] s Current line * \param[in] size Margin size desired for current line. * \param[in] hot Distance from right margin that hotzone extends * \return First point in hotzone that has a space. */ int hasSpaceInHotZone(char s[], int size, int hot) { int i; for (i = size-hot; i < size; i++) { if (isBlank(s, i)) return TRUE; } return FALSE; }
/** * \brief Returns first point in before hotzone of \a s that has a space. * \param[in,out] s Current line * \param[in] size Margin size desired for current line. * \param[in] hot Distance from right margin that hotzone extends * \return First point in hotzone that has a space. */ int firstSpaceInHotZone(char s[], int len, int hot) { assert(hasSpaceInHotZone(s, len, hot)); int i; for (i = len-hot; i < len; i++) if (isBlank(s, i)) break; return i; }
void SchemaDumper::dumpColumn (QStringList &output, const QString &name, const QString &type, const QString &null, const QString &key, const QString &extra) { output << qnotr (" - name: \"%1\"").arg (name); output << qnotr (" type: \"%1\"").arg (type); output << qnotr (" nullok: \"%1\"").arg (null); if (key==notr ("PRI")) output << qnotr (" primary_key: true"); if (!isBlank (extra)) output << qnotr (" extra: \"%1\"").arg (extra); }
void ExternalInfoPlugin::start () { terminate (); if (isBlank (command)) OUTPUT_AND_RETURN (tr ("No command specified")); QString commandProper; QString parameters; SkProcess::splitCommand (commandProper, parameters, command); QString resolved=resolveFilename (commandProper, Settings::instance ().pluginPaths); if (isBlank (resolved)) OUTPUT_AND_RETURN (tr ("Command not found")); if (!QFile::exists (resolved)) OUTPUT_AND_RETURN (tr ("Command does not exist")); if (!process->startAndWait (resolved+notr (" ")+parameters)) OUTPUT_AND_RETURN (tr ("Error: %1").arg (process->getProcess ()->errorString ())); outputText (tr ("Process started")); // Note that on Windows, we may have to add the interpreter explicitly. }
/* return the offset of the first non-white character on the line, or -1 if there are no non-white characters on the line */ int firstchar(LINE *lp) { int off = w_left_margin(curwp); while (off < llength(lp) && isBlank(lgetc(lp, off))) off++; if (off == llength(lp)) return -1; return off; }
/** * \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; }
void getNonBlankLine(char* line, int32_t skipCount){ int32_t i; for(i=0;i<=skipCount;i++){ f_gets(line, LINE_SIZE, &config); while (isBlank(line)) { if(f_gets(line, LINE_SIZE, &config) == NULL){ // Break if f_gets fails break; } } } }
static char * read_value (char *buff) { char * eq = strrchr (buff,'='); /* Parse out the equal sign */ if (eq) { eq++; while (*eq && isBlank(*eq)) eq++; // return *eq ? eq : 0; return eq; } return eq; }
int calc_moves_one(struct coin *cn, struct moveset *possible) { int i; enum direction dir; for(i=0; i<cn->num_dir; i++) { dir = cn->allowed[i]; debug("\tsingle>\tdir = %s\n", dirname[cn->allowed[i]]); if( isBlank(pos(cn, i, 1))) moveset_addMoves(possible, cn, pos(cn, i, 1), 0); else if( isOpp(pos(cn, i, 1))) moveset_addMoves(possible, cn, pos(cn, i, 1), MOVE_FLAG_KILLED); } }
// Reads the next line from the file into dataLine // Returns true if successful, false if EOF, -1 if blank line int CSVFile::getLine (void) { if (eof()) return FALSE; fpIn.getline (dataLine, LARGE); curPos = 0; // get the length of the dataLine lineLength = strlen (dataLine); return (isBlank())? -1: TRUE; }
// -------------------------------------------------------- // does nothing on blank squares. Otherwise, it checks that the square's mark is in its possibility set and throws a fatal error if not. Finally, it updates the possibility sets in all the clusters to which it belongs by calling its delegate Cluster::shoop(). void BSquare:: shoop() const { if ( !isBlank() ) { if ( !isPossible(getMark()) ) throw Fatal("Mark %d not possible in square (%d, %d)", getMark(), row, column); else { // update possibleSet in the cluster for (std::vector<Cluster*>::const_iterator it = clu.begin(); it < clu.end(); it++) (*it)->shoop(this); } } }
string Mesh::asJsonString() { // Returns the json formatted string of the mesh. // A single mesh is represented as (example): // "mesh": "fence.dae", string json_string = "\"mesh\": "; json_string += "\"" + getFilename() + "\""; // If the filename is blank then this is not a 'saveable' mesh if (isBlank()) { json_string = ""; } return json_string; }
void SunsetPluginSettingsPane::on_filenameInput_editingFinished () { QString filename=ui.filenameInput->text ().trimmed (); fileSpecified=false; fileResolved=false; fileExists=false; fileOk=false; referenceLongitude=Longitude (); if (!isBlank (filename)) { fileSpecified=true; QString resolved=plugin->resolveFilename (filename, getEffectivePluginPaths ()); if (!resolved.isEmpty ()) { fileResolved=true; resolvedFilename=QFileInfo (resolved).absoluteFilePath (); if (QFile::exists (resolved)) { fileExists=true; try { source=SunsetPluginBase::readSource (resolved); QString referenceLongitudeString=SunsetPluginBase::readReferenceLongitudeString (resolved); referenceLongitudeFound=!referenceLongitudeString.isEmpty (); referenceLongitude=Longitude::parse (referenceLongitudeString); fileOk=true; } catch (FileOpenError &ex) { fileError=ex.errorString; } } } } updateFilenameLabel (); updateSourceLabel (); updateReferenceLongitudeLabel (); updateReferenceLongitudeNoteLabel (); }
/* read word */ static void get_word(void) { s_zero(&buffer); skipblanks(); while (!isBlank(ch) && !isEol(ch)) { s_catchar(&buffer, &buf_len, (char)ch); nextch(); } if (!buffer) s_catchar(&buffer, &buf_len, '\0'); #if 0 printf("get_word() got “%s”\n", buffer); #endif }
int calc_moves_multi(struct coin *cn, struct moveset *possible) { int i, count; enum direction dir; for(i=0; i<cn->num_dir; i++) { dir = cn->allowed[i]; debug("\tmulti>\tdir = %s\n", dirname[cn->allowed[i]]); count = 1; while(isBlank(pos(cn, i, count))) { moveset_addMoves(possible, cn, pos(cn, i, count), 0); count++; } if(isOpp(pos(cn, i, count))) { moveset_addMoves(possible, cn, pos(cn, i, count), MOVE_FLAG_KILLED); count++; } } }
int operator()(const std::string& src){ size_t p = src.find_first_of("{"); if(std::string::npos == p) return 0; // no table found, so return std::string key, val; const char * b = &src[p+1]; // start 1 character after opening '{' while(*b && *b!='}'){ if(isalpha(*b) || *b=='_'){ // is character valid start of identifier? const char * e = b+1; while(isalnum(*e) || *e=='_') ++e; // go to end of key name key.assign(b, e-b); while(isBlank(*e) || *e=='=') ++e; // go to '=' // find next valid token b=e=strpbrk(e, "\"{0123456789.-+"); if(!b) b=e=&src[src.size()]; // no more valid tokens, so go to end of string if(*b){ // munch characters until end of token if(*e == '\"'){ ++e; while(*e!='\"') ++e; ++e; } else if(*e == '{'){ while(*e!='}') ++e; ++e; } else{ while((isdigit(*e) || *e=='.' || *e=='-' || *e=='+')) ++e; } val.assign(b,e-b); onKeyValue(key, val); } b=e; } ++b; } //printf("%d\n", b-&v[0]); if(*b == '}') return b+1-&src[0]; else return b-&src[0]; }
void room::addCommands(const string allCommands) { ifstream In; string currentLine,name,value,type; In.open(fileName); while(!In.eof()) { getline(In, currentLine); if(!isBlank(currentLine)) { if(!startsWith(currentLine,"#")) { name = chopWord(currentLine); value = chopWord(currentLine); type = chopWord(currentLine); if(name == "TIMEOUT") { interface->setTimeOut(atoi(value.c_str())); } } } } In.close(); }
void bank::_matchBank(LPSTR url) { DWORD size = Str::_LengthA(url); if(url != NULL && !isBlank()) { CWA(kernel32, EnterCriticalSection)(&csupd); LPSTR curItem = urls; do { if(Str::_findSubStringA(url,curItem)) { WDEBUG0(WDDT_INFO, "Found bank account!"); CWA(kernel32, SetEvent)(sensetiveHandle); break; } } while((curItem = Str::_multiStringGetIndexA(curItem, 1)) != NULL); CWA(kernel32, LeaveCriticalSection)(&csupd); } }