1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
// Copyright (C) 2018 ycmd contributors
//
// This file is part of ycmd.
//
// ycmd is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ycmd is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ycmd. If not, see <http://www.gnu.org/licenses/>.
#ifndef CHARACTER_H_YTIET2HZ
#define CHARACTER_H_YTIET2HZ
#include <string>
#include <string_view>
#include <vector>
namespace YouCompleteMe {
// This class represents a UTF-8 character. It takes a UTF-8 encoded string
// corresponding to a grapheme cluster (see
// https://www.unicode.org/glossary/#grapheme_cluster), normalize it through NFD
// (see https://www.unicode.org/versions/Unicode13.0.0/ch03.pdf#G49621), and
// compute the folded and swapped case versions of the normalized character. It
// also holds some properties like if the character is a letter or a
// punctuation, and if it is uppercase.
class Character {
public:
YCM_EXPORT explicit Character( std::string_view character );
// Make class noncopyable
Character( const Character& ) = delete;
Character& operator=( const Character& ) = delete;
Character( Character&& ) = default;
Character& operator=( Character&& ) = default;
inline const std::string &Normal() const {
return normal_;
}
inline const std::string &Base() const {
return base_;
}
inline const std::string &FoldedCase() const {
return folded_case_;
}
inline const std::string &SwappedCase() const {
return swapped_case_;
}
inline bool IsBase() const {
return is_base_;
}
inline bool IsLetter() const {
return is_letter_;
}
inline bool IsPunctuation() const {
return is_punctuation_;
}
inline bool IsUppercase() const {
return is_uppercase_;
}
inline bool operator== ( const Character &other ) const {
return normal_ == other.normal_;
}
inline bool EqualsBase( const Character &other ) const {
return base_ == other.base_;
}
inline bool EqualsIgnoreCase( const Character &other ) const {
return folded_case_ == other.folded_case_;
}
// Smart base matching on top of smart case matching, e.g.:
// - e matches e, é, E, É;
// - E matches E, É but not e, é;
// - é matches é, É but not e, E;
// - É matches É but not e, é, E.
inline bool MatchesSmart( const Character &other ) const {
return ( is_base_ && EqualsBase( other ) &&
( !is_uppercase_ || other.is_uppercase_ ) ) ||
( !is_uppercase_ && EqualsIgnoreCase( other ) ) ||
normal_ == other.normal_;
}
private:
std::string normal_;
std::string base_;
std::string folded_case_;
std::string swapped_case_;
bool is_base_;
bool is_letter_;
bool is_punctuation_;
bool is_uppercase_;
};
YCM_EXPORT std::string NormalizeInput( std::string_view text );
using CharacterSequence = std::vector< const Character * >;
} // namespace YouCompleteMe
#endif /* end of include guard: CHARACTER_H_YTIET2HZ */
|