/*
 * Note to Dr. Sridhar:
 * This file contains a declaration for a new method to be added to
 * CL_PathName, and implementation for that method.  Also, I include a
 * corrected version of method FileName().
 *
 * Ideally, this file should never show up in the YACL distribution; rather,
 * it should be folded into the existing io/pathname.h and io/pathname.cxx
 * files.
 */

// Please add the following to the public protocol for CL_PathName:
	 CL_String Extension () const;
	 // Return the extension of the filename, that is the part that follows
	 // the last dot in the filename portion.  The dot is part of the returned
	 // string.  If the filename has no extension, return an empty string.
	 //
	 // Examples : D:\Directory.dir\file.name.with.ext --> ".ext"
	 //				/etc/mail/sendmail.cf					--> ".cf"
	 //				/usr/foo.bar/file                   --> ""
	 //
	 // (contributed by Ludovic Brenta <brenta@gprhp.insa-lyon.fr>

// Now add these to the pathname.cxx implementation file :

CL_String CL_PathName::FileName () const
{
	/* Corrected by Ludovic Brenta - 27 May 1997 */
	return _pathName.Suffix(_RightmostSeparatorPos() + 1);
	//                                              ^^^^ added
}




/* public */ CL_String CL_PathName::Extension() const
// This method has been contributed to the CL_PathName class.
// Author  : Ludovic Brenta <brenta@gprhp.insa-lyon.fr>
// Date	  : 14 Feb 1997
{
	long i = _pathName.Length() - 1;  // start at the end of the file name
	while(i > 0 && _pathName(i) != '.')
	{
		// If we reach the beginning of the file name (end of the path),
		// go no further.
		#ifdef __UNIX__ // no backslash under Unix
		if(_pathName(i) == '/') i = 0; // using CL_String's operator () is faster
		#else
		if(_pathName(i) == '/' || _pathName(i) == '\\') i = 0;
		#endif
		i--;
	}
	// Now _pathName(i) sould be a dot, or else i == 0.
	if(i == 0 && _pathName(i) != '.') return CL_String();
	else return _pathName.Suffix(i);
}

