text syntax highlighting, add utility function 'text_format_fill()' which fills in the line with a formatting value.
this fixes a mistake in OSL lexer which would comment all lines after '//'
This commit is contained in:
@@ -140,6 +140,35 @@ int text_check_format_len(TextLine *line, unsigned int len)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill the string with formatting constant,
|
||||||
|
* advancing \a str_p and \a fmt_p
|
||||||
|
*
|
||||||
|
* \param len length in bytes
|
||||||
|
*/
|
||||||
|
void text_format_fill(const char **str_p, char **fmt_p, const char type, const int len)
|
||||||
|
{
|
||||||
|
const char *str = *str_p;
|
||||||
|
char *fmt = *fmt_p;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while (i < len) {
|
||||||
|
const int size = BLI_str_utf8_size_safe(str);
|
||||||
|
*fmt++ = type;
|
||||||
|
|
||||||
|
str += size;
|
||||||
|
i += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
str--;
|
||||||
|
fmt--;
|
||||||
|
|
||||||
|
BLI_assert(*str != '\0');
|
||||||
|
|
||||||
|
*str_p = str;
|
||||||
|
*fmt_p = fmt;
|
||||||
|
}
|
||||||
|
|
||||||
/* *** Registration *** */
|
/* *** Registration *** */
|
||||||
static ListBase tft_lb = {NULL, NULL};
|
static ListBase tft_lb = {NULL, NULL};
|
||||||
void ED_text_format_register(TextFormatType *tft)
|
void ED_text_format_register(TextFormatType *tft)
|
||||||
|
@@ -49,18 +49,17 @@ enum {
|
|||||||
FMT_CONT_TRIPLE = (1 << 2), /* triplets of quotes: """ or ''' */
|
FMT_CONT_TRIPLE = (1 << 2), /* triplets of quotes: """ or ''' */
|
||||||
FMT_CONT_QUOTESINGLE_TRIPLE = (FMT_CONT_TRIPLE | FMT_CONT_QUOTESINGLE),
|
FMT_CONT_QUOTESINGLE_TRIPLE = (FMT_CONT_TRIPLE | FMT_CONT_QUOTESINGLE),
|
||||||
FMT_CONT_QUOTEDOUBLE_TRIPLE = (FMT_CONT_TRIPLE | FMT_CONT_QUOTEDOUBLE),
|
FMT_CONT_QUOTEDOUBLE_TRIPLE = (FMT_CONT_TRIPLE | FMT_CONT_QUOTEDOUBLE),
|
||||||
FMT_CONT_COMMENT_C = (1 << 3), /* multi-line comments, OSL only (C style) */
|
FMT_CONT_COMMENT_C = (1 << 3) /* multi-line comments, OSL only (C style) */
|
||||||
FMT_CONT_COMMENT_CXX = (1 << 4), /* single-line comments, OSL only (C++ style) */
|
|
||||||
};
|
};
|
||||||
#define FMT_CONT_ALL \
|
#define FMT_CONT_ALL \
|
||||||
(FMT_CONT_QUOTESINGLE | FMT_CONT_QUOTEDOUBLE | FMT_CONT_TRIPLE | FMT_CONT_COMMENT_C | FMT_CONT_COMMENT_CXX)
|
(FMT_CONT_QUOTESINGLE | FMT_CONT_QUOTEDOUBLE | FMT_CONT_TRIPLE | FMT_CONT_COMMENT_C)
|
||||||
|
|
||||||
int flatten_string(struct SpaceText *st, FlattenString *fs, const char *in);
|
int flatten_string(struct SpaceText *st, FlattenString *fs, const char *in);
|
||||||
void flatten_string_free(FlattenString *fs);
|
void flatten_string_free(FlattenString *fs);
|
||||||
int flatten_string_strlen(FlattenString *fs, const char *str);
|
int flatten_string_strlen(FlattenString *fs, const char *str);
|
||||||
|
|
||||||
int text_check_format_len(TextLine *line, unsigned int len);
|
int text_check_format_len(TextLine *line, unsigned int len);
|
||||||
|
void text_format_fill(const char **str_p, char **fmt_p, const char type, const int len);
|
||||||
|
|
||||||
/* *** Generalize Formatting *** */
|
/* *** Generalize Formatting *** */
|
||||||
typedef struct TextFormatType {
|
typedef struct TextFormatType {
|
||||||
|
@@ -228,10 +228,7 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const int do_n
|
|||||||
/* Handle continuations */
|
/* Handle continuations */
|
||||||
else if (cont) {
|
else if (cont) {
|
||||||
/* C-Style comments */
|
/* C-Style comments */
|
||||||
if (cont & FMT_CONT_COMMENT_CXX) {
|
if (cont & FMT_CONT_COMMENT_C) {
|
||||||
*fmt = FMT_TYPE_COMMENT;
|
|
||||||
}
|
|
||||||
else if (cont & FMT_CONT_COMMENT_C) {
|
|
||||||
if (*str == '*' && *(str + 1) == '/') {
|
if (*str == '*' && *(str + 1) == '/') {
|
||||||
*fmt = FMT_TYPE_COMMENT; fmt++; str++;
|
*fmt = FMT_TYPE_COMMENT; fmt++; str++;
|
||||||
*fmt = FMT_TYPE_COMMENT;
|
*fmt = FMT_TYPE_COMMENT;
|
||||||
@@ -254,8 +251,8 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const int do_n
|
|||||||
else {
|
else {
|
||||||
/* Deal with comments first */
|
/* Deal with comments first */
|
||||||
if (*str == '/' && *(str + 1) == '/') {
|
if (*str == '/' && *(str + 1) == '/') {
|
||||||
cont = FMT_CONT_COMMENT_CXX;
|
/* fill the remaining line */
|
||||||
*fmt = FMT_TYPE_COMMENT;
|
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - (int)(str - fs.buf));
|
||||||
}
|
}
|
||||||
/* C-Style (multi-line) comments */
|
/* C-Style (multi-line) comments */
|
||||||
else if (*str == '/' && *(str + 1) == '*') {
|
else if (*str == '/' && *(str + 1) == '*') {
|
||||||
@@ -298,8 +295,7 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const int do_n
|
|||||||
else if ((i = txtfmt_osl_find_preprocessor(str)) != -1) prev = FMT_TYPE_DIRECTIVE;
|
else if ((i = txtfmt_osl_find_preprocessor(str)) != -1) prev = FMT_TYPE_DIRECTIVE;
|
||||||
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
memset(fmt, prev, i);
|
text_format_fill(&str, &fmt, prev, i);
|
||||||
i--; fmt += i; str += i;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
str += BLI_str_utf8_size_safe(str) - 1;
|
str += BLI_str_utf8_size_safe(str) - 1;
|
||||||
|
@@ -231,9 +231,9 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_ne
|
|||||||
/* Not in a string... */
|
/* Not in a string... */
|
||||||
else {
|
else {
|
||||||
/* Deal with comments first */
|
/* Deal with comments first */
|
||||||
if (prev == FMT_TYPE_COMMENT || *str == '#') {
|
if (*str == '#') {
|
||||||
*fmt = FMT_TYPE_COMMENT;
|
/* fill the remaining line */
|
||||||
str += BLI_str_utf8_size_safe(str) - 1;
|
text_format_fill(&str, &fmt, prev, len - (int)(str - fs.buf));
|
||||||
}
|
}
|
||||||
else if (*str == '"' || *str == '\'') {
|
else if (*str == '"' || *str == '\'') {
|
||||||
/* Strings */
|
/* Strings */
|
||||||
@@ -285,8 +285,7 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_ne
|
|||||||
else if ((i = txtfmt_py_find_decorator(str)) != -1) prev = FMT_TYPE_DIRECTIVE;
|
else if ((i = txtfmt_py_find_decorator(str)) != -1) prev = FMT_TYPE_DIRECTIVE;
|
||||||
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
memset(fmt, prev, i);
|
text_format_fill(&str, &fmt, prev, i);
|
||||||
i--; fmt += i; str += i;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
str += BLI_str_utf8_size_safe(str) - 1;
|
str += BLI_str_utf8_size_safe(str) - 1;
|
||||||
|
Reference in New Issue
Block a user