esc logic in input, w: fix

This commit is contained in:
p.kosyh 2010-06-16 08:36:19 +00:00
parent 3848e22674
commit e3c881f5b9
3 changed files with 19 additions and 7 deletions

View file

@ -1813,7 +1813,7 @@ static int is_delim(int c)
static int process_word_token(const char *p, char **eptr, char ch)
{
int len = 0;
char *ep;
if (eptr)
*eptr = (char*)p;
if (!p)
@ -1821,12 +1821,12 @@ static int process_word_token(const char *p, char **eptr, char ch)
if (p[0] != '<' || p[1] != ch || p[2] != ':')
return 0;
p += 3;
len = strcspn(p, ">");
if (p[len] != '>')
ep = find_in_esc(p, "\\>");
if (*ep != '>')
return 0;
if (eptr)
*eptr = (char*)p + len + 1;
return len + 1;
*eptr = ep + 1;
return (ep - p + 1);
}
static int word_img(const char *p, char **eptr)
@ -2468,12 +2468,18 @@ char *get_word_token(char *p)
{
int len;
char *r;
char *val = NULL;
len = word_token(p, NULL);
if (!len)
return p;
p[len - 1 + 3] = 0;
r = strdup((p + 3));
parse_esc_string(r, &val);
free(p);
if (val) {
free(r);
r = val;
}
return r;
}

View file

@ -35,6 +35,7 @@ end;
iface.nb = function(self, str)
if str == nil then return nil; end;
if str == '' then return ''; end
return "<w:"..str..">";
end;

View file

@ -258,6 +258,11 @@ function(f, ...)
return f(unpack(arg))
end)
function input_esc(s)
if not s then return end
return s:gsub("\\","\\\\"):gsub(">","\\>");
end
function inp(info, txt)
local v = { nam = '', _txt = '', info = info }
if txt then
@ -265,9 +270,9 @@ function inp(info, txt)
end
v.dsc = function(s)
if s._edit then
return s.info..input._txt..input.cursor
return s.info..txtnb(input_esc(input._txt))..input.cursor
end
return s.info..s._txt
return s.info..txtnb(input_esc(s._txt))
end
v.text = function(s)
if s._edit then return input._txt end