src/nvim/screen.c
/// Put a single char from an UTF-8 buffer into a line buffer.
///
/// Handles composing chars and arabic shaping state.
Put a single char from an UTF-8 buffer into a line buffer.
Handles composing chars and arabic shaping state.
Put a single char from an UTF - 8 buffer into a line buffer . Handles composing chars and arabic shaping state .
static int line_putchar(LineState *s, schar_T *dest, int maxcells, bool rl)
{
  const char_u *p = s->p;
  int cells = utf_ptr2cells(p);
  int c_len = utfc_ptr2len(p);
  int u8c, u8cc[MAX_MCO];
  if (cells > maxcells) {
    return -1;
  }
  u8c = utfc_ptr2char(p, u8cc);
  if (*p < 0x80 && u8cc[0] == 0) {
    schar_from_ascii(dest[0], *p);
    s->prev_c = u8c;
  } else {
    if (p_arshape && !p_tbidi && arabic_char(u8c)) {
      int pc, pc1, nc;
      int pcc[MAX_MCO];
      int firstbyte = *p;
      if (rl) {
        pc = s->prev_c;
        pc1 = s->prev_c1;
        nc = utf_ptr2char(p + c_len);
        s->prev_c1 = u8cc[0];
      } else {
        pc = utfc_ptr2char(p + c_len, pcc);
        nc = s->prev_c;
        pc1 = pcc[0];
      }
      s->prev_c = u8c;
      u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], pc, pc1, nc);
    } else {
      s->prev_c = u8c;
    }
    schar_from_cc(dest[0], u8c, u8cc);
  }
  if (cells > 1) {
    dest[1][0] = 0;
  }
  s->p += c_len;
  return cells;
}
static int line_putchar ( LineState * s , schar_T * dest , int maxcells , bool rl ) { const char_u * p = s -> p ; int cells = utf_ptr2cells ( p ) ; int c_len = utfc_ptr2len ( p ) ; int u8c , u8cc [ MAX_MCO ] ; if ( cells > maxcells ) { return -1 ; } u8c = utfc_ptr2char ( p , u8cc ) ; if ( * p < 0x80 && u8cc [ 0 ] == 0 ) { schar_from_ascii ( dest [ 0 ] , * p ) ; s -> prev_c = u8c ; } else { if ( p_arshape && ! p_tbidi && arabic_char ( u8c ) ) { int pc , pc1 , nc ; int pcc [ MAX_MCO ] ; int firstbyte = * p ; if ( rl ) { pc = s -> prev_c ; pc1 = s -> prev_c1 ; nc = utf_ptr2char ( p + c_len ) ; s -> prev_c1 = u8cc [ 0 ] ; } else { pc = utfc_ptr2char ( p + c_len , pcc ) ; nc = s -> prev_c ; pc1 = pcc [ 0 ] ; } s -> prev_c = u8c ; u8c = arabic_shape ( u8c , & firstbyte , & u8cc [ 0 ] , pc , pc1 , nc ) ; } else { s -> prev_c = u8c ; } schar_from_cc ( dest [ 0 ] , u8c , u8cc ) ; } if ( cells > 1 ) { dest [ 1 ] [ 0 ] = 0 ; } s -> p += c_len ; return cells ; }
Put a single char from an UTF-8 buffer into a line buffer.
Put a single char from an UTF - 8 buffer into a line buffer .
// Do Arabic shaping. // The idea of what is the previous and next // character depends on 'rightleft'.