0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.0.0262: Farsi support is barely tested

Problem:    Farsi support is barely tested.
Solution:   Add more tests for Farsi.  Clean up the code.
This commit is contained in:
Bram Moolenaar
2017-01-29 17:59:12 +01:00
parent 24c2e48ef8
commit ddf662a1c8
4 changed files with 313 additions and 309 deletions

View File

@@ -6166,6 +6166,9 @@ insertchar(
&& (!has_mbyte || MB_BYTE2LEN_CHECK(c) == 1)
#endif
&& i < INPUT_BUFLEN
# ifdef FEAT_FKMAP
&& !(p_fkmap && KeyTyped) /* Farsi mode mapping moves cursor */
# endif
&& (textwidth == 0
|| (virtcol += byte2cells(buf[i - 1])) < (colnr_T)textwidth)
&& !(!no_abbr && !vim_iswordc(c) && vim_iswordc(buf[i - 1])))
@@ -6174,10 +6177,6 @@ insertchar(
c = vgetc();
if (p_hkmap && KeyTyped)
c = hkmap(c); /* Hebrew mode mapping */
# ifdef FEAT_FKMAP
if (p_fkmap && KeyTyped)
c = fkmap(c); /* Farsi mode mapping */
# endif
buf[i++] = c;
#else
buf[i++] = vgetc();

View File

@@ -15,30 +15,11 @@
#if defined(FEAT_FKMAP) || defined(PROTO)
static int toF_Xor_X_(int c);
static int F_is_TyE(int c);
static int F_is_TyC_TyD(int c);
static int F_is_TyB_TyC_TyD(int src, int offset);
static int toF_TyB(int c);
static void put_curr_and_l_to_X(int c);
static void put_and_redo(int c);
static void chg_c_toX_orX(void);
static void chg_c_to_X_orX_(void);
static void chg_c_to_X_or_X(void);
static void chg_l_to_X_orX_(void);
static void chg_l_toXor_X(void);
static void chg_r_to_Xor_X_(void);
static int toF_leading(int c);
static int toF_Rjoin(int c);
static int canF_Ljoin(int c);
static int canF_Rjoin(int c);
static int F_isterm(int c);
static int toF_ending(int c);
static void lrswapbuf(char_u *buf, int len);
/*
* Convert the given Farsi character into a _X or _X_ type
*/
*/
static int
toF_Xor_X_(int c)
{
@@ -105,7 +86,7 @@ toF_Xor_X_(int c)
/*
* Convert the given Farsi character into Farsi capital character.
*/
*/
static int
toF_TyA(int c)
{
@@ -156,7 +137,7 @@ toF_TyA(int c)
* Is the character under the cursor+offset in the given buffer a join type.
* That is a character that is combined with the others.
* Note: the offset is used only for command line buffer.
*/
*/
static int
F_is_TyB_TyC_TyD(int src, int offset)
{
@@ -207,7 +188,7 @@ F_is_TyB_TyC_TyD(int src, int offset)
/*
* Is the Farsi character one of the terminating only type.
*/
*/
static int
F_is_TyE(int c)
{
@@ -230,7 +211,7 @@ F_is_TyE(int c)
/*
* Is the Farsi character one of the none leading type.
*/
*/
static int
F_is_TyC_TyD(int c)
{
@@ -254,7 +235,7 @@ F_is_TyC_TyD(int c)
/*
* Convert a none leading Farsi char into a leading type.
*/
*/
static int
toF_TyB(int c)
{
@@ -275,9 +256,18 @@ toF_TyB(int c)
return c;
}
static void
put_and_redo(int c)
{
pchar_cursor(c);
AppendCharToRedobuff(K_BS);
AppendCharToRedobuff(c);
}
/*
* Overwrite the current redo and cursor characters + left adjust.
*/
*/
static void
put_curr_and_l_to_X(int c)
{
@@ -312,17 +302,9 @@ put_curr_and_l_to_X(int c)
put_and_redo(c);
}
static void
put_and_redo(int c)
{
pchar_cursor(c);
AppendCharToRedobuff(K_BS);
AppendCharToRedobuff(c);
}
/*
* Change the char. under the cursor to a X_ or X type
*/
*/
static void
chg_c_toX_orX(void)
{
@@ -446,8 +428,7 @@ chg_c_toX_orX(void)
/*
* Change the char. under the cursor to a _X_ or X_ type
*/
*/
static void
chg_c_to_X_orX_(void)
{
@@ -498,9 +479,9 @@ chg_c_to_X_orX_(void)
/*
* Change the char. under the cursor to a _X_ or _X type
*/
*/
static void
chg_c_to_X_or_X (void)
chg_c_to_X_or_X(void)
{
int tempc;
@@ -529,7 +510,7 @@ chg_c_to_X_or_X (void)
/*
* Change the character left to the cursor to a _X_ or X_ type
*/
*/
static void
chg_l_to_X_orX_(void)
{
@@ -597,10 +578,9 @@ chg_l_to_X_orX_(void)
/*
* Change the character left to the cursor to a X or _X type
*/
*/
static void
chg_l_toXor_X (void)
chg_l_toXor_X(void)
{
int tempc;
@@ -666,8 +646,7 @@ chg_l_toXor_X (void)
/*
* Change the character right to the cursor to a _X or _X_ type
*/
*/
static void
chg_r_to_Xor_X_(void)
{
@@ -691,20 +670,23 @@ chg_r_to_Xor_X_(void)
/*
* Map Farsi keyboard when in fkmap mode.
*/
*/
int
fkmap(int c)
{
int tempc;
static int revins;
int insert_mode = (State & INSERT);
static int revins = 0;
if (IS_SPECIAL(c))
return c;
if (insert_mode)
{
if (VIM_ISDIGIT(c) || ((c == '.' || c == '+' || c == '-' ||
c == '^' || c == '%' || c == '#' || c == '=') && revins))
{
/* Numbers are entered left-to-right. */
if (!revins)
{
if (curwin->w_cursor.col)
@@ -727,12 +709,11 @@ fkmap(int c)
inc_cursor();
++revins;
p_ri=1;
p_ri = 1;
}
else
{
if (revins)
else if (revins)
{
/* Stop entering number. */
arrow_used = TRUE;
(void)stop_arrow();
@@ -773,14 +754,14 @@ fkmap(int c)
if (!revins)
{
if (curwin->w_p_rl)
p_ri=0;
p_ri = 0;
if (!curwin->w_p_rl)
p_ri=1;
p_ri = 1;
}
if ((c < 0x100) && (isalpha(c) || c == '&' || c == '^' || c == ';' ||
c == '\''|| c == ',' || c == '[' ||
c == ']' || c == '{' || c == '}' ))
c == ']' || c == '{' || c == '}'))
chg_r_to_Xor_X_();
tempc = 0;
@@ -844,13 +825,12 @@ fkmap(int c)
case NL:
case TAB:
if (p_ri && c == NL && curwin->w_cursor.col)
if (p_ri && c == NL && curwin->w_cursor.col && insert_mode)
{
/*
* If the char before the cursor is _X_ or X_ do not change
* the one under the cursor with X type.
*/
dec_cursor();
if (F_isalpha(gchar_cursor()))
@@ -920,6 +900,9 @@ fkmap(int c)
}
break;
}
if (insert_mode)
{
if (!p_ri)
dec_cursor();
@@ -1040,6 +1023,7 @@ fkmap(int c)
if (!p_ri)
inc_cursor();
}
tempc = 0;
@@ -1376,14 +1360,14 @@ fkmap(int c)
break;
}
if ((F_isalpha(tempc) || F_isdigit(tempc)))
if (F_isalpha(tempc) || F_isdigit(tempc))
{
if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{
if (!p_ri && !F_is_TyE(tempc))
chg_c_to_X_orX_ ();
chg_c_to_X_orX_();
if (p_ri)
chg_c_to_X_or_X ();
chg_c_to_X_or_X();
}
if (curwin->w_cursor.col)
@@ -1392,9 +1376,9 @@ fkmap(int c)
dec_cursor();
if (F_is_TyE(tempc))
chg_l_toXor_X ();
chg_l_toXor_X();
else
chg_l_to_X_orX_ ();
chg_l_to_X_orX_();
if (!p_ri)
inc_cursor();
@@ -1407,7 +1391,7 @@ fkmap(int c)
/*
* Convert a none leading Farsi char into a leading type.
*/
*/
static int
toF_leading(int c)
{
@@ -1461,7 +1445,7 @@ toF_leading(int c)
/*
* Convert a given Farsi char into right joining type.
*/
*/
static int
toF_Rjoin(int c)
{
@@ -1517,7 +1501,7 @@ toF_Rjoin(int c)
/*
* Can a given Farsi character join via its left edj.
*/
*/
static int
canF_Ljoin(int c)
{
@@ -1591,7 +1575,7 @@ canF_Ljoin(int c)
/*
* Can a given Farsi character join via its right edj.
*/
*/
static int
canF_Rjoin(int c)
{
@@ -1619,7 +1603,7 @@ canF_Rjoin(int c)
/*
* is a given Farsi character a terminating type.
*/
*/
static int
F_isterm(int c)
{
@@ -1646,7 +1630,7 @@ F_isterm(int c)
/*
* Convert the given Farsi character into a ending type .
*/
*/
static int
toF_ending(int c)
{
@@ -1691,7 +1675,7 @@ toF_ending(int c)
/*
* Convert the Farsi 3342 standard into Farsi VIM.
*/
*/
static void
conv_to_pvim(void)
{

View File

@@ -1,4 +1,5 @@
" Simplistic testing of Farsi mode.
" Note: must be edited with latin1 encoding.
if !has('farsi')
finish
@@ -82,3 +83,21 @@ func Test_farsi_map()
set noaltkeymap
bwipe!
endfunc
func Test_input_farsi()
new
setlocal rightleft fkmap
" numbers switch input direction
call feedkeys("aabc0123456789.+-^%#=xyz\<Esc>", 'tx')
call assert_equal("\x8c<38>ν<EFBFBD><CEBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\x93<39>", getline('.'))
" all non-number special chars
call feedkeys("aB E F H I K L M O P Q R T U W Y ` ! @ # $ % ^ & * () - _ = + \\ | : \" . / < > ? \<Esc>", 'tx')
call assert_equal("\x8c<38>ν<EFBFBD><CEBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\x93ա<33><D5A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [<5B>]<5D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>񠢠<EFBFBD><F1A0A2A0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8A0A8><EFBFBD><EFBFBD><EFBFBD><E9A0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EAA0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", getline('.'))
" all letter chars
call feedkeys("aa A b c C d D e f g G h i j J k l m n N o p q r s S t u v V w x X y z Z ; \ , [ ] \<Esc>", 'tx')
call assert_equal("\x8c<38>ν<EFBFBD><CEBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\x93ա<33><D5A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [<5B>]<5D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>񠢠<EFBFBD><F1A0A2A0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8A0A8><EFBFBD><EFBFBD><EFBFBD><E9A0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EAA0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѡ<EFBFBD><D1A0>̠ΠϠ<CEA0><CFA0><EFBFBD><EFBFBD>Ơàܠ<C3A0><DCA0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Š<EFBFBD><C5A0>ޠݠĠˠˠʠɠӠ٠Р<D9A0><D0A0>ؠ֠͠͠ҠԠԠנՠ<D7A0><D5A0>ڠ<EFBFBD>ߠǠȠ", getline('.'))
bwipe!
endfunc

View File

@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
262,
/**/
261,
/**/