LLTextParser now a singleton.
This commit is contained in:
@@ -4095,7 +4095,7 @@ void LLTextEditor::appendHighlightedText(const std::string &new_text,
|
||||
|
||||
if (highlight && stylep)
|
||||
{
|
||||
LLSD pieces = highlight->parsePartialLineHighlights(new_text, stylep->getColor(), highlight_part);
|
||||
LLSD pieces = highlight->parsePartialLineHighlights(new_text, stylep->getColor(), (LLTextParser::EHighlightPosition)highlight_part);
|
||||
bool lprepend=prepend_newline;
|
||||
for (S32 i=0;i<pieces.size();i++)
|
||||
{
|
||||
|
||||
@@ -43,29 +43,14 @@
|
||||
#include "v4color.h"
|
||||
#include "lldir.h"
|
||||
|
||||
// Routines used for parsing text for TextParsers and html
|
||||
|
||||
LLTextParser* LLTextParser::sInstance = NULL;
|
||||
|
||||
//
|
||||
// Member Functions
|
||||
//
|
||||
|
||||
LLTextParser::~LLTextParser()
|
||||
{
|
||||
sInstance=NULL;
|
||||
}
|
||||
LLTextParser::LLTextParser()
|
||||
: mLoaded(false)
|
||||
{}
|
||||
|
||||
// static
|
||||
LLTextParser* LLTextParser::getInstance()
|
||||
{
|
||||
if (!sInstance)
|
||||
{
|
||||
sInstance = new LLTextParser();
|
||||
sInstance->loadFromDisk();
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
// Moved triggerAlerts() to llfloaterchat.cpp to break llui/llaudio library dependency.
|
||||
|
||||
@@ -103,8 +88,10 @@ S32 LLTextParser::findPattern(const std::string &text, LLSD highlight)
|
||||
return found;
|
||||
}
|
||||
|
||||
LLSD LLTextParser::parsePartialLineHighlights(const std::string &text, const LLColor4 &color, S32 part, S32 index)
|
||||
LLSD LLTextParser::parsePartialLineHighlights(const std::string &text, const LLColor4 &color, EHighlightPosition part, S32 index)
|
||||
{
|
||||
loadKeywords();
|
||||
|
||||
//evil recursive string atomizer.
|
||||
LLSD ret_llsd, start_llsd, middle_llsd, end_llsd;
|
||||
|
||||
@@ -122,7 +109,7 @@ LLSD LLTextParser::parsePartialLineHighlights(const std::string &text, const LLC
|
||||
{
|
||||
S32 end = std::string(mHighlights[i]["pattern"]).length();
|
||||
S32 len = text.length();
|
||||
S32 newpart;
|
||||
EHighlightPosition newpart;
|
||||
if (start==0)
|
||||
{
|
||||
start_llsd[0]["text"] =text.substr(0,end);
|
||||
@@ -195,6 +182,8 @@ LLSD LLTextParser::parsePartialLineHighlights(const std::string &text, const LLC
|
||||
|
||||
bool LLTextParser::parseFullLineHighlights(const std::string &text, LLColor4 *color)
|
||||
{
|
||||
loadKeywords();
|
||||
|
||||
for (S32 i=0;i<mHighlights.size();i++)
|
||||
{
|
||||
if ((S32)mHighlights[i]["highlight"]==ALL || (S32)mHighlights[i]["condition"]==MATCHES)
|
||||
@@ -221,14 +210,14 @@ std::string LLTextParser::getFileName()
|
||||
return path;
|
||||
}
|
||||
|
||||
LLSD LLTextParser::loadFromDisk()
|
||||
void LLTextParser::loadKeywords()
|
||||
{
|
||||
std::string filename=getFileName();
|
||||
if (filename.empty())
|
||||
{
|
||||
llwarns << "LLTextParser::loadFromDisk() no valid user directory." << llendl;
|
||||
if (mLoaded)
|
||||
{// keywords already loaded
|
||||
return;
|
||||
}
|
||||
else
|
||||
std::string filename=getFileName();
|
||||
if (!filename.empty())
|
||||
{
|
||||
llifstream file;
|
||||
file.open(filename.c_str());
|
||||
@@ -237,9 +226,8 @@ LLSD LLTextParser::loadFromDisk()
|
||||
LLSDSerialize::fromXML(mHighlights, file);
|
||||
}
|
||||
file.close();
|
||||
mLoaded = true;
|
||||
}
|
||||
|
||||
return mHighlights;
|
||||
}
|
||||
|
||||
bool LLTextParser::saveToDisk(LLSD highlights)
|
||||
|
||||
@@ -35,34 +35,34 @@
|
||||
#define LL_LLTEXTPARSER_H
|
||||
|
||||
#include "llsd.h"
|
||||
#include "llsingleton.h"
|
||||
|
||||
class LLUUID;
|
||||
class LLVector3d;
|
||||
class LLColor4;
|
||||
|
||||
class LLTextParser
|
||||
class LLTextParser : public LLSingleton<LLTextParser>
|
||||
{
|
||||
public:
|
||||
enum ConditionType { CONTAINS, MATCHES, STARTS_WITH, ENDS_WITH };
|
||||
enum HighlightType { PART, ALL };
|
||||
enum HighlightPosition { WHOLE, START, MIDDLE, END };
|
||||
enum DialogAction { ACTION_NONE, ACTION_CLOSE, ACTION_ADD, ACTION_COPY, ACTION_UPDATE };
|
||||
typedef enum e_condition_type { CONTAINS, MATCHES, STARTS_WITH, ENDS_WITH } EConditionType;
|
||||
typedef enum e_highlight_type { PART, ALL } EHighlightType;
|
||||
typedef enum e_highlight_position { WHOLE, START, MIDDLE, END } EHighlightPosition;
|
||||
typedef enum e_dialog_action { ACTION_NONE, ACTION_CLOSE, ACTION_ADD, ACTION_COPY, ACTION_UPDATE } EDialogAction;
|
||||
|
||||
static LLTextParser* getInstance();
|
||||
LLTextParser(){};
|
||||
~LLTextParser();
|
||||
LLTextParser();
|
||||
|
||||
S32 findPattern(const std::string &text, LLSD highlight);
|
||||
LLSD parsePartialLineHighlights(const std::string &text,const LLColor4 &color,S32 part=WHOLE, S32 index=0);
|
||||
LLSD parsePartialLineHighlights(const std::string &text,const LLColor4 &color, EHighlightPosition part=WHOLE, S32 index=0);
|
||||
bool parseFullLineHighlights(const std::string &text, LLColor4 *color);
|
||||
|
||||
std::string getFileName();
|
||||
LLSD loadFromDisk();
|
||||
bool saveToDisk(LLSD highlights);
|
||||
public:
|
||||
LLSD mHighlights;
|
||||
S32 findPattern(const std::string &text, LLSD highlight);
|
||||
private:
|
||||
static LLTextParser* sInstance;
|
||||
std::string getFileName();
|
||||
void loadKeywords();
|
||||
bool saveToDisk(LLSD highlights);
|
||||
|
||||
public:
|
||||
LLSD mHighlights;
|
||||
bool mLoaded;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user