/* OB_DUPLIVERTS - FONT */ static Object *find_family_object(const char *family, size_t family_len, unsigned int ch, GHash *family_gh) { Object **ob_pt; Object *ob; void *ch_key = SET_UINT_IN_POINTER(ch); if ((ob_pt = (Object **)BLI_ghash_lookup_p(family_gh, ch_key))) { ob = *ob_pt; } else { char ch_utf8[7]; size_t ch_utf8_len; ch_utf8_len = BLI_str_utf8_from_unicode(ch, ch_utf8); ch_utf8[ch_utf8_len] = '\0'; ch_utf8_len += 1; /* compare with null terminator */ for (ob = G.main->object.first; ob; ob = ob->id.next) { if (STREQLEN(ob->id.name + 2 + family_len, ch_utf8, ch_utf8_len)) { if (STREQLEN(ob->id.name + 2, family, family_len)) { break; } } } /* inserted value can be NULL, just to save searches in future */ BLI_ghash_insert(family_gh, ch_key, ob); } return ob; }
static int console_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event) { // if (!RNA_struct_property_is_set(op->ptr, "text")) { /* always set from keymap XXX */ if (!RNA_string_length(op->ptr, "text")) { /* if alt/ctrl/super are pressed pass through except for utf8 character event * (when input method are used for utf8 inputs, the user may assign key event * including alt/ctrl/super like ctrl+m to commit utf8 string. in such case, * the modifiers in the utf8 character event make no sense.) */ if ((event->ctrl || event->oskey) && !event->utf8_buf[0]) { return OPERATOR_PASS_THROUGH; } else { char str[BLI_UTF8_MAX + 1]; size_t len; if (event->utf8_buf[0]) { len = BLI_str_utf8_size_safe(event->utf8_buf); memcpy(str, event->utf8_buf, len); } else { /* in theory, ghost can set value to extended ascii here */ len = BLI_str_utf8_from_unicode(event->ascii, str); } str[len] = '\0'; RNA_string_set(op->ptr, "text", str); } } return console_insert_exec(C, op); }
/* wchar len in utf8 */ size_t BLI_wstrlen_utf8(const wchar_t *src) { size_t len = 0; while (*src) { len += BLI_str_utf8_from_unicode(*src++, NULL); } return len; }
size_t BLI_strncpy_wchar_as_utf8(char *dst, const wchar_t *src, const size_t maxcpy) { size_t len = 0; while (*src && len < maxcpy) { /* XXX can still run over the buffer because utf8 size isn't known :| */ len += BLI_str_utf8_from_unicode(*src++, dst+len); } dst[len]= '\0'; return len; }
void SCA_KeyboardSensor::AddToTargetProp(int keyIndex, int unicode) { if (IsPrintable(keyIndex)) { CValue* tprop = GetParent()->GetProperty(m_targetprop); if (IsDelete(keyIndex)) { /* Make a new property. Deletes can be ignored. */ if (tprop) { /* overwrite the old property */ /* strip one char, if possible */ STR_String newprop = tprop->GetText(); int oldlength = newprop.Length(); if (oldlength >= 1 ) { int newlength=oldlength; BLI_str_cursor_step_prev_utf8(newprop, newprop.Length(), &newlength); newprop.SetLength(newlength); CStringValue * newstringprop = new CStringValue(newprop, m_targetprop); GetParent()->SetProperty(m_targetprop, newstringprop); newstringprop->Release(); } } } else { char utf8_buf[7]; size_t utf8_len; utf8_len = BLI_str_utf8_from_unicode(unicode, utf8_buf); utf8_buf[utf8_len] = '\0'; STR_String newprop = tprop ? (tprop->GetText() + utf8_buf) : utf8_buf; CStringValue * newstringprop = new CStringValue(newprop, m_targetprop); GetParent()->SetProperty(m_targetprop, newstringprop); newstringprop->Release(); } } }