Example #1
0
std::string concat_pathname_components(const std::string &comp1, const std::string &comp2)
{
   if (comp1.length() == 0 || comp2.length() == 0)
      return concat_pathname_components_simple(comp1, comp2);

   bool needToAddSlash = true; // so far

   // if comp1 ends in a "/" then no need to add slash
   const char *temp = comp1.c_str();
   if (temp[comp1.length()-1] == '/')
      needToAddSlash = false;

   // if comp2 begins with a "/" then no need to add slash
   if (comp2.length() && comp2[0] == '/')
	   needToAddSlash = false;
#if 0
   if (comp2.prefixed_by("/"))
      needToAddSlash = false;
#endif

   std::string result = comp1;
   if (needToAddSlash)
      result += "/";
   result += comp2;

   return result;
}