00001 /*!\file pmstring.h 00002 \brief Declerations for PackageManager String class. 00003 Part of the heart of the PackageManager.*/ 00004 00005 #ifndef __PMSTRING_H__ 00006 #define __PMSTRING_H__ 00007 00008 #include <string> 00009 #include <vector> 00010 00011 //!The Package Manger string class. 00012 /*!Simple inherited class to inherit from std::string. Includes 00013 some string manipulation functions useful to the package manager.*/ 00014 class PMString : public std::string 00015 { 00016 public: 00017 PMString() : std::string(){} //!<Inherits from std::string. 00018 PMString(const char *ptr) : std::string(ptr) {} //!<Inherits from std::string. 00019 PMString(const std::string& s) : std::string(s) {} //!<Inherits from std::string. 00020 PMString(size_type length, const char& ch) : std::string( length, ch) {} //!<Inherits from std::string. 00021 PMString(const char* str, size_type length) : std::string(str,length) {} //!<Inherits from std::string. 00022 PMString(const std::string& str, size_type index, size_type length) : std::string(str,index,length) {} //!<Inherits from std::string. 00023 00024 std::vector<PMString> Split(char const* delims = " \t\r\n"); //!<Split the string around delims and return a vector of the split. Delims defaults to whitespace. 00025 std::vector<PMString> ProcessUseFlags(std::vector<PMString> useFlags); //!<Removes atoms not associated with useflags provided. 00026 00027 PMString GetName(); //!<Returns the name when string is in cat/name-version format. 00028 PMString GetCategory(); //!<Returns the category when string is in cat/name-version format. 00029 PMString GetVersion(); //!<Returns the version when string is in cat/name-version format. 00030 PMString GetFileName(); //!<Returns the filename if string is in the form dir/dir/filename. 00031 00032 void TrimWhitespace(); //!<Remove the whitespace from either end of the string. 00033 void FormatSize(int size); //!<Format the string as a size - should only be called if the string only contains numbers. 00034 int VersionCompare(PMString secondVersion); //!<Compare this string with secondVersion string. 00035 bool StartsWith(PMString secondString); //!<True if this starts with secondString. 00036 00037 protected: 00038 std::vector<PMString>::iterator _BypassBrackets(std::vector<PMString>::iterator currentLocation,std::vector<PMString>::iterator endLocation); //!<Go out of scope of the current bracket. 00039 }; 00040 00041 #endif