Created
June 2, 2017 07:17
-
-
Save bstaletic/032e6a3c66b0b9bdf0706d0b91c1927c to your computer and use it in GitHub Desktop.
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
diff --git a/cpp/ycm/Candidate.cpp b/cpp/ycm/Candidate.cpp | |
index d204336..2bc34e0 100644 | |
--- a/cpp/ycm/Candidate.cpp | |
+++ b/cpp/ycm/Candidate.cpp | |
@@ -29,18 +29,18 @@ std::string GetWordBoundaryChars( const std::string &text ) { | |
for ( size_t i = 0; i < text.size(); ++i ) { | |
bool is_first_char_but_not_punctuation = i == 0 && | |
- !IsPunctuation( text[ i ] ); | |
+ !ispunct( text[ i ] ); | |
bool is_good_uppercase = i > 0 && | |
- IsUppercase( text[ i ] ) && | |
- !IsUppercase( text[ i - 1 ] ); | |
+ isupper( text[ i ] ) && | |
+ !isupper( text[ i - 1 ] ); | |
bool is_alpha_after_punctuation = i > 0 && | |
- IsPunctuation( text[ i - 1 ] ) && | |
- IsAlpha( text[ i ] ); | |
+ ispunct( text[ i - 1 ] ) && | |
+ isalpha( text[ i ] ); | |
if ( is_first_char_but_not_punctuation || | |
is_good_uppercase || | |
is_alpha_after_punctuation ) { | |
- result.push_back( ToLowercase( text[ i ] ) ); | |
+ result.push_back( tolower( text[ i ] ) ); | |
} | |
} | |
@@ -54,7 +54,7 @@ Bitset LetterBitsetFromString( const std::string &text ) { | |
for ( char letter : text ) { | |
int letter_index = IndexForLetter( letter ); | |
- if ( IsAscii( letter_index ) ) | |
+ if ( isascii( letter_index ) ) | |
letter_bitset.set( letter_index ); | |
} | |
@@ -89,7 +89,7 @@ Result Candidate::QueryMatchResult( const std::string &query, | |
// uppercase and a lowercase letter. This is by design and it's much | |
// better than forcing lowercase letter matches. | |
node = NULL; | |
- if ( case_sensitive && IsUppercase( letter ) ) { | |
+ if ( case_sensitive && isupper( letter ) ) { | |
if ( nearest->indexOfFirstUppercaseOccurrence >= 0 ) | |
node = ( *root_node_ )[ nearest->indexOfFirstUppercaseOccurrence ]; | |
} else { | |
diff --git a/cpp/ycm/LetterNode.cpp b/cpp/ycm/LetterNode.cpp | |
index f65d80d..e765509 100644 | |
--- a/cpp/ycm/LetterNode.cpp | |
+++ b/cpp/ycm/LetterNode.cpp | |
@@ -22,7 +22,7 @@ namespace YouCompleteMe { | |
LetterNode::LetterNode( char letter, int index ) | |
: index_( index ), | |
- is_uppercase_( IsUppercase( letter ) ) { | |
+ is_uppercase_( isupper( letter ) ) { | |
} | |
@@ -47,7 +47,7 @@ LetterNode::LetterNode( const std::string &text ) | |
void LetterNode::SetNodeIndexForLetterIfNearest( char letter, short index ) { | |
NearestLetterNodeIndices& currentLetterNodeIndices = letters_[ letter ]; | |
- if ( IsUppercase( letter ) ) { | |
+ if ( isupper( letter ) ) { | |
if ( currentLetterNodeIndices.indexOfFirstUppercaseOccurrence == -1 ) | |
currentLetterNodeIndices.indexOfFirstUppercaseOccurrence = index; | |
} | |
diff --git a/cpp/ycm/LetterNodeListMap.cpp b/cpp/ycm/LetterNodeListMap.cpp | |
index e4d66ae..03625de 100644 | |
--- a/cpp/ycm/LetterNodeListMap.cpp | |
+++ b/cpp/ycm/LetterNodeListMap.cpp | |
@@ -21,7 +21,7 @@ | |
namespace YouCompleteMe { | |
int IndexForLetter( char letter ) { | |
- if ( IsUppercase( letter ) ) | |
+ if ( isupper( letter ) ) | |
return letter + ( 'a' - 'A' ); | |
return letter; | |
diff --git a/cpp/ycm/Result.cpp b/cpp/ycm/Result.cpp | |
index ea374b4..a2b2e4b 100644 | |
--- a/cpp/ycm/Result.cpp | |
+++ b/cpp/ycm/Result.cpp | |
@@ -52,7 +52,7 @@ int LongestCommonSubsequenceLength( const std::string &first, | |
for ( int i = 0; i < longer_len; ++i ) { | |
for ( int j = 0; j < shorter_len; ++j ) { | |
- if ( ToUppercase( longer[ i ] ) == ToUppercase( shorter[ j ] ) ) | |
+ if ( toupper( longer[ i ] ) == toupper( shorter[ j ] ) ) | |
current[ j + 1 ] = previous[ j ] + 1; | |
else | |
current[ j + 1 ] = std::max( current[ j ], previous[ j + 1 ] ); | |
@@ -185,7 +185,7 @@ void Result::SetResultFeaturesFromQuery( | |
return; | |
first_char_same_in_query_and_text_ = | |
- ToUppercase( query[ 0 ] ) == ToUppercase( ( *text_ )[ 0 ] ); | |
+ toupper( query[ 0 ] ) == toupper( ( *text_ )[ 0 ] ); | |
int num_wb_matches = NumWordBoundaryCharMatches( query, | |
word_boundary_chars ); | |
ratio_of_word_boundary_chars_in_query_ = | |
@@ -200,7 +200,7 @@ void Result::SetResultFeaturesFromQuery( | |
bool Result::QueryIsPrefix( const std::string &text, | |
const std::string &query ) { | |
for ( size_t i = 0; i < query.length(); ++i ) | |
- if ( ToUppercase( query[ i ] ) != ToUppercase( text[ i ] ) ) | |
+ if ( toupper( query[ i ] ) != toupper( text[ i ] ) ) | |
return false; | |
return true; | |
diff --git a/cpp/ycm/Utils.cpp b/cpp/ycm/Utils.cpp | |
index 5472fbe..0332b5d 100644 | |
--- a/cpp/ycm/Utils.cpp | |
+++ b/cpp/ycm/Utils.cpp | |
@@ -17,10 +17,6 @@ | |
#include "Utils.h" | |
#include <algorithm> | |
-#include <cmath> | |
-#include <cctype> | |
-#include <functional> | |
-#include <limits> | |
#include <boost/filesystem.hpp> | |
#include <boost/filesystem/fstream.hpp> | |
#include <unordered_map> | |
@@ -63,77 +59,27 @@ void WriteUtf8File( const fs::path &filepath, const std::string &contents ) { | |
} | |
-bool IsAscii( char letter ) { | |
- return 0 <= letter && letter < NUM_LETTERS; | |
-} | |
- | |
- | |
-bool IsAlpha( char letter ) { | |
- return IsLowercase( letter ) || IsUppercase( letter ); | |
-} | |
- | |
- | |
-bool IsPrintable( char letter ) { | |
- return ' ' <= letter && letter <= '~'; | |
-} | |
- | |
- | |
// Returns true if text contains only printable characters: ASCII characters in | |
// the range 32-126. | |
bool IsPrintable( const std::string &text ) { | |
- return std::all_of( text.cbegin(), text.cend(), | |
- static_cast< bool ( * ) ( char ) > ( &IsPrintable ) ); | |
-} | |
- | |
- | |
-bool IsPunctuation( char letter ) { | |
- return ( '!' <= letter && letter <= '/' ) || | |
- ( ':' <= letter && letter <= '@' ) || | |
- ( '[' <= letter && letter <= '`' ) || | |
- ( '{' <= letter && letter <= '~' ); | |
-} | |
- | |
- | |
-bool IsLowercase( char letter ) { | |
- return 'a' <= letter && letter <= 'z'; | |
+ return std::all_of( text.cbegin(), text.cend(), isprint ); | |
} | |
// A string is assumed to be in lowercase if none of its characters are | |
// uppercase. | |
bool IsLowercase( const std::string &text ) { | |
- return std::none_of( text.cbegin(), text.cend(), | |
- static_cast< bool ( * ) ( char ) > ( &IsUppercase ) ); | |
-} | |
- | |
- | |
-bool IsUppercase( char letter ) { | |
- return 'A' <= letter && letter <= 'Z'; | |
-} | |
- | |
- | |
-char ToLowercase( char letter ) { | |
- if ( IsUppercase( letter ) ) | |
- return letter ^ 0x20; | |
- return letter; | |
-} | |
- | |
- | |
-char ToUppercase( char letter ) { | |
- if ( IsLowercase( letter ) ) | |
- return letter ^ 0x20; | |
- return letter; | |
+ return std::none_of( text.cbegin(), text.cend(), isupper ); | |
} | |
bool HasUppercase( const std::string &text ) { | |
- return std::any_of( text.cbegin(), text.cend(), | |
- static_cast< bool ( * ) ( char ) > ( &IsUppercase ) ); | |
+ return std::any_of( text.cbegin(), text.cend(), isupper ); | |
} | |
char ToOppositeCase( char letter ) { | |
- if ( IsAlpha( letter ) ) | |
+ if ( isalpha( letter ) ) | |
return letter ^ 0x20; | |
return letter; | |
} | |
diff --git a/cpp/ycm/Utils.h b/cpp/ycm/Utils.h | |
index 738b21f..9a1724c 100644 | |
--- a/cpp/ycm/Utils.h | |
+++ b/cpp/ycm/Utils.h | |
@@ -20,6 +20,7 @@ | |
#include "DLLDefines.h" | |
+#include <cctype> | |
#include <string> | |
#include <vector> | |
#include <boost/filesystem.hpp> | |
@@ -81,16 +82,8 @@ bool Erase( Container &container, const Key &key ) { | |
} | |
-bool IsAscii( char letter ); | |
-bool IsAlpha( char letter ); | |
-bool IsPrintable( char letter ); | |
bool IsPrintable( const std::string &text ); | |
-bool IsPunctuation( char letter ); | |
-bool IsLowercase( char letter ); | |
bool IsLowercase( const std::string &text ); | |
-YCM_DLL_EXPORT bool IsUppercase( char letter ); | |
-char ToLowercase( char letter ); | |
-char ToUppercase( char letter ); | |
bool HasUppercase( const std::string &text ); | |
YCM_DLL_EXPORT char ToOppositeCase( char letter ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment