~ubuntu-branches/debian/sid/neovim/sid

« back to all changes in this revision

Viewing changes to src/nvim/charset.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2016-04-18 21:42:19 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20160418214219-1e6d4o1fwqarzk46
Tags: 0.1.3-1
* New upstream release.  (Closes: #820562)
* debian/control:
  + Remove unnecessary luarocks Build-Depends
  + Add libkvm-dev Build-Depends for kfreebsd-*
  + Add python(3)-neovim to Recommends.  (Closes: #812737)
  + Declare compiance with policy 3.9.8, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#endif
33
33
 
34
34
 
35
 
static int chartab_initialized = FALSE;
 
35
static bool chartab_initialized = false;
36
36
 
37
 
// b_chartab[] is an array of 32 bytes, each bit representing one of the
 
37
// b_chartab[] is an array with 256 bits, each bit representing one of the
38
38
// characters 0-255.
39
39
#define SET_CHARTAB(buf, c) \
40
 
    (buf)->b_chartab[(unsigned)(c) >> 3] |= (1 << ((c) & 0x7))
 
40
    (buf)->b_chartab[(unsigned)(c) >> 6] |= (1ull << ((c) & 0x3f))
41
41
#define RESET_CHARTAB(buf, c) \
42
 
    (buf)->b_chartab[(unsigned)(c) >> 3] &= ~(1 << ((c) & 0x7))
 
42
    (buf)->b_chartab[(unsigned)(c) >> 6] &= ~(1ull << ((c) & 0x3f))
43
43
#define GET_CHARTAB(buf, c) \
44
 
    ((buf)->b_chartab[(unsigned)(c) >> 3] & (1 << ((c) & 0x7)))
 
44
    ((buf)->b_chartab[(unsigned)(c) >> 6] & (1ull << ((c) & 0x3f)))
45
45
 
46
46
/// Fill chartab[].  Also fills curbuf->b_chartab[] with flags for keyword
47
47
/// characters for current buffer.
69
69
/// an error, OK otherwise.
70
70
int init_chartab(void)
71
71
{
72
 
  return buf_init_chartab(curbuf, TRUE);
 
72
  return buf_init_chartab(curbuf, true);
73
73
}
74
74
 
75
75
/// Helper for init_chartab
76
76
///
77
 
/// @param global FALSE: only set buf->b_chartab[]
 
77
/// @param global false: only set buf->b_chartab[]
78
78
///
79
79
/// @return FAIL if 'iskeyword', 'isident', 'isfname' or 'isprint' option has
80
80
/// an error, OK otherwise.
84
84
  int c2;
85
85
  char_u *p;
86
86
  int i;
87
 
  int tilde;
88
 
  int do_isalpha;
 
87
  bool tilde;
 
88
  bool do_isalpha;
89
89
 
90
90
  if (global) {
91
91
    // Set the default size for printable characters:
92
92
    // From <Space> to '~' is 1 (printable), others are 2 (not printable).
93
 
    // This also inits all 'isident' and 'isfname' flags to FALSE.
 
93
    // This also inits all 'isident' and 'isfname' flags to false.
94
94
    c = 0;
95
95
 
96
96
    while (c < ' ') {
133
133
    }
134
134
  }
135
135
 
136
 
  // Init word char flags all to FALSE
 
136
  // Init word char flags all to false
137
137
  memset(buf->b_chartab, 0, (size_t)32);
138
138
 
139
139
  if (enc_dbcs != 0) {
169
169
    }
170
170
 
171
171
    while (*p) {
172
 
      tilde = FALSE;
173
 
      do_isalpha = FALSE;
 
172
      tilde = false;
 
173
      do_isalpha = false;
174
174
 
175
175
      if ((*p == '^') && (p[1] != NUL)) {
176
 
        tilde = TRUE;
 
176
        tilde = true;
177
177
        ++p;
178
178
      }
179
179
 
212
212
        // standard function isalpha(). This takes care of locale for
213
213
        // single-byte characters).
214
214
        if (c == '@') {
215
 
          do_isalpha = TRUE;
 
215
          do_isalpha = true;
216
216
          c = 1;
217
217
          c2 = 255;
218
218
        } else {
231
231
          if (i == 0) {
232
232
            // (re)set ID flag
233
233
            if (tilde) {
234
 
              chartab[c] &= ~CT_ID_CHAR;
 
234
              chartab[c] &= (uint8_t)~CT_ID_CHAR;
235
235
            } else {
236
236
              chartab[c] |= CT_ID_CHAR;
237
237
            }
244
244
                 || (p_altkeymap && (F_isalpha(c) || F_isdigit(c))))
245
245
                && !(enc_dbcs && (MB_BYTE2LEN(c) == 2))) {
246
246
              if (tilde) {
247
 
                chartab[c] = (chartab[c] & ~CT_CELL_MASK)
248
 
                             + ((dy_flags & DY_UHEX) ? 4 : 2);
249
 
                chartab[c] &= ~CT_PRINT_CHAR;
 
247
                chartab[c] = (uint8_t)((chartab[c] & ~CT_CELL_MASK)
 
248
                                       + ((dy_flags & DY_UHEX) ? 4 : 2));
 
249
                chartab[c] &= (uint8_t)~CT_PRINT_CHAR;
250
250
              } else {
251
 
                chartab[c] = (chartab[c] & ~CT_CELL_MASK) + 1;
 
251
                chartab[c] = (uint8_t)((chartab[c] & ~CT_CELL_MASK) + 1);
252
252
                chartab[c] |= CT_PRINT_CHAR;
253
253
              }
254
254
            }
255
255
          } else if (i == 2) {
256
256
            // (re)set fname flag
257
257
            if (tilde) {
258
 
              chartab[c] &= ~CT_FNAME_CHAR;
 
258
              chartab[c] &= (uint8_t)~CT_FNAME_CHAR;
259
259
            } else {
260
260
              chartab[c] |= CT_FNAME_CHAR;
261
261
            }
280
280
      }
281
281
    }
282
282
  }
283
 
  chartab_initialized = TRUE;
 
283
  chartab_initialized = true;
284
284
  return OK;
285
285
}
286
286
 
333
333
{
334
334
  char_u *res;
335
335
  char_u *p;
336
 
  int l, c;
 
336
  int c;
 
337
  size_t l;
337
338
  char_u hexbuf[11];
338
339
 
339
340
  if (has_mbyte) {
343
344
    p = s;
344
345
 
345
346
    while (*p != NUL) {
346
 
      if ((l = (*mb_ptr2len)(p)) > 1) {
 
347
      if ((l = (size_t)(*mb_ptr2len)(p)) > 1) {
347
348
        c = (*mb_ptr2char)(p);
348
349
        p += l;
349
350
 
354
355
          len += STRLEN(hexbuf);
355
356
        }
356
357
      } else {
357
 
        l = byte2cells(*p++);
 
358
        l = (size_t)byte2cells(*p++);
358
359
 
359
360
        if (l > 0) {
360
361
          len += l;
366
367
    }
367
368
    res = xmallocz(len);
368
369
  } else {
369
 
    res = xmallocz(vim_strsize(s));
 
370
    res = xmallocz((size_t)vim_strsize(s));
370
371
  }
371
372
 
372
373
  *res = NUL;
373
374
  p = s;
374
375
 
375
376
  while (*p != NUL) {
376
 
    if (has_mbyte && ((l = (*mb_ptr2len)(p)) > 1)) {
 
377
    if (has_mbyte && ((l = (size_t)(*mb_ptr2len)(p)) > 1)) {
377
378
      c = (*mb_ptr2char)(p);
378
379
 
379
380
      if (vim_isprintc(c)) {
477
478
      i += (*mb_ptr2len)(STR_PTR(i));
478
479
    } else {
479
480
      if (buf == NULL) {
480
 
        GA_CHAR(i) = TOLOWER_LOC(GA_CHAR(i));
 
481
        GA_CHAR(i) = (char_u)TOLOWER_LOC(GA_CHAR(i));
481
482
      } else {
482
 
        buf[i] = TOLOWER_LOC(buf[i]);
 
483
        buf[i] = (char_u)TOLOWER_LOC(buf[i]);
483
484
      }
484
485
      ++i;
485
486
    }
493
494
 
494
495
// Catch 22: chartab[] can't be initialized before the options are
495
496
// initialized, and initializing options may cause transchar() to be called!
496
 
// When chartab_initialized == FALSE don't use chartab[].
 
497
// When chartab_initialized == false don't use chartab[].
497
498
// Does NOT work for multi-byte characters, c must be <= 255.
498
499
// Also doesn't work for the first byte of a multi-byte, "c" must be a
499
500
// character!
518
519
  if ((!chartab_initialized && (((c >= ' ') && (c <= '~')) || F_ischar(c)))
519
520
      || ((c < 256) && vim_isprintc_strict(c))) {
520
521
    // printable character
521
 
    transchar_buf[i] = c;
 
522
    transchar_buf[i] = (char_u)c;
522
523
    transchar_buf[i + 1] = NUL;
523
524
  } else {
524
525
    transchar_nonprint(transchar_buf + i, c);
564
565
    // 0x00 - 0x1f and 0x7f
565
566
    buf[0] = '^';
566
567
    // DEL displayed as ^?
567
 
    buf[1] = c ^ 0x40;
 
568
    buf[1] = (char_u)(c ^ 0x40);
568
569
 
569
570
    buf[2] = NUL;
570
571
  } else if (enc_utf8 && (c >= 0x80)) {
572
573
  } else if ((c >= ' ' + 0x80) && (c <= '~' + 0x80)) {
573
574
    // 0xa0 - 0xfe
574
575
    buf[0] = '|';
575
 
    buf[1] = c - 0x80;
 
576
    buf[1] = (char_u)(c - 0x80);
576
577
    buf[2] = NUL;
577
578
  } else {
578
579
    // 0x80 - 0x9f and 0xff
579
580
    buf[0] = '~';
580
 
    buf[1] = (c - 0x80) ^ 0x40;
 
581
    buf[1] = (char_u)((c - 0x80) ^ 0x40);
581
582
    buf[2] = NUL;
582
583
  }
583
584
}
592
593
 
593
594
  buf[0] = '<';
594
595
  if (c > 255) {
595
 
    buf[++i] = nr2hex((unsigned)c >> 12);
596
 
    buf[++i] = nr2hex((unsigned)c >> 8);
 
596
    buf[++i] = (char_u)nr2hex((unsigned)c >> 12);
 
597
    buf[++i] = (char_u)nr2hex((unsigned)c >> 8);
597
598
  }
598
 
  buf[++i] = nr2hex((unsigned)c >> 4);
599
 
  buf[++i] = nr2hex((unsigned)c);
 
599
  buf[++i] = (char_u)(nr2hex((unsigned)c >> 4));
 
600
  buf[++i] = (char_u)(nr2hex((unsigned)c));
600
601
  buf[++i] = '>';
601
602
  buf[++i] = NUL;
602
603
}
734
735
/// @return Number of characters.
735
736
#define RET_WIN_BUF_CHARTABSIZE(wp, buf, p, col) \
736
737
  if (*(p) == TAB && (!(wp)->w_p_list || lcs_tab1)) { \
737
 
    int ts; \
738
 
    ts = (buf)->b_p_ts; \
739
 
    return (int)(ts - (col % ts)); \
 
738
    const int ts = (int) (buf)->b_p_ts; \
 
739
    return (ts - (int)(col % ts)); \
740
740
  } else { \
741
741
    return ptr2cells(p); \
742
742
  }
799
799
  return (unsigned int)col;
800
800
}
801
801
 
802
 
/// Return TRUE if 'c' is a normal identifier character:
803
 
///
 
802
/// Check that "c" is a normal identifier character:
804
803
/// Letters and characters from the 'isident' option.
805
804
///
806
 
/// @param c
807
 
///
808
 
/// @return TRUE if 'c' is a normal identifier character.
809
 
int vim_isIDc(int c)
 
805
/// @param  c  character to check
 
806
bool vim_isIDc(int c)
 
807
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
810
808
{
811
809
  return c > 0 && c < 0x100 && (chartab[c] & CT_ID_CHAR);
812
810
}
813
811
 
814
 
/// return TRUE if 'c' is a keyword character: Letters and characters from
815
 
/// 'iskeyword' option for current buffer.
816
 
///
 
812
/// Check that "c" is a keyword character:
 
813
/// Letters and characters from 'iskeyword' option for current buffer.
817
814
/// For multi-byte characters mb_get_class() is used (builtin rules).
818
815
///
819
 
/// @param c
820
 
///
821
 
/// @return TRUE if 'c' is a keyword character.
822
 
int vim_iswordc(int c)
 
816
/// @param  c  character to check
 
817
bool vim_iswordc(int c)
 
818
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
823
819
{
824
820
  return vim_iswordc_buf(c, curbuf);
825
821
}
826
822
 
827
 
int vim_iswordc_buf(int c, buf_T *buf)
 
823
/// Check that "c" is a keyword character:
 
824
/// Letters and characters from 'iskeyword' option for given buffer.
 
825
/// For multi-byte characters mb_get_class() is used (builtin rules).
 
826
///
 
827
/// @param  c    character to check
 
828
/// @param  buf  buffer whose keywords to use
 
829
bool vim_iswordc_buf(int c, buf_T *buf)
 
830
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(2)
828
831
{
829
832
  if (c >= 0x100) {
830
833
    if (enc_dbcs != 0) {
840
843
 
841
844
/// Just like vim_iswordc() but uses a pointer to the (multi-byte) character.
842
845
///
843
 
/// @param p
 
846
/// @param  p  pointer to the multi-byte character
844
847
///
845
 
/// @return TRUE if 'p' points to a keyword character.
846
 
int vim_iswordp(char_u *p)
 
848
/// @return true if "p" points to a keyword character.
 
849
bool vim_iswordp(char_u *p)
 
850
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
847
851
{
848
852
  if (has_mbyte && (MB_BYTE2LEN(*p) > 1)) {
849
853
    return mb_get_class(p) >= 2;
851
855
  return GET_CHARTAB(curbuf, *p) != 0;
852
856
}
853
857
 
854
 
int vim_iswordp_buf(char_u *p, buf_T *buf)
 
858
/// Just like vim_iswordc_buf() but uses a pointer to the (multi-byte)
 
859
/// character.
 
860
///
 
861
/// @param  p    pointer to the multi-byte character
 
862
/// @param  buf  buffer whose keywords to use
 
863
///
 
864
/// @return true if "p" points to a keyword character.
 
865
bool vim_iswordp_buf(char_u *p, buf_T *buf)
 
866
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
855
867
{
856
868
  if (has_mbyte && (MB_BYTE2LEN(*p) > 1)) {
857
869
    return mb_get_class(p) >= 2;
859
871
  return GET_CHARTAB(buf, *p) != 0;
860
872
}
861
873
 
862
 
/// return TRUE if 'c' is a valid file-name character
 
874
/// Check that "c" is a valid file-name character.
863
875
/// Assume characters above 0x100 are valid (multi-byte).
864
876
///
865
 
/// @param c
866
 
///
867
 
/// @return TRUE if 'c' is a valid file name character.
868
 
int vim_isfilec(int c)
 
877
/// @param  c  character to check
 
878
bool vim_isfilec(int c)
 
879
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
869
880
{
870
881
  return c >= 0x100 || (c > 0 && (chartab[c] & CT_FNAME_CHAR));
871
882
}
872
883
 
873
 
/// return TRUE if 'c' is a valid file-name character or a wildcard character
 
884
/// Check that "c" is a valid file-name character or a wildcard character
874
885
/// Assume characters above 0x100 are valid (multi-byte).
875
886
/// Explicitly interpret ']' as a wildcard character as path_has_wildcard("]")
876
887
/// returns false.
877
888
///
878
 
/// @param c
879
 
///
880
 
/// @return TRUE if 'c' is a valid file-name character or wildcard character.
881
 
int vim_isfilec_or_wc(int c)
 
889
/// @param  c  character to check
 
890
bool vim_isfilec_or_wc(int c)
 
891
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
882
892
{
883
893
  char_u buf[2];
884
894
  buf[0] = (char_u)c;
886
896
  return vim_isfilec(c) || c == ']' || path_has_wildcard(buf);
887
897
}
888
898
 
889
 
/// return TRUE if 'c' is a printable character
890
 
/// Assume characters above 0x100 are printable (multi-byte), except for
891
 
/// Unicode.
892
 
///
893
 
/// @param c
894
 
///
895
 
/// @return TRUE if 'c' a printable character.
896
 
int vim_isprintc(int c)
 
899
/// Check that "c" is a printable character.
 
900
/// Assume characters above 0x100 are printable for double-byte encodings.
 
901
///
 
902
/// @param  c  character to check
 
903
bool vim_isprintc(int c)
 
904
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
897
905
{
898
906
  if (enc_utf8 && (c >= 0x100)) {
899
907
    return utf_printable(c);
901
909
  return c >= 0x100 || (c > 0 && (chartab[c] & CT_PRINT_CHAR));
902
910
}
903
911
 
904
 
/// Strict version of vim_isprintc(c), don't return TRUE if "c" is the head
 
912
/// Strict version of vim_isprintc(c), don't return true if "c" is the head
905
913
/// byte of a double-byte character.
906
914
///
907
 
/// @param c
 
915
/// @param  c  character to check
908
916
///
909
 
/// @return TRUE if 'c' is a printable character.
910
 
int vim_isprintc_strict(int c)
 
917
/// @return true if "c" is a printable character.
 
918
bool vim_isprintc_strict(int c)
 
919
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
911
920
{
912
921
  if ((enc_dbcs != 0) && (c < 0x100) && (MB_BYTE2LEN(c) > 1)) {
913
 
    return FALSE;
 
922
    return false;
914
923
  }
915
924
 
916
925
  if (enc_utf8 && (c >= 0x100)) {
921
930
 
922
931
/// like chartabsize(), but also check for line breaks on the screen
923
932
///
924
 
/// @param line 
 
933
/// @param line
925
934
/// @param s
926
935
/// @param col
927
936
///
1128
1137
  int n;
1129
1138
 
1130
1139
  if ((*s == TAB) && (!wp->w_p_list || lcs_tab1)) {
1131
 
    n = wp->w_buffer->b_p_ts;
 
1140
    n = (int)wp->w_buffer->b_p_ts;
1132
1141
    return n - (col % n);
1133
1142
  }
1134
1143
  n = ptr2cells(s);
1144
1153
  return n;
1145
1154
}
1146
1155
 
1147
 
/// Return TRUE if virtual column "vcol" is in the rightmost column of window
1148
 
/// "wp".
1149
 
///
1150
 
/// @param wp
1151
 
/// @param vcol
1152
 
///
1153
 
/// @return TRUE if the virtual column is in the rightmost column.
1154
 
int in_win_border(win_T *wp, colnr_T vcol)
 
1156
/// Check that virtual column "vcol" is in the rightmost column of window "wp".
 
1157
///
 
1158
/// @param  wp    window
 
1159
/// @param  vcol  column number
 
1160
bool in_win_border(win_T *wp, colnr_T vcol)
 
1161
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
1155
1162
{
1156
1163
  int width1;             // width of first line (after line number)
1157
1164
  int width2;             // width of further lines
1158
1165
 
1159
1166
  if (wp->w_width == 0) {
1160
1167
    // there is no border
1161
 
    return FALSE;
 
1168
    return false;
1162
1169
  }
1163
1170
  width1 = wp->w_width - win_col_off(wp);
1164
1171
 
1165
1172
  if ((int)vcol < width1 - 1) {
1166
 
    return FALSE;
 
1173
    return false;
1167
1174
  }
1168
1175
 
1169
1176
  if ((int)vcol == width1 - 1) {
1170
 
    return TRUE;
 
1177
    return true;
1171
1178
  }
1172
1179
  width2 = width1 + win_col_off2(wp);
1173
1180
 
1174
1181
  if (width2 <= 0) {
1175
 
    return FALSE;
 
1182
    return false;
1176
1183
  }
1177
1184
  return (vcol - width1) % width2 == width2 - 1;
1178
1185
}
1198
1205
  char_u *line;   // start of the line
1199
1206
  int incr;
1200
1207
  int head;
1201
 
  int ts = wp->w_buffer->b_p_ts;
 
1208
  int ts = (int)wp->w_buffer->b_p_ts;
1202
1209
  int c;
1203
1210
 
1204
1211
  vcol = 0;
1205
 
  line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE);
 
1212
  line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, false);
1206
1213
 
1207
1214
  if (pos->col == MAXCOL) {
1208
1215
    // continue until the NUL
1322
1329
  int list_save = curwin->w_p_list;
1323
1330
  colnr_T vcol;
1324
1331
 
1325
 
  curwin->w_p_list = FALSE;
 
1332
  curwin->w_p_list = false;
1326
1333
  getvcol(curwin, posp, NULL, &vcol, NULL);
1327
1334
  curwin->w_p_list = list_save;
1328
1335
  return vcol;
1351
1358
    endadd = 0;
1352
1359
 
1353
1360
    // Cannot put the cursor on part of a wide character.
1354
 
    ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE);
 
1361
    ptr = ml_get_buf(wp->w_buffer, pos->lnum, false);
1355
1362
 
1356
1363
    if (pos->col < (colnr_T)STRLEN(ptr)) {
1357
1364
      int c = (*mb_ptr2char)(ptr + pos->col);
1571
1578
    "\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee"
1572
1579
    "\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff";
1573
1580
 
1574
 
int vim_islower(int c)
 
1581
/// Check that the character is lower-case
 
1582
///
 
1583
/// @param  c  character to check
 
1584
bool vim_islower(int c)
 
1585
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
1575
1586
{
1576
1587
  if (c <= '@') {
1577
 
    return FALSE;
 
1588
    return false;
1578
1589
  }
1579
1590
 
1580
1591
  if (c >= 0x80) {
1584
1595
 
1585
1596
    if (c >= 0x100) {
1586
1597
      if (has_mbyte) {
1587
 
        return iswlower(c);
 
1598
        return iswlower((wint_t)c);
1588
1599
      }
1589
1600
 
1590
1601
      // islower() can't handle these chars and may crash
1591
 
      return FALSE;
 
1602
      return false;
1592
1603
    }
1593
1604
 
1594
1605
    if (enc_latin1like) {
1598
1609
  return islower(c);
1599
1610
}
1600
1611
 
1601
 
int vim_isupper(int c)
 
1612
/// Check that the character is upper-case
 
1613
///
 
1614
/// @param  c  character to check
 
1615
bool vim_isupper(int c)
 
1616
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
1602
1617
{
1603
1618
  if (c <= '@') {
1604
 
    return FALSE;
 
1619
    return false;
1605
1620
  }
1606
1621
 
1607
1622
  if (c >= 0x80) {
1611
1626
 
1612
1627
    if (c >= 0x100) {
1613
1628
      if (has_mbyte) {
1614
 
        return iswupper(c);
 
1629
        return iswupper((wint_t)c);
1615
1630
      }
1616
1631
 
1617
 
      // islower() can't handle these chars and may crash
1618
 
      return FALSE;
 
1632
      // isupper() can't handle these chars and may crash
 
1633
      return false;
1619
1634
    }
1620
1635
 
1621
1636
    if (enc_latin1like) {
1638
1653
 
1639
1654
    if (c >= 0x100) {
1640
1655
      if (has_mbyte) {
1641
 
        return towupper(c);
 
1656
        return (int)towupper((wint_t)c);
1642
1657
      }
1643
1658
 
1644
1659
      // toupper() can't handle these chars and may crash
1665
1680
 
1666
1681
    if (c >= 0x100) {
1667
1682
      if (has_mbyte) {
1668
 
        return towlower(c);
 
1683
        return (int)towlower((wint_t)c);
1669
1684
      }
1670
1685
 
1671
1686
      // tolower() can't handle these chars and may crash
1744
1759
  return (long)number;
1745
1760
}
1746
1761
 
1747
 
/// Return TRUE if "lbuf" is empty or only contains blanks.
1748
 
///
1749
 
/// @param lbuf
1750
 
///
1751
 
/// @return TRUE if `lbuf` is empty or only contains blanks.
1752
 
int vim_isblankline(char_u *lbuf)
 
1762
/// Check that "lbuf" is empty or only contains blanks.
 
1763
///
 
1764
/// @param  lbuf  line buffer to check
 
1765
bool vim_isblankline(char_u *lbuf)
1753
1766
{
1754
1767
  char_u *p = skipwhite(lbuf);
1755
1768
  return *p == NUL || *p == '\r' || *p == '\n';
1922
1935
  return c - '0';
1923
1936
}
1924
1937
 
1925
 
/// Return true if "str" starts with a backslash that should be removed.
1926
 
/// For WIN32 this is only done when the character after the
 
1938
/// Check that "str" starts with a backslash that should be removed.
 
1939
/// For Windows this is only done when the character after the
1927
1940
/// backslash is not a normal file name character.
1928
1941
/// '$' is a valid file name character, we don't remove the backslash before
1929
1942
/// it.  This means it is not possible to use an environment variable after a
1934
1947
/// character, assume that all multi-byte characters are valid file name
1935
1948
/// characters.
1936
1949
///
1937
 
/// @param str
1938
 
///
1939
 
/// @return true if `str` starts with a backslash that should be removed.
 
1950
/// @param  str  file path string to check
1940
1951
bool rem_backslash(const char_u *str)
 
1952
  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
1941
1953
{
1942
1954
#ifdef BACKSLASH_IN_FILENAME
1943
1955
  return str[0] == '\\'