Skip to content

Commit

Permalink
Classier enums
Browse files Browse the repository at this point in the history
  • Loading branch information
TimePath authored and Kangz committed Feb 6, 2016
1 parent e9aba41 commit 83e5a4a
Show file tree
Hide file tree
Showing 172 changed files with 3,886 additions and 3,922 deletions.
18 changes: 9 additions & 9 deletions daemon/src/common/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int StrlenNocolor( const char *string )
int len = 0;
for ( const auto& token : Parser( string ) )
{
if ( token.Type() == Token::CHARACTER || token.Type() == Token::ESCAPE )
if ( token.Type() == Token::TokenType::CHARACTER || token.Type() == Token::TokenType::ESCAPE )
{
len++;
}
Expand All @@ -103,11 +103,11 @@ char *StripColors( char *string )

for ( const auto& token : Parser( string ) )
{
if ( token.Type() == Token::CHARACTER )
if ( token.Type() == Token::TokenType::CHARACTER )
{
output.append( token.Begin(), token.Size() );
}
else if ( token.Type() == Token::ESCAPE )
else if ( token.Type() == Token::TokenType::ESCAPE )
{
output.push_back(Constants::ESCAPE);
}
Expand All @@ -124,7 +124,7 @@ void StripColors( const char *in, char *out, int len )

for ( const auto& token : Parser( in ) )
{
if ( token.Type() == Token::CHARACTER )
if ( token.Type() == Token::TokenType::CHARACTER )
{
if ( len < token.Size() )
{
Expand All @@ -135,7 +135,7 @@ void StripColors( const char *in, char *out, int len )
out += token.Size();
len -= token.Size();
}
else if ( token.Type() == Token::ESCAPE )
else if ( token.Type() == Token::TokenType::ESCAPE )
{
if ( len < 1 )
{
Expand All @@ -154,11 +154,11 @@ std::string StripColors( const std::string& input )

for ( const auto& token : Parser( input.c_str() ) )
{
if ( token.Type() == Token::CHARACTER )
if ( token.Type() == Token::TokenType::CHARACTER )
{
output.append( token.Begin(), token.Size() );
}
else if ( token.Type() == Token::ESCAPE )
else if ( token.Type() == Token::TokenType::ESCAPE )
{
output.push_back(Constants::ESCAPE);
}
Expand Down Expand Up @@ -253,7 +253,7 @@ TokenIterator::value_type TokenIterator::NextToken(const char* input)
{
if ( input[1] == Constants::ESCAPE )
{
return value_type( input, input+2, value_type::ESCAPE );
return value_type( input, input+2, value_type::TokenType::ESCAPE );
}
else if ( input[1] == Constants::NULL_COLOR )
{
Expand Down Expand Up @@ -295,7 +295,7 @@ TokenIterator::value_type TokenIterator::NextToken(const char* input)
}
}

return value_type( input, input + Q_UTF8_Width( input ), value_type::CHARACTER );
return value_type( input, input + Q_UTF8_Width( input ), value_type::TokenType::CHARACTER );
}

} // namespace Color
8 changes: 4 additions & 4 deletions daemon/src/common/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ extern Color LtOrange;
class Token
{
public:
enum TokenType {
enum class TokenType {
INVALID, // Invalid/empty token
CHARACTER, // A character
ESCAPE, // Color escape
Expand Down Expand Up @@ -407,7 +407,7 @@ class Token
Token( const char* begin, const char* end, const ::Color::Color& color )
: begin( begin ),
end( end ),
type( COLOR ),
type( TokenType::COLOR ),
color( color )
{}

Expand Down Expand Up @@ -455,14 +455,14 @@ class Token
*/
explicit operator bool() const
{
return type != INVALID && begin && begin < end;
return type != TokenType::INVALID && begin && begin < end;
}

private:

const char* begin = nullptr;
const char* end = nullptr;
TokenType type = INVALID;
TokenType type = TokenType::INVALID;
::Color::Color color;

};
Expand Down
Loading

0 comments on commit 83e5a4a

Please sign in to comment.