forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check text style in c++ code using clang-tidy
- Loading branch information
Showing
8 changed files
with
634 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
#include "StringLiteralIterator.h" | ||
|
||
namespace clang | ||
{ | ||
namespace tidy | ||
{ | ||
namespace cata | ||
{ | ||
|
||
StringLiteralIterator::StringLiteralIterator( const StringLiteral &str, size_t ind ) | ||
: str( str ), ind( ind ) | ||
{ | ||
} | ||
|
||
SourceLocation StringLiteralIterator::toSourceLocation( const SourceManager &SrcMgr, | ||
const LangOptions &LangOpts, const TargetInfo &Info ) const | ||
{ | ||
return str.get().getLocationOfByte( ind, SrcMgr, LangOpts, Info ); | ||
} | ||
|
||
uint32_t StringLiteralIterator::operator*() const | ||
{ | ||
uint32_t ch = str.get().getCodeUnit( ind ); | ||
unsigned int n; | ||
if( ch >= 0xFC ) { | ||
ch &= 0x01; | ||
n = 5; | ||
} else if( ch >= 0xF8 ) { | ||
ch &= 0x03; | ||
n = 4; | ||
} else if( ch >= 0xF0 ) { | ||
ch &= 0x07; | ||
n = 3; | ||
} else if( ch >= 0xE0 ) { | ||
ch &= 0x0F; | ||
n = 2; | ||
} else if( ch >= 0xC0 ) { | ||
ch &= 0x1F; | ||
n = 1; | ||
} else { | ||
n = 0; | ||
} | ||
for( size_t i = 1; i <= n; ++i ) { | ||
ch = ( ch << 6 ) | ( str.get().getCodeUnit( ind + i ) & 0x3F ); | ||
} | ||
return ch; | ||
} | ||
|
||
bool StringLiteralIterator::operator<( const StringLiteralIterator &rhs ) const | ||
{ | ||
return ind < rhs.ind; | ||
} | ||
|
||
bool StringLiteralIterator::operator>( const StringLiteralIterator &rhs ) const | ||
{ | ||
return rhs.operator < ( *this ); | ||
} | ||
|
||
bool StringLiteralIterator::operator<=( const StringLiteralIterator &rhs ) const | ||
{ | ||
return !rhs.operator < ( *this ); | ||
} | ||
|
||
bool StringLiteralIterator::operator>=( const StringLiteralIterator &rhs ) const | ||
{ | ||
return !operator<( rhs ); | ||
} | ||
|
||
bool StringLiteralIterator::operator==( const StringLiteralIterator &rhs ) const | ||
{ | ||
return ind == rhs.ind; | ||
} | ||
|
||
bool StringLiteralIterator::operator!=( const StringLiteralIterator &rhs ) const | ||
{ | ||
return !operator==( rhs ); | ||
} | ||
|
||
StringLiteralIterator &StringLiteralIterator::operator+=( ptrdiff_t inc ) | ||
{ | ||
if( inc == 0 ) { | ||
return *this; | ||
} else if( inc > 0 ) { | ||
while( inc > 0 && ind < str.get().getLength() ) { | ||
uint32_t byte = str.get().getCodeUnit( ind ); | ||
if( byte >= 0xFC ) { | ||
ind += 6; | ||
} else if( byte >= 0xF8 ) { | ||
ind += 5; | ||
} else if( byte >= 0xF0 ) { | ||
ind += 4; | ||
} else if( byte >= 0xE0 ) { | ||
ind += 3; | ||
} else if( byte >= 0xC0 ) { | ||
ind += 2; | ||
} else { | ||
++ind; | ||
} | ||
--inc; | ||
} | ||
ind = std::min<size_t>( ind, str.get().getLength() ); | ||
} else { | ||
while( inc < 0 && ind > 0 ) { | ||
uint32_t byte = str.get().getCodeUnit( ind - 1 ); | ||
if( byte < 0x80 || byte >= 0xC0 ) { | ||
++inc; | ||
} | ||
--ind; | ||
} | ||
} | ||
return *this; | ||
} | ||
|
||
StringLiteralIterator &StringLiteralIterator::operator-=( ptrdiff_t dec ) | ||
{ | ||
return operator+=( -dec ); | ||
} | ||
|
||
StringLiteralIterator StringLiteralIterator::operator+( ptrdiff_t inc ) const | ||
{ | ||
StringLiteralIterator ret = *this; | ||
ret.operator += ( inc ); | ||
return ret; | ||
} | ||
|
||
StringLiteralIterator StringLiteralIterator::operator-( ptrdiff_t dec ) const | ||
{ | ||
return operator+( -dec ); | ||
} | ||
|
||
StringLiteralIterator &StringLiteralIterator::operator++() | ||
{ | ||
return operator+=( 1 ); | ||
} | ||
|
||
StringLiteralIterator StringLiteralIterator::operator++( int ) | ||
{ | ||
StringLiteralIterator ret = *this; | ||
operator++(); | ||
return ret; | ||
} | ||
|
||
StringLiteralIterator &StringLiteralIterator::operator--() | ||
{ | ||
return operator-=( 1 ); | ||
} | ||
|
||
StringLiteralIterator StringLiteralIterator::operator--( int ) | ||
{ | ||
StringLiteralIterator ret = *this; | ||
operator--(); | ||
return ret; | ||
} | ||
|
||
StringLiteralIterator StringLiteralIterator::begin( const StringLiteral &str ) | ||
{ | ||
return StringLiteralIterator( str, 0 ); | ||
} | ||
|
||
StringLiteralIterator StringLiteralIterator::end( const StringLiteral &str ) | ||
{ | ||
return StringLiteralIterator( str, str.getLength() ); | ||
} | ||
|
||
ptrdiff_t StringLiteralIterator::distance( const StringLiteralIterator &beg, | ||
const StringLiteralIterator &end ) | ||
{ | ||
if( beg <= end ) { | ||
ptrdiff_t dist = 0; | ||
for( auto it = beg; it < end; ++it, ++dist ) { | ||
} | ||
return dist; | ||
} else { | ||
return -distance( end, beg ); | ||
} | ||
} | ||
|
||
} // namespace cata | ||
} // namespace tidy | ||
} // namespace clang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef CATA_TOOLS_CLANG_TIDY_STRINGLITERALVIEW_H | ||
#define CATA_TOOLS_CLANG_TIDY_STRINGLITERALVIEW_H | ||
|
||
#include "ClangTidy.h" | ||
|
||
namespace clang | ||
{ | ||
namespace tidy | ||
{ | ||
namespace cata | ||
{ | ||
|
||
// Currently only supports utf8 becasue StringLiteral only has full support | ||
// for single-byte ascii/utf8 strings | ||
class StringLiteralIterator | ||
{ | ||
public: | ||
// This assumes that ind points to the start of a valid utf8 sequence | ||
StringLiteralIterator( const StringLiteral &str, size_t ind ); | ||
|
||
SourceLocation toSourceLocation( const SourceManager &SrcMgr, const LangOptions &LangOpts, | ||
const TargetInfo &Info ) const; | ||
|
||
// All following operators assume that StringLiteral contains a valid | ||
// utf8 string | ||
uint32_t operator*() const; | ||
|
||
bool operator<( const StringLiteralIterator &rhs ) const; | ||
bool operator>( const StringLiteralIterator &rhs ) const; | ||
bool operator<=( const StringLiteralIterator &rhs ) const; | ||
bool operator>=( const StringLiteralIterator &rhs ) const; | ||
bool operator==( const StringLiteralIterator &rhs ) const; | ||
bool operator!=( const StringLiteralIterator &rhs ) const; | ||
|
||
StringLiteralIterator &operator+=( ptrdiff_t inc ); | ||
StringLiteralIterator &operator-=( ptrdiff_t dec ); | ||
StringLiteralIterator operator+( ptrdiff_t inc ) const; | ||
StringLiteralIterator operator-( ptrdiff_t dec ) const; | ||
StringLiteralIterator &operator++(); | ||
StringLiteralIterator operator++( int ); | ||
StringLiteralIterator &operator--(); | ||
StringLiteralIterator operator--( int ); | ||
|
||
static StringLiteralIterator begin( const StringLiteral &str ); | ||
static StringLiteralIterator end( const StringLiteral &str ); | ||
|
||
static ptrdiff_t distance( const StringLiteralIterator &beg, | ||
const StringLiteralIterator &end ); | ||
|
||
private: | ||
std::reference_wrapper<const StringLiteral> str; | ||
size_t ind; | ||
}; | ||
|
||
} // namespace cata | ||
} // namespace tidy | ||
} // namespace clang | ||
|
||
#endif // CATA_TOOLS_CLANG_TIDY_STRINGLITERALVIEW_H |
Oops, something went wrong.