Text: buffer from text, optional length return arg

No functional changes (currently unused).
This commit is contained in:
2019-07-11 14:18:39 +10:00
parent 676543d91f
commit a7ac40888f
4 changed files with 27 additions and 11 deletions

View File

@@ -54,7 +54,7 @@ void BKE_text_write(struct Text *text, struct TextUndoBuf *utxt, const char *str
int BKE_text_file_modified_check(struct Text *text);
void BKE_text_file_modified_ignore(struct Text *text);
char *txt_to_buf(struct Text *text);
char *txt_to_buf(struct Text *text, int *r_buf_strlen);
void txt_clean_text(struct Text *text);
void txt_order_cursors(struct Text *text, const bool reverse);
int txt_find_string(struct Text *text, const char *findstr, int wrap, int match_case);
@@ -83,7 +83,7 @@ void txt_delete_selected(struct Text *text, struct TextUndoBuf *utxt);
void txt_sel_all(struct Text *text);
void txt_sel_clear(struct Text *text);
void txt_sel_line(struct Text *text);
char *txt_sel_to_buf(struct Text *text);
char *txt_sel_to_buf(struct Text *text, int *r_buf_strlen);
void txt_insert_buf(struct Text *text, struct TextUndoBuf *utxt, const char *in_buffer);
void txt_undo_add_op(struct Text *text, struct TextUndoBuf *utxt, int op);
void txt_do_undo(struct Text *text, struct TextUndoBuf *utxt);

View File

@@ -1289,7 +1289,7 @@ static void txt_delete_sel(Text *text, TextUndoBuf *utxt)
txt_order_cursors(text, false);
if (!undoing) {
buf = txt_sel_to_buf(text);
buf = txt_sel_to_buf(text, NULL);
txt_undo_add_blockop(text, utxt, UNDO_DBLOCK, buf);
MEM_freeN(buf);
}
@@ -1353,13 +1353,17 @@ void txt_sel_line(Text *text)
/* Cut and paste functions */
/***************************/
char *txt_to_buf(Text *text)
char *txt_to_buf(Text *text, int *r_buf_strlen)
{
int length;
TextLine *tmp, *linef, *linel;
int charf, charl;
char *buf;
if (r_buf_strlen) {
*r_buf_strlen = 0;
}
if (!text->curl) {
return NULL;
}
@@ -1419,6 +1423,10 @@ char *txt_to_buf(Text *text)
buf[length] = 0;
}
if (r_buf_strlen) {
*r_buf_strlen = length;
}
return buf;
}
@@ -1475,13 +1483,17 @@ int txt_find_string(Text *text, const char *findstr, int wrap, int match_case)
}
}
char *txt_sel_to_buf(Text *text)
char *txt_sel_to_buf(Text *text, int *r_buf_strlen)
{
char *buf;
int length = 0;
TextLine *tmp, *linef, *linel;
int charf, charl;
if (r_buf_strlen) {
*r_buf_strlen = 0;
}
if (!text->curl) {
return NULL;
}
@@ -1556,6 +1568,10 @@ char *txt_sel_to_buf(Text *text)
buf[length] = 0;
}
if (r_buf_strlen) {
*r_buf_strlen = length;
}
return buf;
}

View File

@@ -932,7 +932,7 @@ static void txt_copy_clipboard(Text *text)
return;
}
buf = txt_sel_to_buf(text);
buf = txt_sel_to_buf(text, NULL);
if (buf) {
WM_clipboard_text_set(buf, 0);
@@ -2994,7 +2994,7 @@ static void text_cursor_set_exit(bContext *C, wmOperator *op)
char *buffer;
if (txt_has_sel(text)) {
buffer = txt_sel_to_buf(text);
buffer = txt_sel_to_buf(text, NULL);
WM_clipboard_text_set(buffer, 1);
MEM_freeN(buffer);
}
@@ -3308,7 +3308,7 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
/* Replace current */
if (mode != TEXT_FIND && txt_has_sel(text)) {
tmp = txt_sel_to_buf(text);
tmp = txt_sel_to_buf(text, NULL);
if (flags & ST_MATCH_CASE) {
found = STREQ(st->findstr, tmp);
@@ -3406,7 +3406,7 @@ static int text_find_set_selected_exec(bContext *C, wmOperator *op)
Text *text = CTX_data_edit_text(C);
char *tmp;
tmp = txt_sel_to_buf(text);
tmp = txt_sel_to_buf(text, NULL);
BLI_strncpy(st->findstr, tmp, ST_MAX_FIND_STR);
MEM_freeN(tmp);
@@ -3437,7 +3437,7 @@ static int text_replace_set_selected_exec(bContext *C, wmOperator *UNUSED(op))
Text *text = CTX_data_edit_text(C);
char *tmp;
tmp = txt_sel_to_buf(text);
tmp = txt_sel_to_buf(text, NULL);
BLI_strncpy(st->replacestr, tmp, ST_MAX_FIND_STR);
MEM_freeN(tmp);

View File

@@ -457,7 +457,7 @@ static bool python_script_exec(
fn_dummy_py = PyC_UnicodeFromByte(fn_dummy);
buf = txt_to_buf(text);
buf = txt_to_buf(text, NULL);
text->compiled = Py_CompileStringObject(buf, fn_dummy_py, Py_file_input, NULL, -1);
MEM_freeN(buf);