Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/text.c')
-rw-r--r--source/blender/blenkernel/intern/text.c95
1 files changed, 88 insertions, 7 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index dac426de4eb..8bf0f6b8bdf 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -130,8 +130,10 @@ undo position
static void txt_pop_first(Text *text);
static void txt_pop_last(Text *text);
static void txt_undo_add_op(Text *text, int op);
-static void txt_undo_add_block(Text *text, int op, char *buf);
+static void txt_undo_add_block(Text *text, int op, const char *buf);
static void txt_delete_line(Text *text, TextLine *line);
+static void txt_delete_sel (Text *text);
+static void txt_make_dirty (Text *text);
/***/
@@ -537,6 +539,30 @@ void unlink_text(Main *bmain, Text *text)
text->id.us= 0;
}
+void clear_text(Text *text) /* called directly from rna */
+{
+ int oldstate;
+
+ oldstate = txt_get_undostate( );
+ txt_set_undostate( 1 );
+ txt_sel_all( text );
+ txt_delete_sel(text);
+ txt_set_undostate( oldstate );
+
+ txt_make_dirty(text);
+}
+
+void write_text(Text *text, char *str) /* called directly from rna */
+{
+ int oldstate;
+
+ oldstate = txt_get_undostate( );
+ txt_insert_buf( text, str );
+ txt_move_eof( text, 0 );
+ txt_set_undostate( oldstate );
+
+ txt_make_dirty(text);
+}
/*****************************/
/* Editing utility functions */
@@ -570,17 +596,15 @@ static TextLine *txt_new_line(char *str)
return tmp;
}
-static TextLine *txt_new_linen(char *str, int n)
+static TextLine *txt_new_linen(const char *str, int n)
{
TextLine *tmp;
- if(!str) str= "";
-
tmp= (TextLine *) MEM_mallocN(sizeof(TextLine), "textline");
tmp->line= MEM_mallocN(n+1, "textline_string");
tmp->format= NULL;
- BLI_strncpy(tmp->line, str, n+1);
+ BLI_strncpy(tmp->line, (str)? str: "", n+1);
tmp->len= strlen(tmp->line);
tmp->next= tmp->prev= NULL;
@@ -1315,7 +1339,7 @@ char *txt_sel_to_buf (Text *text)
return buf;
}
-void txt_insert_buf(Text *text, char *in_buffer)
+void txt_insert_buf(Text *text, const char *in_buffer)
{
int i=0, l=0, j, u, len;
TextLine *add;
@@ -1544,7 +1568,7 @@ static void txt_undo_add_op(Text *text, int op)
text->undo_buf[text->undo_pos+1]= 0;
}
-static void txt_undo_add_block(Text *text, int op, char *buf)
+static void txt_undo_add_block(Text *text, int op, const char *buf)
{
int length;
@@ -2808,3 +2832,60 @@ TextMarker *txt_next_marker(Text *text, TextMarker *marker) {
}
return NULL; /* Only if marker==NULL */
}
+
+
+/*******************************/
+/* Character utility functions */
+/*******************************/
+
+int text_check_bracket(char ch)
+{
+ int a;
+ char opens[] = "([{";
+ char close[] = ")]}";
+
+ for(a=0; a<(sizeof(opens)-1); a++) {
+ if(ch==opens[a])
+ return a+1;
+ else if(ch==close[a])
+ return -(a+1);
+ }
+ return 0;
+}
+
+int text_check_delim(char ch)
+{
+ int a;
+ char delims[] = "():\"\' ~!%^&*-+=[]{};/<>|.#\t,";
+
+ for(a=0; a<(sizeof(delims)-1); a++) {
+ if(ch==delims[a])
+ return 1;
+ }
+ return 0;
+}
+
+int text_check_digit(char ch)
+{
+ if(ch < '0') return 0;
+ if(ch <= '9') return 1;
+ return 0;
+}
+
+int text_check_identifier(char ch)
+{
+ if(ch < '0') return 0;
+ if(ch <= '9') return 1;
+ if(ch < 'A') return 0;
+ if(ch <= 'Z' || ch == '_') return 1;
+ if(ch < 'a') return 0;
+ if(ch <= 'z') return 1;
+ return 0;
+}
+
+int text_check_whitespace(char ch)
+{
+ if(ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n')
+ return 1;
+ return 0;
+}