Improve the logic for identifying numbers

This commit is contained in:
Saumya Bhatnagar 2018-06-03 06:15:30 +05:30
parent 507c1b1578
commit f52c02e327
2 changed files with 15 additions and 3 deletions

BIN
editor

Binary file not shown.

View File

@ -217,15 +217,27 @@ int getWindowSize(int * row, int * col) {
}
/*** syntax highlighting ***/
int is_separator(int c) {
return isspace(c) || c == '\0' || strchr(",.()+-/*=~%<>[];", c) != NULL;
}
void editorUpdateSyntax(editorrow *row) {
row->hl = realloc(row->hl, row->rsize);
memset(row->hl, HL_NORMAL, row->rsize);
for (int i = 0; i < row->rsize; i++) {
if (isdigit(row->render[i])) {
int prev_sep = 1;
int i = 0;
while (i < row->rsize) {
char c = row->render[i];
unsigned char prev_hl = (i > 0) ? row->hl[i - 1] : HL_NORMAL;
if ((isdigit(c) && (prev_sep || prev_hl == HL_NUMBER)) ||
(c == '.' && prev_hl == HL_NUMBER)) {
row->hl[i] = HL_NUMBER;
i++;
prev_sep = 0;
continue;
}
prev_sep = is_separator(c);
i++;
}
}