Example #1
0
	void StringUtil::toLowerCase(String& str)
	{
		std::transform(str.begin(),
			str.end(),
			str.begin(),
			tolower);
	}
Example #2
0
template<class String> inline
void append_string(String& dst, const String& src,
                   const typename String::size_type beg,
                   const typename String::size_type end) 
   {
     dst.append(src.begin()+beg, src.begin()+end);
   }
Example #3
0
String Path::ExtractPathFromCmdLine(String& input)
{
	String r;
	input.Trim();
	bool q = input[0] == '"';
	size_t i = q ? 1 : 0;
	while(i < input.size())
	{
		if(q)
		{
			if(input[i] == '"')
			{
				break;
			}
		}
		else
		{
			if(input[i] == ' ')
			{
				break;
			}
		}
		r += input[i];
		i++;
	}
	input.erase(input.begin(), input.begin() + r.size() + (q ? 2 : 0));
	input.Trim();
	return r;
}
Example #4
0
	Bool Object::getBoolean() const
	{
		switch (this->getNativeType())
		{
		default:
			throw ObjectConversionException(FORMAT("Unknown DataType %u", this->getNativeType()));

		case NIL:
			return false;

		case BOOLEAN:
			return this->data.boolean;

		case NUMBER:
			return this->data.number != 0;

		case ADDRESS:
			return false;

		case STRING:
		{
			String lower = this->data.string;
			std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
			return !String(this->data.string).empty();
		}

		case USERDATA:
			return this->data.userdata != 0;
		}
	}
Example #5
0
bool operator==(const String & lhs, const String & rhs) {
    if(lhs.size( ) == rhs.size( )) {
        auto r = rhs.begin( );
        for(auto l = lhs.begin( ); l != lhs.end( ); ++l) {
            if(*l != *r) {
                return false;
            } else {
                ++r;
            }
        }
        return true;
    } else {
        return false;
    }
}
Example #6
0
bool File::skipUntil(const String &text) {
	/**
	 * skipUntil(): Set file cursor after the next occurrence of 'text'.
	 *    Return false if 'text' was not found.
	 */
	char *wtf = NULL;
	while (good()) {
		if (myRdBufPos < myRdBufEnd) {
			wtf = ssi::strnstr(myRdBuf + myRdBufPos, text.begin(), myRdBufEnd - myRdBufPos);
		}
		if (wtf) {
			myRdBufPos = wtf - myRdBuf + text.length();
			return true;
		}
		
		/* 
		 * Not found yet => refill buffer.
		 * We leave the last (len - 1) chars in the buffer in case the
		 * text we're looking for is split across 2 buffer reads.
		 */
		INT64 leave =  text.length() - 1;
		if (leave > myRdBufEnd - myRdBufPos) {
			leave = myRdBufEnd - myRdBufPos;
		}
		memmove(myRdBuf, myRdBuf + myRdBufEnd - leave, leave);
		myRdBufEnd = ::read(myFd, myRdBuf + leave, myBufSize - leave) + leave;
		myRdBufPos = 0;
		myEof = (myRdBufEnd == leave);
	}
	
	return false;
}
Example #7
0
String::String(const String& s)
{
    std::cout << "copy constructor used" << std::endl;
    auto data = alloc_n_copy(s.begin(), s.end());
    elements = data.first;
    first_free = data.second;
}
Example #8
0
// return true if the string contains any characters which must be encoded
static bool NeedsEncoding(const String& in)
{
   // if input contains "=?", encode it anyhow to avoid generating invalid
   // encoded words
   if ( in.find(_T("=?")) == wxString::npos )
   {
      // only encode the strings which contain the characters unallowed in RFC
      // 822 headers
      wxString::const_iterator p;
      const wxString::const_iterator end = in.end();
      for ( p = in.begin(); p != end; ++p )
      {
         if ( NeedsEncodingInHeader(*p) )
            break;
      }

      if ( p == end )
      {
         // string has only valid chars, don't encode
         return false;
      }
   }

   return true;
}
inline bool string_parse(
    String const& ucstr, String const& lcstr
    , Iterator& first, Iterator const& last, Attribute& attr)
{
    typename String::const_iterator uc_i = ucstr.begin();
    typename String::const_iterator uc_last = ucstr.end();
    typename String::const_iterator lc_i = lcstr.begin();
    Iterator i = first;

    for (; uc_i != uc_last; ++uc_i, ++lc_i, ++i)
        if (i == last || ((*uc_i != *i) && (*lc_i != *i)))
            return false;
    spirit::traits::assign_to(first, i, attr);
    first = i;
    return true;
}
Example #10
0
String::String(const String& str)
{
	auto newdata = alloc_n_copy(str.begin(), str.end());
	elements = newdata.first;
	firstfree = cap = newdata.second;
	std::cout << "copy construct" << std::endl;
}
Example #11
0
String::String(const String &s)
{
    cout << "copy constructor" << endl;
    auto newdata = alloc_n_copy(s.begin(), s.end());
    elements = newdata.first;
    first_free = cap = newdata.second;
}
Example #12
0
void KeywordParam::eat_separator_after(const String& text, size_t& i) {
	if (separator_after_eat.empty()) return;
	Regex::Results result;
	if (separator_after_eat.matches(result, text.begin() + i, text.end())) {
		// advance past the separator
		assert(result.position() == 0);
		i += result.length();
	}
}
Example #13
0
bool operator>(const String & lhs, const String & rhs) {
    auto r = rhs.begin( );
    for(auto l = lhs.begin( ); l != lhs.end( ); ++l) {
        if(*r <= *l) {
            return false;
        } else {
            if(*r > *l) {
                return true;
            } else {
                r++;
            }
        }
    }
    if(r == rhs.end( )) {
        return false;
    } else {
        return true;
    }
}
Example #14
0
bool ConfigFile::macroParse(String& value, const char* fileName) const
{
	String::size_type subFrom;

	while ((subFrom = value.find("$(")) != String::npos)
	{
		String::size_type subTo = value.find(")", subFrom);
		if (subTo != String::npos)
		{
			String macro;
			String m = value.substr(subFrom + 2, subTo - (subFrom + 2));
			if (! translate(fileName, m, macro))
			{
				return false;
			}
			++subTo;

			// Avoid double slashes in pathnames
			PathUtils::setDirIterator(value.begin());
			PathUtils::setDirIterator(macro.begin());

			if (subFrom > 0 && value[subFrom - 1] == PathUtils::dir_sep &&
				macro.length() > 0 && macro[0] == PathUtils::dir_sep)
			{
				--subFrom;
			}
			if (subTo < value.length() && value[subTo] == PathUtils::dir_sep &&
				macro.length() > 0 && macro[macro.length() - 1] == PathUtils::dir_sep)
			{
				++subTo;
			}

			// Now perform operation
			value.replace(subFrom, subTo - subFrom, macro);
		}
		else
		{
			return false;
		}
	}

	return true;
}
Example #15
0
    //-----------------------------------------------------------------------
    String StringUtil::standardisePath(const String& init)
    {
        String path = init;

        std::replace( path.begin(), path.end(), '\\', '/' );
        if( path[path.length() - 1] != '/' )
            path += '/';

        return path;
    }
Example #16
0
    //--------------------------------
    bool Utils::equalsIgnoreCase ( const String& s1, const String& s2 )
    {
        String::const_iterator it1=s1.begin();
        String::const_iterator it2=s2.begin();

        // has the end of at least one of the strings been reached?
        while ( (it1!=s1.end()) && (it2!=s2.end()) )
        {
            if(::toupper(*it1) != ::toupper(*it2)) //letters differ?
                // return -1 to indicate 'smaller than', 1 otherwise
                return false;
            // proceed to the next character in each string
            ++it1;
            ++it2;
        }
        size_t size1=s1.size(), size2=s2.size();// cache lengths
        //return -1,0 or 1 according to strings' lengths
        if (size1==size2)
            return true;
        return false;
    }
Example #17
0
String _cleanPath(const String& name) {
	String path = name;
	for (size_t i = 0; i < path.size(); ++i) {
		auto& c = path[i];
		if (c == ':' || c == '\\' || c == '/') { //TODO more invalid chars
			path.erase(path.begin() + i);
			--i;
		}
	}

	return path;
}
Example #18
0
void BoldFontProcessor::ProcessString(String &str)
{
    for (String::iterator it = str.begin(); it != str.end(); it++)
    {
        Word *wordPtr = dynamic_cast<Word*>(*it);

        if (!wordPtr)
            continue;

        if (m_voc.IsWordIncluded(wordPtr->StrRepr()))
            wordPtr->SetFontStyle(Word::ItalicBold);
    }
}
Example #19
0
void Wikidiff2::explodeLines(const String & text, StringVector &lines)
{
	String::const_iterator ptr = text.begin();
	while (ptr != text.end()) {
		String::const_iterator ptr2 = std::find(ptr, text.end(), '\n');
		lines.push_back(String(ptr, ptr2));

		ptr = ptr2;
		if (ptr != text.end()) {
			++ptr;
		}
	}
}
Example #20
0
static bool compare_nocase_breadth_first(const String& first, const String& second) {
    // Check "path depth" first
    unsigned firstPathDepth = std::count(first.begin(), first.end(), '/');
    unsigned secondPathDepth = std::count(second.begin(), second.end(), '/');
    if (firstPathDepth < secondPathDepth)
        return true;
    else if (firstPathDepth > secondPathDepth)
        return false;

    unsigned i = 0;
    while ((i < first.length()) && (i < second.length())) {
        if (tolower(first[i]) < tolower(second[i]))
            return true;
        else if (tolower(first[i]) > tolower(second[i]))
            return false;
        ++i;
    }

    if (first.length() < second.length())
        return true;
    else
        return false;
}
inline bool string_parse(
    String const& str
    , Iterator& first, Iterator const& last, Attribute& attr)
{
    Iterator i = first;
    typename String::const_iterator stri = str.begin();
    typename String::const_iterator str_last = str.end();

    for (; stri != str_last; ++stri, ++i)
        if (i == last || (*stri != *i))
            return false;
    spirit::traits::assign_to(first, i, attr);
    first = i;
    return true;
}
void Document::loadFromCurrenttDir( const String& fileName_ )
{
	FRL_EXCEPT_GUARD();
	String currDir = io::fs::getCurrentDirectory();
	io::fs::addSlashToEndPath( currDir );
	fileName = currDir + fileName_;
	String buffer;
	loadFileToString( fileName, buffer );
	buffer.erase( std::remove_if( buffer.begin(), buffer.end(), private_::isCRLF ), buffer.end() ); // remove CRLF
	parseHeader( buffer );
	NodesList tmpMap = Parser::getSubNodes( buffer );
	if( tmpMap.size() > 1 )
		FRL_THROW_S_CLASS( Document::BrokenXML ); // must be one root node
	root = (*tmpMap.begin());
}
 void CompNovoIdentificationBase::permute_(String prefix, String s, set<String> & permutations)
 {
   if (s.size() <= 1)
   {
     permutations.insert(prefix + s);
   }
   else
   {
     for (String::Iterator p = s.begin(); p < s.end(); p++)
     {
       char c = *p;
       p = s.erase(p);
       permute_(prefix + c, s, permutations);
       s.insert(p, c);
     }
   }
 }
  AASequence CompNovoIdentificationBase::getModifiedAASequence_(const String & sequence)
  {
    AASequence seq;
    for (String::ConstIterator it = sequence.begin(); it != sequence.end(); ++it)
    {
      if (name_to_residue_.has(*it))
      {
        seq += name_to_residue_[*it];
      }
      else
      {
        seq += *it;
      }
    }

    return seq;
  }
Example #25
0
String Path::ReplaceExtension(String path, String newExt)
{
	newExt.TrimFront('.');

	// Remove everything in the extension and the dot
	size_t dotPos = path.find_last_of(".");
	if(dotPos != -1)
	{
		path.erase(path.begin() + dotPos, path.end());
	}

	if(newExt.empty())
		return path;

	path.push_back('.');
	path += newExt;

	return path;
}
Example #26
0
/**
This function sets the section header fields.
@internalComponent
@released
@return Error status
@param aSectionIndex The index of the section
@param aSectionName The name of the section
@param aType The type of the section
@param aEntSz The size of each entry of the section
@param aSectionSize The size of the section
@param aLink The section this section is linked to
@param aInfo Extra information. Depends on the section type of this section.
@param aAddrAlign The address alignment of this section.
@param aFlags Section flags
@param aAddr The address of this section in memory(Here it remains 0)
*/
void ElfProducer::SetSectionFields(PLUINT32 aSectionIndex, char* aSectionName, PLUINT32 aType, \
								   PLUINT32 aEntSz, PLUINT32 aSectionSize, PLUINT32 aLink, \
								   PLUINT32 aInfo, PLUINT32 aAddrAlign, PLUINT32 aFlags, \
								   PLUINT32 aAddr)
{
	String aSecName = aSectionName;

	iSections[aSectionIndex].sh_name			= iDSOSectionNames.size();
	iDSOSectionNames.insert(iDSOSectionNames.end(), aSecName.begin(), aSecName.end());
	iDSOSectionNames.insert(iDSOSectionNames.end(), 0);
	
	iSections[aSectionIndex].sh_type			= aType;
	iSections[aSectionIndex].sh_entsize		= aEntSz;
	iSections[aSectionIndex].sh_size			= aSectionSize;
	iSections[aSectionIndex].sh_link			= aLink;
	iSections[aSectionIndex].sh_flags		= aFlags;
	iSections[aSectionIndex].sh_addralign	= aAddrAlign;
	iSections[aSectionIndex].sh_info			= aInfo;
	iSections[aSectionIndex].sh_addr			= aAddr;
}
Example #27
0
  void
  UniqueIdInterface::setUniqueId(const String & rhs)
  {
    clearUniqueId();

    String::size_type last_underscore = rhs.rfind('_');
    String s = rhs.substr(last_underscore + 1);

    for (String::const_iterator s_i = s.begin(); s_i < s.end(); ++s_i)
    {
      int i = (*s_i - '0');
      if (i < 0 || i > 9)
      {
        clearUniqueId();
        return;
      }
      unique_id_ = 10 * unique_id_ + i;
    }

  }
Example #28
0
    //-----------------------------------------------------------------------
    void StringUtil::splitFilename(const String& qualifiedName, 
        String& outBasename, String& outPath)
    {
        String path = qualifiedName;
        // Replace \ with / first
        std::replace( path.begin(), path.end(), '\\', '/' );
        // split based on final /
        size_t i = path.find_last_of('/');

        if (i == String::npos)
        {
            outPath.clear();
			outBasename = qualifiedName;
        }
        else
        {
            outBasename = path.substr(i+1, path.size() - i - 1);
            outPath = path.substr(0, i+1);
        }

    }
Example #29
0
 std::vector<Size> EnzymaticDigestion::tokenize_(const String& s) const
 {
   std::vector<Size> pep_positions;
   Size pos = 0;
   boost::regex re(enzyme_.getRegEx());
   if (enzyme_.getRegEx() != "()") // if it's not "no cleavage"
   {
     boost::sregex_token_iterator i(s.begin(), s.end(), re, -1);
     boost::sregex_token_iterator j;
     while (i != j)
     {
       pep_positions.push_back(pos);
       pos += (i++)->length();
     }
   }
   else
   {
     pep_positions.push_back(pos);
   }
   return pep_positions;
 }
Example #30
0
String File::readUntil(const String &text) {
	/**
	 * readUntil(): Return file contents before the next occurrence of 'text'.
	 *    If 'text' is not found, an empty string is returned.
	 *    NB: Careful when searching in large files!
	 */
	String result;
	char *wtf = NULL;
	while (good()) {
		if (myRdBufPos < myRdBufEnd) {
			wtf = ssi::strnstr(myRdBuf + myRdBufPos, text.begin(), myRdBufEnd - myRdBufPos);
		}
		if (wtf) {
			INT64 new_pos = wtf - myRdBuf;
			result += String(myRdBuf + myRdBufPos, new_pos - myRdBufPos);
			myRdBufPos = new_pos + text.length();
			return result;
		}
		
		/* 
		 * Not found yet => refill buffer.
		 * We leave the last (len - 1) chars in the buffer in case the
		 * text we're looking for is split across 2 buffer reads.
		 */
		INT64 leave =  text.length() - 1;
		if (leave > myRdBufEnd - myRdBufPos) {
			leave = myRdBufEnd - myRdBufPos;
		}
		result += String(myRdBuf + myRdBufPos, myRdBufEnd - myRdBufPos - leave);
		memmove(myRdBuf, myRdBuf + myRdBufEnd - leave, leave);
		myRdBufEnd = ::read(myFd, myRdBuf + leave, myBufSize - leave) + leave;
		myRdBufPos = 0;
		myEof = (myRdBufEnd == leave);
	}
	
	return result;
}