[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44706] trunk/blender/source/blender: Unify string stepping delimiter code for text buttons, text editor and console (all had duplicate code).
Campbell Barton
ideasman42 at gmail.com
Wed Mar 7 16:55:15 CET 2012
Revision: 44706
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44706
Author: campbellbarton
Date: 2012-03-07 15:55:12 +0000 (Wed, 07 Mar 2012)
Log Message:
-----------
Unify string stepping delimiter code for text buttons, text editor and console (all had duplicate code).
this is also a step toward the console working with utf8 though many todo's remain.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/text.c
trunk/blender/source/blender/blenlib/CMakeLists.txt
trunk/blender/source/blender/editors/interface/interface_handlers.c
trunk/blender/source/blender/editors/space_console/console_ops.c
Added Paths:
-----------
trunk/blender/source/blender/blenlib/BLI_string_cursor_utf8.h
trunk/blender/source/blender/blenlib/intern/string_cursor_utf8.c
Modified: trunk/blender/source/blender/blenkernel/intern/text.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/text.c 2012-03-07 15:10:21 UTC (rev 44705)
+++ trunk/blender/source/blender/blenkernel/intern/text.c 2012-03-07 15:55:12 UTC (rev 44706)
@@ -29,7 +29,7 @@
* \ingroup bke
*/
-
+#include <stdlib.h> /* abort */
#include <string.h> /* strstr */
#include <sys/types.h>
#include <sys/stat.h>
@@ -38,7 +38,11 @@
#include "MEM_guardedalloc.h"
-#include "BLI_blenlib.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_string_cursor_utf8.h"
+#include "BLI_string_utf8.h"
+#include "BLI_listbase.h"
#include "BLI_utildefines.h"
#include "DNA_constraint_types.h"
@@ -731,14 +735,6 @@
#endif
}
-/* 0:whitespace, 1:punct, 2:alphanumeric */
-static short txt_char_type(unsigned int ch)
-{
- if (iswspace(ch)) return 0;
- if (iswalpha(ch) || iswdigit(ch)) return 2;
- return 1;
-}
-
/****************************/
/* Cursor utility functions */
/****************************/
@@ -957,33 +953,33 @@
void txt_jump_left(Text *text, short sel)
{
TextLine **linep, *oldl;
- int *charp, oldc, count, i;
+ int *charp, oldc, oldflags, i;
unsigned char oldu;
+ short pos;
if (!text) return;
if(sel) txt_curs_sel(text, &linep, &charp);
else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); }
if (!*linep) return;
+ oldflags = text->flags;
+ text->flags &= ~TXT_TABSTOSPACES;
+
oldl= *linep;
oldc= *charp;
oldu= undoing;
undoing= 1; /* Don't push individual moves to undo stack */
- count= 0;
- for (i=0; i<3; i++) {
- if (count < 2) {
- while (*charp>0) {
- char *sym= BLI_str_prev_char_utf8((*linep)->line + *charp);
- if (txt_char_type(BLI_str_utf8_as_unicode(sym))==i) {
- txt_move_left(text, sel);
- count++;
- } else break;
- }
- }
+ pos = *charp;
+ BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len,
+ &pos, STRCUR_DIR_PREV,
+ STRCUR_JUMP_DELIM);
+ for (i = *charp; i > pos; i--) {
+ txt_move_left(text, sel);
}
- if (count==0) txt_move_left(text, sel);
+ text->flags = oldflags;
+
undoing= oldu;
if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
}
@@ -991,33 +987,33 @@
void txt_jump_right(Text *text, short sel)
{
TextLine **linep, *oldl;
- int *charp, oldc, count, i;
+ int *charp, oldc, oldflags, i;
unsigned char oldu;
+ short pos;
if (!text) return;
if(sel) txt_curs_sel(text, &linep, &charp);
else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); }
if (!*linep) return;
+ oldflags = text->flags;
+ text->flags &= ~TXT_TABSTOSPACES;
+
oldl= *linep;
oldc= *charp;
oldu= undoing;
undoing= 1; /* Don't push individual moves to undo stack */
- count= 0;
- for (i=0; i<3; i++) {
- if (count < 2) {
- while (*charp<(*linep)->len) {
- char *sym= (*linep)->line + *charp;
- if (txt_char_type(BLI_str_utf8_as_unicode(sym))==i) {
- txt_move_right(text, sel);
- count++;
- } else break;
- }
- }
+ pos = *charp;
+ BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len,
+ &pos, STRCUR_DIR_NEXT,
+ STRCUR_JUMP_DELIM);
+ for (i = *charp; i < pos; i++) {
+ txt_move_right(text, sel);
}
- if (count==0) txt_move_right(text, sel);
+ text->flags = oldflags;
+
undoing= oldu;
if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
}
Added: trunk/blender/source/blender/blenlib/BLI_string_cursor_utf8.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_string_cursor_utf8.h (rev 0)
+++ trunk/blender/source/blender/blenlib/BLI_string_cursor_utf8.h 2012-03-07 15:55:12 UTC (rev 44706)
@@ -0,0 +1,62 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2011 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLI_STRING_CURSOR_UTF8_H__
+#define __BLI_STRING_CURSOR_UTF8_H__
+
+/** \file BLI_string_utf8.h
+ * \ingroup bli
+ */
+
+typedef enum strCursorDelimType {
+ STRCUR_DELIM_NONE,
+ STRCUR_DELIM_ALPHA,
+ STRCUR_DELIM_PUNCT,
+ STRCUR_DELIM_BRACE,
+ STRCUR_DELIM_OPERATOR,
+ STRCUR_DELIM_QUOTE,
+ STRCUR_DELIM_WHITESPACE,
+ STRCUR_DELIM_OTHER
+} strCursorDelimType;
+
+typedef enum strCursorJumpType {
+ STRCUR_JUMP_NONE,
+ STRCUR_JUMP_DELIM,
+ STRCUR_JUMP_ALL
+} strCursorJumpType;
+
+typedef enum strCursorJumpDirection {
+ STRCUR_DIR_PREV,
+ STRCUR_DIR_NEXT
+} strCursorJumpDirection;
+
+int BLI_str_cursor_step_next_utf8(const char *str, size_t maxlen, short *pos);
+int BLI_str_cursor_step_prev_utf8(const char *str, size_t maxlen, short *pos);
+
+void BLI_str_cursor_step_utf8(const char *str, size_t maxlen,
+ short *pos, strCursorJumpDirection direction,
+ strCursorJumpType jump);
+
+#endif /* __BLI_STRING_CURSOR_UTF8_H__ */
Property changes on: trunk/blender/source/blender/blenlib/BLI_string_cursor_utf8.h
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/blender/source/blender/blenlib/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/blenlib/CMakeLists.txt 2012-03-07 15:10:21 UTC (rev 44705)
+++ trunk/blender/source/blender/blenlib/CMakeLists.txt 2012-03-07 15:55:12 UTC (rev 44706)
@@ -82,6 +82,7 @@
intern/smallhash.c
intern/storage.c
intern/string.c
+ intern/string_cursor_utf8.c
intern/string_utf8.c
intern/threads.c
intern/time.c
@@ -132,6 +133,7 @@
BLI_rect.h
BLI_scanfill.h
BLI_string.h
+ BLI_string_cursor_utf8.h
BLI_string_utf8.h
BLI_threads.h
BLI_utildefines.h
Added: trunk/blender/source/blender/blenlib/intern/string_cursor_utf8.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/string_cursor_utf8.c (rev 0)
+++ trunk/blender/source/blender/blenlib/intern/string_cursor_utf8.c 2012-03-07 15:55:12 UTC (rev 44706)
@@ -0,0 +1,181 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2011 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Campbell Barton.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+/** \file blender/blenlib/intern/string_cursor_utf8.c
+ * \ingroup bli
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "BLI_utildefines.h"
+#include "BLI_string_utf8.h"
+
+#include "BLI_string_cursor_utf8.h" /* own include */
+
+
+/* return 1 if char ch is special character, otherwise return 0 */
+static strCursorDelimType test_special_char(const char ch)
+{
+ /* TODO - use BLI_str_utf8_as_unicode rather then assuming ascii */
+
+ if ((ch >= 'a' && ch <= 'z') ||
+ (ch >= 'A' && ch <= 'Z') ||
+ (ch == '_') /* not quite correct but allow for python, could become configurable */
+ )
+ {
+ return STRCUR_DELIM_ALPHA;
+ }
+
+ switch (ch) {
+ case ',':
+ case '.':
+ return STRCUR_DELIM_PUNCT;
+
+ case '{':
+ case '}':
+ case '[':
+ case ']':
+ case '(':
+ case ')':
+ return STRCUR_DELIM_BRACE;
+
+ case '+':
+ case '-':
+ case '=':
+ case '~':
+ case '%':
+ case '/':
+ case '<':
+ case '>':
+ case '^':
+ case '*':
+ case '&':
+ return STRCUR_DELIM_OPERATOR;
+
+ case '\'':
+ case '\"': // " - an extra closing one for Aligorith's text editor
+ return STRCUR_DELIM_QUOTE;
+
+ case ' ':
+ return STRCUR_DELIM_WHITESPACE;
+
+ case '\\':
+ case '!':
+ case '@':
+ case '#':
+ case '$':
+ case ':':
+ case ';':
+ case '?':
+ /* case '_': */ /* special case, for python */
+ return STRCUR_DELIM_OTHER;
+
+ default:
+ break;
+ }
+ return STRCUR_DELIM_NONE;
+}
+
+int BLI_str_cursor_step_next_utf8(const char *str, size_t maxlen, short *pos)
+{
+ const char *str_end= str + (maxlen + 1);
+ const char *str_pos= str + (*pos);
+ const char *str_next= BLI_str_find_next_char_utf8(str_pos, str_end);
+ if (str_next) {
+ (*pos) += (str_next - str_pos);
+ if((*pos) > maxlen) (*pos)= maxlen;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+int BLI_str_cursor_step_prev_utf8(const char *str, size_t UNUSED(maxlen), short *pos)
+{
+ if((*pos) > 0) {
+ const char *str_pos= str + (*pos);
+ const char *str_prev= BLI_str_find_prev_char_utf8(str, str_pos);
+ if (str_prev) {
+ (*pos) -= (str_pos - str_prev);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+void BLI_str_cursor_step_utf8(const char *str, size_t maxlen,
+ short *pos, strCursorJumpDirection direction,
+ strCursorJumpType jump)
+{
+ const short pos_prev= *pos;
+
+ if (direction == STRCUR_DIR_NEXT) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list