char *GetCmdParaString(char *str) { //puts("0"); if(GetParaNumOfCmd(str)==1) return NULL; //puts("1"); str=trimLeft(str); for(;*str!=0x20 && *str!='\t' ; ++str); str=trimLeft(str); //puts("2"); return str; }
char *GetCmdParaStringWithcmdCode(int cmdCode ,char *str) { str=trimLeft(str); if(cmdCode==1) str=trimLeft(str+6); if(cmdCode==2) str=trimLeft(str+3); if(cmdCode==3) str=trimLeft(str+7); if(cmdCode==4|| cmdCode==5) str=trimLeft(str+5); return str; }
void trim(char *buffer) { ASSERT(buffer != NULL); trimLeft(buffer); trimRight(buffer); return; }
void IsotopeDistribution::merge(double resolution, double min_prob) { // Sort by mass and trim the tails of the container sortByMass(); trimLeft(min_prob); trimRight(min_prob); ContainerType raw = distribution_; double mass_range = (raw.back().getMZ() - raw.front().getMZ()); UInt output_size = ceil(mass_range / resolution); if (output_size > distribution_.size()) { throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "New Isotope Distribution " "has more points than the old one."); } distribution_.clear(); ContainerType distribution(output_size, Peak1D(0, 0)); double delta = mass_range / output_size; for (auto& p : raw) { UInt index = round((p.getMZ() - raw.front().getMZ())/resolution); if (index >= distribution.size()) {continue;} double mass = raw.front().getMZ() + (index * delta); distribution[index].setMZ(mass); distribution[index].setIntensity(distribution[index].getIntensity() + p.getIntensity()); } distribution_ = distribution; trimIntensities(min_prob); }
bool Parser::hasMoreCommands() { if (f_.eof()) { // No more file to check. return false; } // We have to look ahead for commands, skipping comments and blank lines. std::istream::streampos parsed_pos = f_.tellg(); // Saving stream state. std::ios::iostate status = f_.rdstate(); f_.clear(); bool res = false; unsigned int lines_read = 0; // So that if there's an error it displays where. do { std::string s; std::getline(f_, s); lines_read++; trimLeft(s); trimRight(s); if (!s.empty() && !isComment(s)) { // Found a command line... if (!validCommand(s)) { // ...but it's an invalid line! std::cerr << "Error at line "; std::cerr << current_line_number_ + lines_read; std::cerr << ". '" << s << "': Invalid line" << std::endl; throw std::runtime_error("Invalid line"); } res = true; goto done; } } while (!f_.eof()); done: f_.seekg(parsed_pos); // Restoring stream to its original state. f_.setstate(status); return res; }
StringView StringView::takeFirstWord() noexcept(false) { trimLeft(); mustNotBeEmpty(); assert(!lastChar().isSpace()); const auto it = begin_; for (; begin_ != end_; ++begin_) if (firstChar().isSpace()) break; const auto result = StringView{it, begin_}; trimLeft(); return result; }
ustring trim( ustring &str, const ustring trimChars) { trimRight( str, trimChars ); trimLeft( str, trimChars ); return str; }
void Eliza::verify_keyword_boundary(std::string keyWord, int pos) { bool bFrontWordsAloud = 0; bool bBackWordsAloud = 0; m_bWrongBoundary = 0; if(keyWord[0] != '_') { bFrontWordsAloud = 1; } else { trimLeft(keyWord, '_'); } char lastChar = keyWord[keyWord.length()-1]; if(lastChar != '_') { bBackWordsAloud = 1; } else { trimRight(keyWord, '_'); } keyWord.insert(0, " "); keyWord.append(" "); if(!bFrontWordsAloud && pos > 0) { m_bWrongBoundary = 1; } else if(!bBackWordsAloud && (pos + keyWord.length()) != m_sInput.length()) { m_bWrongBoundary = 1; } else if(bBackWordsAloud && (pos + keyWord.length()) == m_sInput.length()) { m_bWrongBoundary = 1; } }
void assembleFile() { std::ifstream in(inPath_.c_str()); if (!in) { error("couldn't open: " + errorString()); } while (getline(in, line_)) { ++lineNumber_; p_ = line_.c_str(); // Handle labels. if (isalnum(*p_)) { handleLabel(); } else { // Trim leading whitespace. trimLeft(); if (*p_ == 0 || *p_ == '#') { // Skip blank or comment lines. } else if (*p_ == '.') { handleDirective(); } else { handleInstruction(); } } } fixForwardBranches(); writeBytes(&code_[0], &code_[code_.size()]); }
// trim all left and right characters that is specified by // the string "characters" void trimLR(std::string &str, std::string characters) { int len = characters.length(); for(int i = 0; i < len; ++i) { trimLeft( str, characters[i] ); trimRight( str, characters[i] ); } }
void Properties::load(QIODevice *pDevice) { const QLatin1Char append_char(msEscapeChar); if (!pDevice) { logger()->warn("No device specified for load."); return; } QTextStream stream(pDevice); QString line; int line_number = 0; QString property; int property_start_line = 1; do { line = trimLeft(stream.readLine()); line_number++; if (!line.isEmpty() && line.at(line.length() - 1) == append_char) property += line.left(line.length() - 1); else { property += line; parseProperty(property, property_start_line); property.clear(); property_start_line = line_number + 1; } } while (!line.isNull()); }
ustring trimC( ustring str, const ustring trimChars) { ustring copy=str; trimRight(copy, trimChars); trimLeft(copy, trimChars ); return copy; }
//Reads the input file line by line void readInput() { std::string temp; std::stringstream sstream; while (std::getline(std::cin, temp)) { trimLeft(temp); trimRight(temp); input.push_back(temp); } }
char *trimRight(char *str) { char *strTmp = str+strlen(str)-1; if(str==NULL || strlen(trimLeft(str))==0) return NULL; while ((*strTmp == ' ' || *strTmp == '\t' || *strTmp == 10) && strTmp>str) { *strTmp = '\0'; strTmp--; } return str; }
string modulenameFromFilename(const string &filename) { // blank filename is an error string strippedFilename(trimRight(trimLeft(filename, "\t "), "\t ")); if (strippedFilename == "") { THROW(ArgExc, "Expected non-blank filename"); } vector<string> filenameComponents(split(strippedFilename, '.')); return filenameComponents[0]; }
char *ModifyString(char *str){ int i=0; str=trimLeft(str); if(strlen(str)==0) return NULL; while(str[i]!='\0' ) { i++; } str[i]=' '; return str; }
char *ReturnFirstString(char *str){ int i=0; str=trimLeft(str); if(strlen(str)==0) return NULL; while(str[i]!=' ' && str[i]!='\t') { i++; } str[i]='\0'; return str; }
void Parser::advance() { /* PRE: hasMoreCommands() == true => next non-comment line contains a valid command. */ std::string s; do { std::getline(f_, s); current_line_number_++; trimLeft(s); } while (isComment(s) || s.empty()); trimRight(s); current_line_ = s; }
int main () { int c=0; char s[100]; for(;;){ switch(GetMenu("Input String;Trim right;Trim Left;Trim Mid;Print Output",5,1)) { case 1:c++;inputs(s);while(getchar() != '\n');break; case 2:if(c!=0)trimRight(s);else printf("\t%s\n","Input String First !"); break; case 3:if(c!=0)trimLeft(s);else printf("\t%s\n","Input String First !");break; case 4:if(c!=0)trimMid(s);else printf("\t%s\n","Input String First !");break; case 5:if(c!=0)printf("\tOutput String :\"%s\"\n",s);else printf("\t%s\n","Input String First !");break; case 0:return 0; } } }
void Parser::advance() { /* PRE: hasMoreCommands() == true => next non-comment line contains a valid command. */ std::string s; do { std::getline(f_, s); current_line_number_++; trimLeft(s); } while (isComment(s) || s.empty()); trimRight(s); // Saving the line in lower case: std::transform(s.begin(), s.end(), s.begin(), ::tolower); current_line_ = s; }
string filenameFromPathname(const string &path) { string strippedPath(trimRight(trimLeft(path, "\t "), "\t ")); // special-case the root if (strippedPath == "/") { return strippedPath; } // directories are components too strippedPath = trimRight(strippedPath, "/"); vector<string> pathComponents(split(path, '/')); if (pathComponents.size() == 0) { THROW(ArgExc, "Expected at least one component of path '" << path << "', but saw none"); } return pathComponents[pathComponents.size() -1]; }
int CommandCheckAndReturncmdCode(char *str) { int cmdCode=0; str=trimLeft(str);//key=login|add|remove|list|quit|[error] //puts(str); if(strncasecmp("login",str,5)==0) cmdCode=1; if(strncasecmp("add",str,3)==0) cmdCode=2; if(strncasecmp("remove",str,6)==0) cmdCode=3; if(strncasecmp("list",str,4)==0) cmdCode=4; if(strncasecmp("quit",str,4)==0) cmdCode=5; //printf("common cmdcode %d\n",cmdCode); return cmdCode; }
void Parser::printFileInfo(std::ostream& os) { std::istream::streampos parsed_pos = f_.tellg(); // Saving stream position. std::ios::iostate status = f_.rdstate(); f_.clear(); f_.seekg(0, std::ios::beg); unsigned int lines = 0; unsigned int comments = 0; std::string s; while (getline(f_, s)) { trimLeft(s); if (isComment(s)) comments++; lines++; } os << "File has " << lines << " lines. "; os << lines-comments << " are commands. \n"; f_.seekg(parsed_pos); // Restoring stream to its original position. f_.setstate(status); }
int GetParaNumOfCmd(char *str) { int num=1; int i=0; int flag=0; str=trimLeft(str); if(str==NULL || strlen(str)==0) return 0; for(i=0;i<strlen(str);i++) { if((str[i]!=' ' && str[i]!='\t') && flag==1) { num++; flag=0; } else if(str[i]==' ' ||str[i]=='\t') { flag=1; } } return num; }
/** * Modify str in place to erase whitespace on the left and right. * @param str */ static void trim(string& str) { trimLeft(str); trimRight(str); }
void Properties::parseProperty(const QString &rProperty, int line) { Q_ASSERT_X(rProperty == trimLeft(rProperty), "parseProperty()", "rProperty has leading spaces"); enum State { KEY_STATE, KEYSPACE_STATE, SPACEVALUE_STATE, VALUE_STATE, KEYESCAPE_STATE, VALUEESCAPE_STATE, UNICODEESCAPE_STATE }; const QString value_escape_codes =QLatin1String(msValueEscapeCodes); const QString value_escape_chars = QLatin1String(msValueEscapeChars); Q_ASSERT_X(value_escape_codes.length() == value_escape_chars.length(), "parseProperty()", "Value escape sequence character definition does not map"); const QString key_escape_codes = QLatin1String(msKeyEscapeCodes); const QString key_escape_chars = QLatin1String(msKeyEscapeChars); Q_ASSERT_X(key_escape_codes.length() == key_escape_chars.length(), "parseProperty()", "Key escape sequence character definition does not map"); if (rProperty.isEmpty()) return; int i = 0; QChar c; char ch; State state = KEY_STATE; QString key; QString value; QString *p_string = &key; uint ucs; int ucs_digits; while (i < rProperty.length()) { // i points to the current character. // c contains the current character // ch contains the Latin1 equivalent of the current character // i is incremented at the end of the loop to consume the character. // continue is used to change state without consuming the character c = rProperty.at(i); ch = c.toLatin1(); switch (state) { case KEY_STATE: if (ch == '!' || ch == '#' ) return; else if (c.isSpace()) { p_string = &value; state = KEYSPACE_STATE; } else if (ch == '=' || ch == ':') { p_string = &value; state = SPACEVALUE_STATE; } else if (ch == msEscapeChar) state = KEYESCAPE_STATE; else *p_string += c; break; case KEYSPACE_STATE: if (ch == '=' || ch == ':') state = SPACEVALUE_STATE; else if (!c.isSpace()) { *p_string += c; state = VALUE_STATE; } break; case SPACEVALUE_STATE: if (!c.isSpace()) { *p_string += c; state = VALUE_STATE; } break; case VALUE_STATE: if (ch == msEscapeChar) state = VALUEESCAPE_STATE; else *p_string += c; break; case KEYESCAPE_STATE: { int convert = key_escape_codes.indexOf(c); if (convert >= 0) *p_string += key_escape_chars.at(convert); else { logger()->warn("Unknown escape sequence '\\%1' in key of property starting at line %2", QString(c), line); *p_string += c; } state = KEY_STATE; break; } case VALUEESCAPE_STATE: { int convert = value_escape_codes.indexOf(c); if (convert >= 0) { *p_string += value_escape_chars.at(convert); state = VALUE_STATE; } else if (ch == 'u') { ucs = 0; ucs_digits = 0; state = UNICODEESCAPE_STATE; } else { logger()->warn("Unknown escape sequence '\\%1' in value of property starting at line %2", QString(c), line); *p_string += c; state = VALUE_STATE; } break; } case UNICODEESCAPE_STATE: { int hex = hexDigitValue(c); if (hex >= 0) { ucs = ucs * 16 + hex; ucs_digits++; if (ucs_digits == 4 || i == rProperty.length() - 1) { *p_string += QChar(ucs); state = VALUE_STATE; } } else { if (ucs_digits > 0) *p_string += QChar(ucs); state = VALUE_STATE; continue; } break; } default: Q_ASSERT_X(false, "Properties::parseProperty()", "Unknown state constant"); return; } i++; } if (key.isEmpty() && !value.isEmpty()) logger()->warn("Found value with no key in property starting at line %1", line); logger()->trace("Loaded property '%1' : '%2'", key, value); insert(key, value); }
std::string& Utils::trim( std::string& str ) { return trimLeft( trimRight( str ) ); }
string trim(string s) { return trimRight(trimLeft(s)); }
/** enqueue a set of variants */ void VariantAlleleNormalizer::add(Variants const & vs) { bool all_homref = true; for(Call const & c : vs.calls) { if(!(c.isHomref() || c.isNocall())) { all_homref = false; break; } } for(auto const & x : vs.ambiguous_alleles) { if(!x.empty()) { all_homref = false; break; } } if (all_homref && !_impl->homref) { #ifdef DEBUG_VARIANTNORMALIZER std::cerr << "Skipping homref variant: " << vs << "\n"; #endif return; } // don't touch import fails if (vs.getInfoFlag("IMPORT_FAIL")) { _impl->buffered_variants.push(vs); return; } Variants nv(vs); size_t tmp = 0; _impl->current_maxpos.resize(std::max(_impl->current_maxpos.size(), nv.calls.size()), tmp); #ifdef DEBUG_VARIANTNORMALIZER std::cerr << "before: " << nv << "\n"; #endif if(_impl->ref_fasta) { int64_t new_start = -1; int64_t new_end = -1; int64_t leftshift_limit = -1; if(_impl->limit >= 0) { leftshift_limit = nv.pos - _impl->limit; } for (size_t rvc = 0; rvc < nv.variation.size(); ++rvc) { int64_t this_leftshift_limit = leftshift_limit; if(nv.chr == _impl->maxpos_chr) { for(size_t j = 0; j < nv.calls.size(); ++j) { for(size_t c = 0; c < nv.calls[j].ngt; ++c) { if(nv.calls[j].gt[c] - 1 == (int)rvc) { this_leftshift_limit = std::max(this_leftshift_limit, _impl->current_maxpos[j]); } } } } #ifdef DEBUG_VARIANTNORMALIZER std::cerr << "leftshift limit for " << nv.variation[rvc] << " is " << this_leftshift_limit << "\n"; #endif leftShift(*(_impl->ref_fasta), nv.chr.c_str(), nv.variation[rvc], this_leftshift_limit); trimLeft(*(_impl->ref_fasta), nv.chr.c_str(), nv.variation[rvc], _impl->refpadding); trimRight(*(_impl->ref_fasta), nv.chr.c_str(), nv.variation[rvc], _impl->refpadding); if(new_start < 0 || new_start > nv.variation[rvc].start) { new_start = nv.variation[rvc].start; } if(new_end < 0 || new_end > nv.variation[rvc].end) { new_end = nv.variation[rvc].end; } } if (new_start > 0 && new_end > 0) { nv.pos = new_start; nv.len = new_end - new_start + 1; // handle insertions if (nv.len == 0) { --nv.pos; nv.len = 1; } } } #ifdef DEBUG_VARIANTNORMALIZER std::cerr << "after: " << nv << "\n"; #endif if(_impl->maxpos_chr != nv.chr) { for(size_t j = 0; j < nv.calls.size(); ++j) { if(!nv.calls[j].isNocall() && !nv.calls[j].isHomref()) { _impl->current_maxpos[j] = nv.pos + nv.len - 1; } } } else { for(size_t j = 0; j < nv.calls.size(); ++j) { if(!nv.calls[j].isNocall() && !nv.calls[j].isHomref()) { _impl->current_maxpos[j] = std::max(nv.pos + nv.len - 1, _impl->current_maxpos[j]); } } } _impl->maxpos_chr = nv.chr; #ifdef DEBUG_VARIANTNORMALIZER std::cerr << "new max-shifting pos on " << _impl->maxpos_chr << " : "; for(size_t s = 0; s < _impl->current_maxpos.size(); ++s) { std::cerr << " s" << s << ": " << _impl->current_maxpos[s] << " "; } std::cerr << "\n"; #endif _impl->buffered_variants.push(nv); }
std::string string_util::trim(const std::string& s) { return trimRight(trimLeft(s)); }