//compare two strings starting from the end
//returns similar to strncmp
int rstrncmp(std::string lhs, std::string rhs, int rnum) {
	auto lit = lhs.rbegin();
	auto rit = rhs.rbegin();
	int ret = 0;

	while (rnum-- > 0) {
		if (*lit < *rit) {
			ret = -1;
			break;
		}
		if (*lit > *rit) {
			ret = 1;
			break;
		}

		//check if the "end" of the string has been reached
		if (lit++ == lhs.rend()) {
			rnum = -1;
			ret += -1;
		}
		if (rit++ == rhs.rend()) {
			rnum = -1;
			ret += 1;
		}
	}

	//rnum ran out or was set to -1
	return ret;
}
示例#2
0
bool URIUtils::HasExtension(const std::string& strFileName, const std::string& strExtensions)
{
  if (IsURL(strFileName))
  {
    CURL url(strFileName);
    return HasExtension(url.GetFileName(), strExtensions);
  }

  // Search backwards so that '.' can be used as a search terminator.
  std::string::const_reverse_iterator itExtensions = strExtensions.rbegin();
  while (itExtensions != strExtensions.rend())
  {
    // Iterate backwards over strFileName untill we hit a '.' or a mismatch
    for (std::string::const_reverse_iterator itFileName = strFileName.rbegin();
         itFileName != strFileName.rend() && itExtensions != strExtensions.rend() &&
         tolower(*itFileName) == *itExtensions;
         ++itFileName, ++itExtensions)
    {
      if (*itExtensions == '.')
        return true; // Match
    }

    // No match. Look for more extensions to try.
    while (itExtensions != strExtensions.rend() && *itExtensions != '|')
      ++itExtensions;

    while (itExtensions != strExtensions.rend() && *itExtensions == '|')
      ++itExtensions;
  }

  return false;
}
示例#3
0
std::string util::remove_extension( std::string const& filename ) {
    auto pivot = std::find(filename.rbegin(), filename.rend(), '.');
    if (pivot == filename.rend()) {
        return filename;
    }
    return std::string(filename.begin(), pivot.base() - 1);
}
示例#4
0
文件: dirname.cpp 项目: bbrrck/libigl
IGL_INLINE std::string igl::dirname(const std::string & path)
{
  if(path == "")
  {
    return std::string("");
  }
#if defined (WIN32)
  char del('\\');
#else
  char del('/');
#endif
  // http://stackoverflow.com/questions/5077693/dirnamephp-similar-function-in-c
  std::string::const_reverse_iterator last_slash =
    std::find(
      path.rbegin(), 
      path.rend(),del);
  if( last_slash == path.rend() )
  {
    // No slashes found
    return std::string(".");
  }else if(1 == (last_slash.base() - path.begin()))
  {
    // Slash is first char
    return std::string(&del);
  }else if(path.end() == last_slash.base() )
  {
    // Slash is last char
    std::string redo = std::string(path.begin(),path.end()-1);
    return igl::dirname(redo);
  }
  return std::string(path.begin(),last_slash.base()-1);
}
示例#5
0
    virtual SharedAssetTypeT loadAsset( const std::string& name ) noexcept override
    {
        SharedAssetTypeT shared;

        auto rit( name.rbegin() );
        while ( rit != name.rend() )
        {
            if ( *rit == ':' )
            {
                break;
            }
            ++rit;
        }
        if ( rit == name.rend() )
        {
            assert( false && "FontMgr can't parse willing font ptsize from asset name" );
        }
        auto fit = --( rit.base() ); //forward iterator

        std::string fileName{ name.begin(), fit };
        std::string ptStr{ ++fit, name.end() };
        int ptSize{ std::stoi( ptStr ) };

        TTF_Font* rawFont{ TTF_OpenFontIndex( fileName.c_str(), ptSize, 0 ) };
        if ( rawFont == nullptr )
        {
            //TODO: some logging lib needed
        }
        else
        {
            shared = Font::create( rawFont, ptSize );
        }
        return ( shared );
    }
示例#6
0
void
check_lcs_delta_algorithm()
{
	cout << "******* check_lcs_delta_algorithm()" << endl;

	const std::string nano = "nano";
	const std::string aano = "aano";
	const std::string ano = "ano";
	const std::string anoo = "anoo";
	const std::string nematode_knowledge = "nematode knowledge";
	const std::string empty_bottle = "empty bottle";

	test_lcs_delta(nano, aano, "ano");
	test_lcs_delta(nano, ano, "ano");
	test_lcs_delta(nano, anoo, "ano");
	test_lcs_delta(ano, ano, "ano");
	test_lcs_delta(nano, nematode_knowledge, "nano");
	test_lcs_delta(empty_bottle, nematode_knowledge, "emt ole");

	//use an equals with a wildcard
	{
		const std::string x = "nano";
		const std::string y = "aaao";

		std::string result_x;
		std::string result_y;
		lcs_delta(
			x.rbegin(),
			x.rend(),
			y.rbegin(),
			y.rend(),
			make_lcs_inserter(result_x, result_y),
			WildcardNsEqualTo());
		BOOST_CHECK_EQUAL(y, result_y);
		BOOST_CHECK_EQUAL(x, result_x);
	}

	//test on real sequences
	{
#ifdef VERBOSE_CHECKING
		cout << "Testing DLX5 remo 1" << endl;
#endif

		build_test_remos();

#ifdef VERBOSE_CHECKING
		boost::progress_timer timer;
#endif

		seq_t result;
		lcs_delta(
			test_remos["dlx5_1"]->map[MOUSE_SPECIES].rbegin(),
			test_remos["dlx5_1"]->map[MOUSE_SPECIES].rend(),
			test_remos["dlx5_1"]->map[HUMAN_SPECIES].rbegin(),
			test_remos["dlx5_1"]->map[HUMAN_SPECIES].rend(),
			make_lcs_inserter(result));
		BOOST_CHECK_EQUAL(result.size(), 574u);
	}
}
示例#7
0
std::string FileSystem::getFilename(const std::string &filePath)
{
    auto lastSlashPos = std::find_if(filePath.rbegin(), filePath.rend(), [](char ch) { return ch == '/' || ch == '\\'; });
    if (lastSlashPos == filePath.rend())
        return "";

    return std::string(lastSlashPos.base(), filePath.end());
}
示例#8
0
std::string get_txt_file_for(const std::string file_path) {
  auto it = file_path.rbegin();
  for (; it != file_path.rend() && *it != '.'; ++it);
  if (it == file_path.rend())
    return file_path + ".txt";
  else
    return std::string(file_path.begin(), file_path.end() - (it - file_path.rbegin())) + "txt";
}
示例#9
0
文件: main.cpp 项目: DDMAL/aruspix
std::string removePath( std::string const& filename )
{
    std::string::const_reverse_iterator
    pivot
    = std::find( filename.rbegin(), filename.rend(), '/' );
    return pivot == filename.rend()
    ? filename
    : std::string( pivot.base(), filename.end() );
}
示例#10
0
文件: main.cpp 项目: DDMAL/aruspix
std::string removeExtension( std::string const& filename )
{
    std::string::const_reverse_iterator
    pivot
    = std::find( filename.rbegin(), filename.rend(), '.' );
    return pivot == filename.rend()
    ? filename
    : std::string( filename.begin(), pivot.base() - 1 );
}
示例#11
0
OutT matches2 (std::string const& ws, std::string const& s, OutT dst) {
  std::string sw (ws.rbegin (), ws.rend ());
  std::size_t num_chars=s.size ();
  for (std::size_t i = 0; i < num_chars; ++i) {
    std::string::const_reverse_iterator rbegin = s.rbegin ();
    std::advance (rbegin, num_chars - i);
    if (prefix (sw.begin (), sw.end (), rbegin, s.rend ()))  {
      *dst++ = i;
    }
  }

  return dst;
}
示例#12
0
        RAYTRACER_EXPORTS static std::string getParentDirectoryFromFilePath(std::string filePath) {
            replaceSubstring(filePath, "\\", "/");
            std::string::reverse_iterator sit = filePath.rbegin();
            int stopAt(0);
            while (stopAt != 2 && sit != filePath.rend()) {
                if ((*sit) == '/')
                    ++stopAt;
                ++sit;
            }

            std::string directory(sit, filePath.rend());
            std::reverse(directory.begin(), directory.end());
            directory += "/";
            return directory;
        }
示例#13
0
bool getNext(std::string& s, char skip) {
    std::string::reverse_iterator j = s.rbegin();
    while (j != s.rend()) {
	*j = '0' + (*j - '0' + 1) % 10;
	bool carry = *j == '0';
	if (*j == skip) {
	    *j = '0' + (*j - '0' + 1) % 10;
	    carry |= *j == '0';
	}

	if (carry) ++j;
	else break;
    }
    
    return j != s.rend();
}
示例#14
0
std::string basename( std::string const& pathname )
{
    return std::string( 
        std::find_if( pathname.rbegin(), pathname.rend(),
                      MatchPathSeparator() ).base(),
        pathname.end() );
}
示例#15
0
 /**
  *  Trim spaces
  *  @param  strig
  */
 void IniConfigs::trim(std::string &str) const
 {
     // trim from start
     str.erase(str.begin(), std::find_if(str.begin(), str.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
     // trim from end
     str.erase(std::find_if(str.rbegin(), str.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), str.end());
 }
示例#16
0
void test_both(std::string const& caseid,
               T pi_x, T pi_y, T pj_x, T pj_y, T pk_x, T pk_y,
               T qi_x, T qi_y, T qj_x, T qj_y, T qk_x, T qk_y,
               bg::detail::overlay::method_type method
               = bg::detail::overlay::method_none,
               T ip_x = -1, T ip_y = -1,
               std::string const& expected = "",
               T ip_x2 = -1, T ip_y2 = -1)
{
    test_with_point<P, double>(caseid,
                               pi_x, pi_y, pj_x, pj_y, pk_x, pk_y,
                               qi_x, qi_y, qj_x, qj_y, qk_x, qk_y,
                               method, ip_x, ip_y, expected, ip_x2, ip_y2);

    //return;

    std::string reversed(expected.rbegin(), expected.rend());

    if (ip_x2 >= 0 && ip_y2 >= 0)
    {
        std::swap(ip_x, ip_x2);
        std::swap(ip_y, ip_y2);
    }

    test_with_point<P, double>(caseid + "_r",
                               qi_x, qi_y, qj_x, qj_y, qk_x, qk_y, // q
                               pi_x, pi_y, pj_x, pj_y, pk_x, pk_y, // p
                               method, ip_x, ip_y, reversed, ip_x2, ip_y2);
}
示例#17
0
		// Trim left and right side of the string.
		static std::string trim(std::string str)
		{
			str.erase(str.begin(), std::find_if(str.begin(), str.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
			str.erase(std::find_if(str.rbegin(), str.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), str.end());

			return str;
		}
示例#18
0
void Dictionary::addWord( const std::string &word )
{
    TrieNode *node = root_;

    int tmp = 0;
    for ( auto it = word.rbegin(); it != word.rend(); ++it )
    {
        char c = *it;
        if ( !isdigit(c) && !isalpha(c) )
        {
            ++tmp;
            continue;
        }
        TrieNode *next_node = node->contain(c); 
        if ( next_node ) 
        {
            node = next_node;    
            continue;
        }
        node = node->addNode(c);
    }
    
    max_length_ = std::max( max_length_, word.size() - tmp );
    if ( node != root_ )
    {
        node->setEndWord(true);
    }
}
示例#19
0
std::string Breakpoint::rev_complement(std::string seq) {
	std::string tmp;
	for (std::string::reverse_iterator i = seq.rbegin(); i != seq.rend(); i++) {
		tmp += complement((*i));
	}
	return tmp;
}
std::string HRStringHelper::stringFormat(const std::string &str,
                                         unsigned int unit,
                                         const std::string &delimiter,
                                         bool reverse /* = false */)
{
    std::string ret;
    int i = 1;
    
    if (reverse) {
        // 後ろから
        const auto begin = str.rbegin();
        const auto end   = str.rend();
        for (auto iter=begin; iter!=end; iter++) {
            ret = (*iter) + ret;
            if (i%unit == 0 && iter+1 != end) ret = delimiter + ret;
            i++;
        }
    }
    else {
        // 前から
        const auto begin = str.begin();
        const auto end   = str.end();
        for (auto iter=begin; iter!=end; iter++) {
            ret = ret + (*iter);
            if (i%unit == 0 && iter+1 != end) ret = ret + delimiter;
            i++;
        }
    }
    
    return ret;
}
示例#21
0
OutT matches (std::string const& ws, std::string const& s, OutT dst) {
  typedef std::pair<int, std::deque<char>> acc_t;

  auto step = [](acc_t p, char x) -> acc_t {
    ++p.first;
    p.second.push_front (x);

    return p;
  };

  std::deque<acc_t> buf;
  scan_left (
      step
    , std::make_pair(0, std::deque<char>())
    , s.begin ()
    , s.end ()
    , std::back_inserter(buf));

  std::string sw(ws.rbegin (), ws.rend ());
  auto pred = [&sw] (auto p) -> bool { 
    return prefix (
      sw.begin (), sw.end ()
    , p.second.begin (), p.second.end ()); 
  };
  std::deque<acc_t> temp;
  filter (pred, buf, std::back_inserter (temp));

  return std::transform (
     temp.begin (), temp.end (), dst, 
     [](acc_t const& p) -> int {  return p.first; });
}
示例#22
0
std::string right_trim(std::string s) {
  s.erase(std::find_if(
              s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace)))
              .base(),
          s.end());
  return s;
}
示例#23
0
		/**
		 * \param input The string.
		 */
		inline void trimr(std::string & s) {
			std::string::reverse_iterator ri;
			for (ri = s.rbegin();
				 ri != s.rend() && isSpace(*ri);
				 ++ri);
			s.erase(ri.base(), s.end());
		}
示例#24
0
std::string extract_dir_name(const std::string &str)
{
	for(std::string::const_reverse_iterator f=str.rbegin(),en=str.rend();f!=en;++f)
		if (*f=='/')
			return str.substr(0,en-f);			
	return str;
}
示例#25
0
BigInteger::BigInteger(const std::string& integer) : data(integer.size())
{
  std::transform(integer.rbegin(), integer.rend(), data.begin(), [](char c)
                 {
                   return c - '0';
                 });
}
示例#26
0
文件: text.hpp 项目: hallor/vasum
inline bool endsWith(std::string const &value, std::string const &part)
{
     if (part.size() > value.size()) {
         return false;
     }
     return std::equal(part.rbegin(), part.rend(), value.rbegin());
}
示例#27
0
std::string right_trim(std::string s) {
  s.erase(
      std::find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch); })
          .base(),
      s.end());
  return s;
}
示例#28
0
std::string skyGetFileNameFromDirectory( std::string const& a_strPath )
{
    return std::string( 
        std::find_if( a_strPath.rbegin(), a_strPath.rend(),
                      skyMatchPathSeparator() ).base(),
        a_strPath.end() );
}
示例#29
0
bool palindrome(std::string&str)
{
    //std::string temp(str.rbegin(), str.rend());
    std::string temp;
    copy(str.rbegin(),str.rend(), std::insert_iterator<std::string>(temp, temp.begin()));
    return temp == str;
}
示例#30
0
std::string skyGetFileExtension(std::string const& a_strFileName)
{
	return std::string( 
        std::find_if( a_strFileName.rbegin(), a_strFileName.rend(),
                      skyMatchExtensionSeparator() ).base(),
        a_strFileName.end() );
}