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:
authorJiri Hnidek <jiri.hnidek@tul.cz>2012-10-26 16:58:54 +0400
committerJiri Hnidek <jiri.hnidek@tul.cz>2012-10-26 16:58:54 +0400
commit2821f822c52146e2e6fbcdeb70232ad2fd9a176f (patch)
tree2a0bc903bd8eb02768ecb6b5b2790850c58b3172 /source/blender/blenlib/intern/string_utf8.c
parent608d62f6a6af224d2d2356e886b1a02855857ff6 (diff)
* New string property subtype: PASSWORD
When this new subtypes is used, then string of property is hidden using asterisks, e.g.: mysecretpassword -> **************** This code was reviewed and modified by Brecht. Thanks very much: - https://codereview.appspot.com/6713044/ This new subtype of string property is intended mostly for Add-on developers writing Add-on which communicates with some server (http, sql, ftp, verse, etc.). When this server requires user authentication and user has to type username and password, then current API didn't allow to type 'hidden' password, e.g. when you want to demonstrate this script, then everybody can see this security password. Some examples of Add-on which could use this new subtype: - On-line database of textures - Integration of render farm - Integration of Verse Security Notes: - You can copy paste hiddent string of property from text input using (Ctrl-C, Ctrl-V), but you can do this in other GUI toolkits too (this behavior it is widely used). - Text of string property is stored in plain text, but it is widely used in other GUI toolkits (Qt, Gtk, etc.). Simple examples: - https://dl.dropbox.com/u/369894/draw_op_passwd.py - https://dl.dropbox.com/u/369894/blender-password.png
Diffstat (limited to 'source/blender/blenlib/intern/string_utf8.c')
-rw-r--r--source/blender/blenlib/intern/string_utf8.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c
index ac2334e7d8e..9c7829dbcb6 100644
--- a/source/blender/blenlib/intern/string_utf8.c
+++ b/source/blender/blenlib/intern/string_utf8.c
@@ -231,28 +231,42 @@ size_t BLI_wstrlen_utf8(const wchar_t *src)
return len;
}
-// utf8slen
+/* size of UTF-8 character in bytes */
+size_t BLI_strlen_utf8_char(const char *strc)
+{
+ if ((*strc & 0xe0) == 0xc0) {
+ if ((strc[1] & 0x80) && (strc[1] & 0x40) == 0x00)
+ return 2;
+ }
+ else if ((*strc & 0xf0) == 0xe0) {
+ if ((strc[1] & strc[2] & 0x80) && ((strc[1] | strc[2]) & 0x40) == 0x00)
+ return 3;
+ }
+ else if ((*strc & 0xf8) == 0xf0) {
+ if ((strc[1] & strc[2] & strc[3] & 0x80) && ((strc[1] | strc[2] | strc[3]) & 0x40) == 0x00)
+ return 4;
+ }
+
+ return 1;
+}
+
size_t BLI_strlen_utf8(const char *strc)
{
- int len = 0;
+ int len;
- while (*strc) {
- if ((*strc & 0xe0) == 0xc0) {
- if ((strc[1] & 0x80) && (strc[1] & 0x40) == 0x00)
- strc++;
- }
- else if ((*strc & 0xf0) == 0xe0) {
- if ((strc[1] & strc[2] & 0x80) && ((strc[1] | strc[2]) & 0x40) == 0x00)
- strc += 2;
- }
- else if ((*strc & 0xf8) == 0xf0) {
- if ((strc[1] & strc[2] & strc[3] & 0x80) && ((strc[1] | strc[2] | strc[3]) & 0x40) == 0x00)
- strc += 3;
- }
+ for (len = 0; *strc; len++)
+ strc += BLI_strlen_utf8_char(strc);
- strc++;
- len++;
- }
+ return len;
+}
+
+size_t BLI_strlen_range_utf8(const char *start, const char *end)
+{
+ const char *strc = start;
+ int len;
+
+ for (len = 0; strc < end; len++)
+ strc += BLI_strlen_utf8_char(strc);
return len;
}