33 for(
int i = 0 ; i < argc ; i++ )
34 m_array.push_back( argv[i] ) ;
52 m_array(other.m_array) ,
53 m_prefix(other.m_prefix)
61 m_array = rhs.m_array ;
62 m_prefix = rhs.m_prefix ;
67 void G::Arg::setPrefix()
70 Path path( m_array[0U] ) ;
71 path.removeExtension() ;
72 m_prefix = path.basename() ;
77 return find( cs , sw , sw_args , NULL ) ;
80 bool G::Arg::find(
bool cs ,
const std::string & sw ,
size_type sw_args ,
size_type * index_p )
const
82 for(
size_type i = 1 ; i < m_array.size() ; i++ )
84 if( match(cs,sw,m_array[i]) && (i+sw_args) < m_array.size() )
94 bool G::Arg::match(
bool cs ,
const std::string & s1 ,
const std::string & s2 )
105 const bool found = find(
true , sw , sw_args , &i ) ;
107 removeAt( i , sw_args ) ;
113 G_ASSERT( sw_index > 0U && sw_index < m_array.size() ) ;
114 if( sw_index > 0U && sw_index < m_array.size() )
116 StringArray::iterator p = m_array.begin() ;
117 for(
size_type i = 0U ; i < sw_index ; i++ ) ++p ;
118 p = m_array.erase( p ) ;
119 for(
size_type i = 0U ; i < sw_args && p != m_array.end() ; i++ )
120 p = m_array.erase( p ) ;
127 const bool found = find(
true , sw , sw_args , &i ) ;
128 return found ? i : 0U ;
133 return m_array.size() ;
149 const char * exe = argv[0] ;
150 const char * p1 = std::strrchr( exe ,
'/' ) ;
151 const char * p2 = std::strrchr( exe ,
'\\' ) ;
152 p1 = p1 ? (p1+1U) : exe ;
153 p2 = p2 ? (p2+1U) : exe ;
154 return p1 > p2 ? p1 : p2 ;
std::string prefix() const
Returns the basename of v(0) without any extension.
bool contains(const std::string &sw, size_type sw_args=0U, bool case_sensitive=true) const
< An exception-free version of prefix() which can be used in main() outside of the outermost try bloc...
Arg()
Default constructor for Windows.
std::string::size_type size_type
A std::size_t type.
size_type index(const std::string &sw, size_type sw_args=0U) const
Returns the index of the given switch.
Arg & operator=(const Arg &)
Assignment operator.
std::string v(size_type i) const
Returns the i'th argument.
size_type c() const
Returns the number of tokens in the command line, including the program name.
bool remove(const std::string &sw, size_type sw_args=0U)
Removes the given switch and its arguments.
static std::string upper(const std::string &s)
Returns a copy of 's' in which all lowercase characters have been replaced by uppercase characters...
void removeAt(size_type sw_index, size_type sw_args=0U)
Removes the given argument and the following 'sw_args' ones.
A class which holds a represention of the argc/argv command line array, and supports simple command-l...
A Path object represents a file system path.