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:
parent
4754d33419
commit
1b6401d6a4
|
@ -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 = "&";
|
||||
static const String htmlLt = "<";
|
||||
static const String htmlGt = ">";
|
||||
static const String htmlQuot = """;
|
||||
|
||||
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)
|
||||
|
|
|
@ -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 = "&";
|
||||
static const String htmlLt = "<";
|
||||
static const String htmlGt = ">";
|
||||
static const String htmlQuot = """;
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue