perform case insensitive searching in text fields
This commit is contained in:
@@ -3,7 +3,7 @@ ncmpcpp_SOURCES = browser.cpp charset.cpp clock.cpp conv.cpp display.cpp \
|
|||||||
error.cpp help.cpp helpers.cpp info.cpp lyrics.cpp media_library.cpp menu.cpp \
|
error.cpp help.cpp helpers.cpp info.cpp lyrics.cpp media_library.cpp menu.cpp \
|
||||||
misc.cpp mpdpp.cpp ncmpcpp.cpp outputs.cpp playlist.cpp playlist_editor.cpp \
|
misc.cpp mpdpp.cpp ncmpcpp.cpp outputs.cpp playlist.cpp playlist_editor.cpp \
|
||||||
scrollpad.cpp search_engine.cpp server_info.cpp settings.cpp song.cpp status.cpp \
|
scrollpad.cpp search_engine.cpp server_info.cpp settings.cpp song.cpp status.cpp \
|
||||||
tag_editor.cpp tiny_tag_editor.cpp visualizer.cpp window.cpp
|
tag_editor.cpp tiny_tag_editor.cpp tolower.cpp visualizer.cpp window.cpp
|
||||||
|
|
||||||
# set the include path found by configure
|
# set the include path found by configure
|
||||||
INCLUDES= $(all_includes)
|
INCLUDES= $(all_includes)
|
||||||
@@ -11,7 +11,6 @@ INCLUDES= $(all_includes)
|
|||||||
# the library search path.
|
# the library search path.
|
||||||
ncmpcpp_LDFLAGS = $(all_libraries)
|
ncmpcpp_LDFLAGS = $(all_libraries)
|
||||||
noinst_HEADERS = browser.h charset.h clock.h conv.h display.h error.h global.h \
|
noinst_HEADERS = browser.h charset.h clock.h conv.h display.h error.h global.h \
|
||||||
help.h helpers.h home.h info.h lyrics.h media_library.h menu.h misc.h \
|
help.h helpers.h home.h info.h lyrics.h media_library.h menu.h misc.h mpdpp.h \
|
||||||
mpdpp.h outputs.h playlist_editor.h screen.h scrollpad.h search_engine.h \
|
outputs.h playlist_editor.h screen.h scrollpad.h search_engine.h server_info.h \
|
||||||
server_info.h settings.h song.h tag_editor.h tiny_tag_editor.h visualizer.h \
|
settings.h song.h tag_editor.h tiny_tag_editor.h tolower.h visualizer.h window.h
|
||||||
window.h
|
|
||||||
|
|||||||
@@ -23,11 +23,6 @@
|
|||||||
|
|
||||||
#include "conv.h"
|
#include "conv.h"
|
||||||
|
|
||||||
void ToLower(std::string &s)
|
|
||||||
{
|
|
||||||
transform(s.begin(), s.end(), s.begin(), tolower);
|
|
||||||
}
|
|
||||||
|
|
||||||
int StrToInt(const std::string &str)
|
int StrToInt(const std::string &str)
|
||||||
{
|
{
|
||||||
return atoi(str.c_str());
|
return atoi(str.c_str());
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ template <size_t N> void Replace(std::string &s, const char (&from)[N], const ch
|
|||||||
s.replace(i, N-1, to);
|
s.replace(i, N-1, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToLower(std::string &);
|
|
||||||
|
|
||||||
int StrToInt(const std::string &);
|
int StrToInt(const std::string &);
|
||||||
long StrToLong(const std::string &);
|
long StrToLong(const std::string &);
|
||||||
|
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ void Info::GetArtist()
|
|||||||
}
|
}
|
||||||
input.close();
|
input.close();
|
||||||
w->SetFormatting(fmtBold, U("\n\nSimilar artists:\n"), fmtBoldEnd, 0);
|
w->SetFormatting(fmtBold, U("\n\nSimilar artists:\n"), fmtBoldEnd, 0);
|
||||||
w->SetFormatting(Config.color2, U("\n * "), clEnd);
|
w->SetFormatting(Config.color2, U("\n * "), clEnd, 1);
|
||||||
// below is used so format won't be removed using RemoveFormatting() by accident.
|
// below is used so format won't be removed using RemoveFormatting() by accident.
|
||||||
w->ForgetFormatting();
|
w->ForgetFormatting();
|
||||||
w->Flush();
|
w->Flush();
|
||||||
|
|||||||
@@ -1812,7 +1812,7 @@ int main(int argc, char *argv[])
|
|||||||
ShowMessage("Searching...");
|
ShowMessage("Searching...");
|
||||||
Screen<Scrollpad> *s = static_cast<Screen<Scrollpad> *>(myScreen);
|
Screen<Scrollpad> *s = static_cast<Screen<Scrollpad> *>(myScreen);
|
||||||
s->Main()->RemoveFormatting();
|
s->Main()->RemoveFormatting();
|
||||||
ShowMessage("%s", findme.empty() || s->Main()->SetFormatting(fmtReverse, TO_WSTRING(findme), fmtReverseEnd) ? "Done!" : "No matching patterns found");
|
ShowMessage("%s", findme.empty() || s->Main()->SetFormatting(fmtReverse, TO_WSTRING(findme), fmtReverseEnd, 0) ? "Done!" : "No matching patterns found");
|
||||||
s->Main()->Flush();
|
s->Main()->Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ Scrollpad::Scrollpad(size_t startx,
|
|||||||
Border border)
|
Border border)
|
||||||
: Window(startx, starty, width, height, title, color, border),
|
: Window(startx, starty, width, height, title, color, border),
|
||||||
itsBeginning(0),
|
itsBeginning(0),
|
||||||
itsFoundForEach(0),
|
|
||||||
itsFoundValueBegin(-1),
|
itsFoundValueBegin(-1),
|
||||||
itsFoundValueEnd(-1),
|
itsFoundValueEnd(-1),
|
||||||
itsRealHeight(1)
|
itsRealHeight(1)
|
||||||
@@ -92,12 +91,13 @@ void Scrollpad::Flush()
|
|||||||
itsBuffer.SetTemp(0);
|
itsBuffer.SetTemp(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Scrollpad::SetFormatting(short val_b, const std::basic_string<my_char_t> &s, short val_e, bool for_each)
|
bool Scrollpad::SetFormatting(short val_b, const std::basic_string<my_char_t> &s, short val_e, bool case_sensitive, bool for_each)
|
||||||
{
|
{
|
||||||
bool result = itsBuffer.SetFormatting(val_b, s, val_e, for_each);
|
bool result = itsBuffer.SetFormatting(val_b, s, val_e, case_sensitive, for_each);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
itsFoundForEach = for_each;
|
itsFoundForEach = for_each;
|
||||||
|
itsFoundCaseSensitive = case_sensitive;
|
||||||
itsFoundValueBegin = val_b;
|
itsFoundValueBegin = val_b;
|
||||||
itsFoundValueEnd = val_e;
|
itsFoundValueEnd = val_e;
|
||||||
itsFoundPattern = s;
|
itsFoundPattern = s;
|
||||||
@@ -109,7 +109,6 @@ bool Scrollpad::SetFormatting(short val_b, const std::basic_string<my_char_t> &s
|
|||||||
|
|
||||||
void Scrollpad::ForgetFormatting()
|
void Scrollpad::ForgetFormatting()
|
||||||
{
|
{
|
||||||
itsFoundForEach = 0;
|
|
||||||
itsFoundValueBegin = -1;
|
itsFoundValueBegin = -1;
|
||||||
itsFoundValueEnd = -1;
|
itsFoundValueEnd = -1;
|
||||||
itsFoundPattern.clear();
|
itsFoundPattern.clear();
|
||||||
@@ -118,7 +117,7 @@ void Scrollpad::ForgetFormatting()
|
|||||||
void Scrollpad::RemoveFormatting()
|
void Scrollpad::RemoveFormatting()
|
||||||
{
|
{
|
||||||
if (itsFoundValueBegin >= 0 && itsFoundValueEnd >= 0)
|
if (itsFoundValueBegin >= 0 && itsFoundValueEnd >= 0)
|
||||||
itsBuffer.RemoveFormatting(itsFoundValueBegin, itsFoundPattern, itsFoundValueEnd, itsFoundForEach);
|
itsBuffer.RemoveFormatting(itsFoundValueBegin, itsFoundPattern, itsFoundValueEnd, itsFoundCaseSensitive, itsFoundForEach);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scrollpad::Refresh()
|
void Scrollpad::Refresh()
|
||||||
|
|||||||
@@ -60,13 +60,14 @@ namespace NCurses
|
|||||||
/// @param val_b flag set at the beginning of found occurence of string
|
/// @param val_b flag set at the beginning of found occurence of string
|
||||||
/// @param s string that function seaches for
|
/// @param s string that function seaches for
|
||||||
/// @param val_e flag set at the end of found occurence of string
|
/// @param val_e flag set at the end of found occurence of string
|
||||||
|
/// @param case_sensitive indicates whether algorithm should care about case sensitivity
|
||||||
/// @param for_each indicates whether function searches through whole text and sets
|
/// @param for_each indicates whether function searches through whole text and sets
|
||||||
/// given format for all occurences of given string or stops after first occurence
|
/// given format for all occurences of given string or stops after first occurence
|
||||||
/// @return true if at least one occurence of the string was found, false otherwise
|
/// @return true if at least one occurence of the string was found, false otherwise
|
||||||
/// @see basic_buffer::SetFormatting()
|
/// @see basic_buffer::SetFormatting()
|
||||||
///
|
///
|
||||||
bool SetFormatting(short val_b, const std::basic_string<my_char_t> &s,
|
bool SetFormatting(short val_b, const std::basic_string<my_char_t> &s,
|
||||||
short val_e, bool for_each = 1);
|
short val_e, bool case_sensitive, bool for_each = 1);
|
||||||
|
|
||||||
/// Removes all format flags and colors from stored text
|
/// Removes all format flags and colors from stored text
|
||||||
///
|
///
|
||||||
@@ -130,6 +131,7 @@ namespace NCurses
|
|||||||
int itsBeginning;
|
int itsBeginning;
|
||||||
|
|
||||||
bool itsFoundForEach;
|
bool itsFoundForEach;
|
||||||
|
bool itsFoundCaseSensitive;
|
||||||
short itsFoundValueBegin;
|
short itsFoundValueBegin;
|
||||||
short itsFoundValueEnd;
|
short itsFoundValueEnd;
|
||||||
std::basic_string<my_char_t> itsFoundPattern;
|
std::basic_string<my_char_t> itsFoundPattern;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#ifndef _STRBUFFER_H
|
#ifndef _STRBUFFER_H
|
||||||
#define _STRBUFFER_H
|
#define _STRBUFFER_H
|
||||||
|
|
||||||
|
#include "tolower.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -85,23 +86,25 @@ namespace NCurses
|
|||||||
/// @param val_b flag set at the beginning of found occurence of string
|
/// @param val_b flag set at the beginning of found occurence of string
|
||||||
/// @param s string that function seaches for
|
/// @param s string that function seaches for
|
||||||
/// @param val_e flag set at the end of found occurence of string
|
/// @param val_e flag set at the end of found occurence of string
|
||||||
|
/// @param case_sensitive indicates whether algorithm should care about case sensitivity
|
||||||
/// @param for_each indicates whether function searches through whole buffer and sets
|
/// @param for_each indicates whether function searches through whole buffer and sets
|
||||||
/// the format for all occurences of given string or stops after the first one
|
/// the format for all occurences of given string or stops after the first one
|
||||||
/// @return true if at least one occurence of the string was found, false otherwise
|
/// @return true if at least one occurence of the string was found, false otherwise
|
||||||
///
|
///
|
||||||
bool SetFormatting(short val_b, const std::basic_string<C> &s,
|
bool SetFormatting(short val_b, std::basic_string<C> s, short val_e,
|
||||||
short val_e, bool for_each = 1);
|
bool case_sensitive, bool for_each = 1);
|
||||||
|
|
||||||
/// Searches for given string in buffer and removes given
|
/// Searches for given string in buffer and removes given
|
||||||
/// format/color from the beginning and end of its occurence
|
/// format/color from the beginning and end of its occurence
|
||||||
/// @param val_b flag to be removed from the beginning of the string
|
/// @param val_b flag to be removed from the beginning of the string
|
||||||
/// @param s string that function seaches for
|
/// @param s string that function seaches for
|
||||||
/// @param val_e flag to be removed from the end of the string
|
/// @param val_e flag to be removed from the end of the string
|
||||||
|
/// @param case_sensitive indicates whether algorithm should care about case sensitivity
|
||||||
/// @param for_each indicates whether function searches through whole buffer and removes
|
/// @param for_each indicates whether function searches through whole buffer and removes
|
||||||
/// given format from all occurences of given string or stops after the first one
|
/// given format from all occurences of given string or stops after the first one
|
||||||
///
|
///
|
||||||
void RemoveFormatting(short val_b, const std::basic_string<C> &s,
|
void RemoveFormatting(short val_b, std::basic_string<C> pattern, short val_e,
|
||||||
short val_e, bool for_each = 1);
|
bool case_sensitive, bool for_each = 1);
|
||||||
|
|
||||||
/// Sets the pointer to string, that will be passed in operator<<() to window
|
/// Sets the pointer to string, that will be passed in operator<<() to window
|
||||||
/// object instead of the internal buffer. This is useful if you took the content
|
/// object instead of the internal buffer. This is useful if you took the content
|
||||||
@@ -187,8 +190,9 @@ template <typename C> std::basic_string<C> NCurses::basic_buffer<C>::Str() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename C> bool NCurses::basic_buffer<C>::SetFormatting( short val_b,
|
template <typename C> bool NCurses::basic_buffer<C>::SetFormatting( short val_b,
|
||||||
const std::basic_string<C> &s,
|
std::basic_string<C> s,
|
||||||
short val_e,
|
short val_e,
|
||||||
|
bool case_sensitive,
|
||||||
bool for_each
|
bool for_each
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -196,8 +200,12 @@ template <typename C> bool NCurses::basic_buffer<C>::SetFormatting( short val_b,
|
|||||||
return false;
|
return false;
|
||||||
bool result = false;
|
bool result = false;
|
||||||
std::basic_string<C> base = itsString.str();
|
std::basic_string<C> base = itsString.str();
|
||||||
|
if (!case_sensitive)
|
||||||
|
{
|
||||||
|
ToLower(s);
|
||||||
|
ToLower(base);
|
||||||
|
}
|
||||||
FormatPos fp;
|
FormatPos fp;
|
||||||
|
|
||||||
for (size_t i = base.find(s); i != std::basic_string<C>::npos; i = base.find(s, i))
|
for (size_t i = base.find(s); i != std::basic_string<C>::npos; i = base.find(s, i))
|
||||||
{
|
{
|
||||||
result = true;
|
result = true;
|
||||||
@@ -216,22 +224,27 @@ template <typename C> bool NCurses::basic_buffer<C>::SetFormatting( short val_b,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename C> void NCurses::basic_buffer<C>::RemoveFormatting( short val_b,
|
template <typename C> void NCurses::basic_buffer<C>::RemoveFormatting( short val_b,
|
||||||
const std::basic_string<C> &s,
|
std::basic_string<C> pattern,
|
||||||
short val_e,
|
short val_e,
|
||||||
|
bool case_sensitive,
|
||||||
bool for_each
|
bool for_each
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (s.empty())
|
if (pattern.empty())
|
||||||
return;
|
return;
|
||||||
std::basic_string<C> base = itsString.str();
|
std::basic_string<C> base = itsString.str();
|
||||||
|
if (!case_sensitive)
|
||||||
|
{
|
||||||
|
ToLower(pattern);
|
||||||
|
ToLower(base);
|
||||||
|
}
|
||||||
FormatPos fp;
|
FormatPos fp;
|
||||||
|
for (size_t i = base.find(pattern); i != std::basic_string<C>::npos; i = base.find(pattern, i))
|
||||||
for (size_t i = base.find(s); i != std::basic_string<C>::npos; i = base.find(s, i))
|
|
||||||
{
|
{
|
||||||
fp.Value = val_b;
|
fp.Value = val_b;
|
||||||
fp.Position = i;
|
fp.Position = i;
|
||||||
itsFormat.remove(fp);
|
itsFormat.remove(fp);
|
||||||
i += s.length();
|
i += pattern.length();
|
||||||
fp.Value = val_e;
|
fp.Value = val_e;
|
||||||
fp.Position = i;
|
fp.Position = i;
|
||||||
itsFormat.remove(fp);
|
itsFormat.remove(fp);
|
||||||
|
|||||||
Reference in New Issue
Block a user