Example #1
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;
		}
	}
}
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());
}
Example #3
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 #4
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 #5
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 #6
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;
}
Example #7
0
	void StringUtil::toLowerCase(String& str)
	{
		std::transform(str.begin(),
			str.end(),
			str.begin(),
			tolower);
	}
Example #8
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 #9
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 #10
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 #11
0
/**
This function aligns the string table to a 4-byte boundary
@internalComponent
@released
@return Error status
@param aStr - string to be aligned
*/
void ElfProducer::AlignString(String& aStr) {

	if( aStr.size() %4 ){
		PLUCHAR	aPad = (PLUCHAR)(4 - (aStr.size() %4));

		while(aPad--) {
			aStr.insert(aStr.end(), 0);
		}
	}
}
Example #12
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 #13
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 #14
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 #15
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;
}
Example #17
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;
    }
}
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;
}
 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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
0
bool receive_request_test(ByteVector &request, int attempt)
{
	String data;
	switch (attempt) {
		case 0:
			data += "GET / HTTP/1.1\r\n";
			data += "Accept: */*\r\n";
			break;
		case 1:
			break;
		case 2:
			data += "User-Agent: Test\r\n";
			data += "Host";
			break;
		case 3:
			data += ": 127.0.0.1\r\n";
			data += "Content-Length: 4\r\n";
			break;
		case 4:
			data += "\r\n";
			break;
		case 5:
			break;
		case 6:
			data += "12";
			break;
		case 7:
			data += "34";
			break;
		default:
			return false;
	}
	
	request.insert(request.end(), data.begin(), data.end());
	return true;
}
Example #27
0
void Translate(const String& key, void* result, size_t size)
{
    String::const_iterator pos = key.begin();
    unsigned int* head = (unsigned int*)result;
    memset(result, 0, size);
    while(size > 0)
    {
        unsigned int value = 0;
        unsigned int bit = 1;
        while(pos != key.end())
        {
            if(*pos == '-')
            {
                ++pos;
                break;
            }
            int delta;
            switch(*pos)
            {
                case '2':
                    delta = 0;
                    break;
                case '6':
                    delta = 1;
                    break;
                case '3':
                    delta = 2;
                    break;
                case '7':
                    delta = 3;
                    break;
                case '4':
                    delta = 4;
                    break;
                case '8':
                    delta = 5;
                    break;
                case '0':
                    delta = 6;
                    break;
                case '5':
                    delta = 7;
                    break;
                case '1':
                    delta = 8;
                    break;
                case '9':
                    delta = 9;
                    break;
                case 'A':
                    delta = 10;
                    break;
                case 'M':
                    delta = 11;
                    break;
                case 'W':
                    delta = 12;
                    break;
                case 'R':
                    delta = 13;
                    break;
                case 'S':
                    delta = 14;
                    break;
                case 'T':
                    delta = 15;
                    break;
                case 'Y':
                    delta = 16;
                    break;
                case 'F':
                    delta = 17;
                    break;
                case 'B':
                    delta = 18;
                    break;
                case 'P':
                    delta = 19;
                    break;
                case 'U':
                    delta = 20;
                    break;
                case 'V':
                    delta = 21;
                    break;
                case 'C':
                    delta = 22;
                    break;
                case 'K':
                    delta = 23;
                    break;
                case 'L':
                    delta = 24;
                    break;
                case 'X':
                    delta = 25;
                    break;
                case 'N':
                    delta = 26;
                    break;
                case 'D':
                    delta = 27;
                    break;
                case 'G':
                    delta = 28;
                    break;
                case 'H':
                    delta = 29;
                    break;
                case 'Q':
                    delta = 30;
                    break;
                case 'Z':
                    delta = 31;
                    break;
                default:
                    return;
            };
            value += delta * bit;
            static const int MapSize = 32;
            ++pos;
            bit *= MapSize;
        }
        if(size >= sizeof(unsigned int))
        {
            *head = value;
            ++head;
            size -= sizeof(unsigned int);
        } else {
            memcpy(head, &value, size);
            break;
        }
    }
}
Example #28
0
bool String::operator<(const String& other) const {
    return std::lexicographical_compare(begin(), end(), other.begin(), other.end());
}
 Bytes TestCase1Uncompressed()
 {
   static const String data = "foobar\n";
   return Bytes(new Bytes::element_type(data.begin(), data.end()));
 }
Example #30
0
String::String(const String & s) {
    auto newdata = alloc.allocate(s.size( ));
    std::uninitialized_copy(s.begin( ), s.end( ), newdata);
    elements = newdata;
    cap = first_free = newdata + s.size( );
}