TextDocument find improvements: lua pattern find and whole word filter.

This commit is contained in:
Martín Lucas Golini
2020-12-25 17:45:41 -03:00
parent dccd0617e5
commit ccb22f34aa
9 changed files with 195 additions and 76 deletions

View File

@@ -88,9 +88,19 @@ class EE_API String {
/** @return If the value passed is a letter */
static bool isLetter( const int& value );
/** @return If the value passed is a letter or a number */
static bool isAlphaNum( const int& value );
/** @return If the string is a representation of a hexa number */
static bool isHexNotation( const std::string& value, const std::string& withPrefix = "" );
/** @return If the needle substring, found starting at startPos is a whole-word. */
static bool isWholeWord( const std::string& haystack, const std::string& needle,
const Int64& startPos );
/** @return If the needle substring, found starting at startPos is a whole-word. */
static bool isWholeWord( const String& haystack, const String& needle, const Int64& startPos );
/** Split a String and hold it on a vector */
static std::vector<String> split( const String& str, const StringBaseType& delim = '\n',
const bool& pushEmptyString = false );

View File

@@ -31,6 +31,8 @@ class EE_API TextDocument {
enum class LineEnding { LF, CRLF };
enum class FindReplaceType { Normal, LuaPattern };
class EE_API Client {
public:
virtual ~Client();
@@ -247,17 +249,31 @@ class EE_API TextDocument {
void setCommand( const std::string& command, DocumentCommand func );
TextPosition find( String text, TextPosition from = { 0, 0 }, const bool& caseSensitive = true,
TextRange restrictRange = TextRange() );
TextRange find( String text, TextPosition from = { 0, 0 }, const bool& caseSensitive = true,
const bool& wholeWord = false,
const FindReplaceType& type = FindReplaceType::Normal,
TextRange restrictRange = TextRange() );
TextPosition findLast( String text, TextPosition from = { 0, 0 },
const bool& caseSensitive = true,
const bool& caseSensitive = true, const bool& wholeWord = false,
TextRange restrictRange = TextRange() );
std::vector<TextRange> findAll( const String& text, const bool& caseSensitive = true,
const bool& wholeWord = false,
const FindReplaceType& type = FindReplaceType::Normal,
TextRange restrictRange = TextRange() );
int replaceAll( const String& text, const String& replace, const bool& caseSensitive = true,
const bool& wholeWord = false,
const FindReplaceType& type = FindReplaceType::Normal,
TextRange restrictRange = TextRange() );
TextPosition replaceSelection( const String& replace );
TextPosition replace( String search, const String& replace, TextPosition from = { 0, 0 },
const bool& caseSensitive = true, TextRange restrictRange = TextRange() );
const bool& caseSensitive = true, const bool& wholeWord = false,
const FindReplaceType& type = FindReplaceType::Normal,
TextRange restrictRange = TextRange() );
String getIndentString();

View File

@@ -12,6 +12,7 @@ class EE_API TextRange {
mStart( start ), mEnd( end ) {}
bool isValid() const { return mStart.isValid() && mEnd.isValid(); }
void clear() {
mStart = {};
mEnd = {};
@@ -27,6 +28,8 @@ class EE_API TextRange {
TextRange normalized() const { return TextRange( normalizedStart(), normalizedEnd() ); }
TextRange reversed() { return TextRange( mEnd, mStart ); }
void setStart( const TextPosition& position ) { mStart = position; }
void setEnd( const TextPosition& position ) { mEnd = position; }