Added client method used to replace plain text chars with html markups.

git-svn-id: http://yate.null.ro/svn/yate/trunk@4341 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2011-04-27 12:09:19 +00:00
parent 4754d33419
commit 1b6401d6a4
3 changed files with 44 additions and 36 deletions

View File

@ -2916,6 +2916,42 @@ void Client::generateGuid(String& buf, const String& extra)
buf << tmp.substr(20);
}
// Replace plain text chars with HTML escape or markup
void Client::plain2html(String& buf, bool spaceEol)
{
static const String space = " ";
static const String htmlBr = "<br>";
static const String htmlAmp = "&amp;";
static const String htmlLt = "&lt;";
static const String htmlGt = "&gt;";
static const String htmlQuot = "&quot;";
unsigned int i = 0;
while (i < buf.length()) {
const String* mark = 0;
if (buf[i] == '\r' || buf[i] == '\n')
mark = spaceEol ? &space : &htmlBr;
else if (buf[i] == '&')
mark = &htmlAmp;
else if (buf[i] == '<')
mark = &htmlLt;
else if (buf[i] == '>')
mark = &htmlGt;
else if (buf[i] == '\"')
mark = &htmlQuot;
else {
i++;
continue;
}
// Handle "\r\n" as single <br>
if (buf[i] == '\r' && i != buf.length() - 1 && buf[i + 1] == '\n')
buf = buf.substr(0,i) + *mark + buf.substr(i + 2);
else
buf = buf.substr(0,i) + *mark + buf.substr(i + 1);
i += mark->length();
}
}
// Build an 'ui.event' message
Message* Client::eventMessage(const String& event, Window* wnd, const char* name,
NamedList* params)

View File

@ -70,41 +70,6 @@ static inline bool isIgnoreUrlEnd(char c)
return (c == '.' || c == ';' || c == ':' || c == '?' || c == '!');
}
// Replace plain text chars with HTML escape or markup
static void plain2html(String& buf)
{
static const String htmlBr = "<br>";
static const String htmlAmp = "&amp;";
static const String htmlLt = "&lt;";
static const String htmlGt = "&gt;";
static const String htmlQuot = "&quot;";
unsigned int i = 0;
while (i < buf.length()) {
const String* mark = 0;
if (buf[i] == '\r' || buf[i] == '\n')
mark = &htmlBr;
else if (buf[i] == '&')
mark = &htmlAmp;
else if (buf[i] == '<')
mark = &htmlLt;
else if (buf[i] == '>')
mark = &htmlGt;
else if (buf[i] == '\"')
mark = &htmlQuot;
else {
i++;
continue;
}
// Handle "\r\n" as single <br>
if (buf[i] == '\r' && i != buf.length() - 1 && buf[i + 1] == '\n')
buf = buf.substr(0,i) + *mark + buf.substr(i + 2);
else
buf = buf.substr(0,i) + *mark + buf.substr(i + 1);
i += mark->length();
}
}
// Move a cursor at document start/end.
// Adjust position by 'blocks' count
// Select if required and blocks is not 0
@ -194,7 +159,7 @@ void CustomTextFormat::buildText(String& text, const NamedList* params,
for (unsigned int i = 0; i < n; i++) {
String* s = dummy.getParam(i);
if (!TelEngine::null(s)) {
plain2html(*s);
Client::plain2html(*s);
if (owner)
owner->replace(*s);
}

View File

@ -1647,6 +1647,13 @@ public:
*/
static void generateGuid(String& buf, const String& extra = String::empty());
/**
* Replace plain text chars with HTML escape or markup
* @param buf Destination string
* @param spaceEol True to replace end of line with space instead of html markup
*/
static void plain2html(String& buf, bool spaceEol = false);
static Configuration s_settings; // Client settings
static Configuration s_actions; // Logic preferrences
static Configuration s_accounts; // Accounts