这篇教程C++ utf8_strlen函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中utf8_strlen函数的典型用法代码示例。如果您正苦于以下问题:C++ utf8_strlen函数的具体用法?C++ utf8_strlen怎么用?C++ utf8_strlen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了utf8_strlen函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: gui_input_delete_end_of_linevoidgui_input_delete_end_of_line (const char *args){ char *start; int size_deleted, length_deleted, pos_start; /* make C compiler happy */ (void) args; if (gui_current_window->buffer->input) { start = utf8_add_offset (gui_current_window->buffer->input_buffer, gui_current_window->buffer->input_buffer_pos); pos_start = start - gui_current_window->buffer->input_buffer; size_deleted = strlen (start); length_deleted = utf8_strlen (start); gui_input_clipboard_copy (start, size_deleted); start[0] = '/0'; gui_current_window->buffer->input_buffer_size = strlen (gui_current_window->buffer->input_buffer); gui_current_window->buffer->input_buffer_length = utf8_strlen (gui_current_window->buffer->input_buffer); gui_input_optimize_size (gui_current_window->buffer); gui_completion_stop (gui_current_window->buffer->completion, 1); gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); }}
开发者ID:matsuu,项目名称:weechat,代码行数:25,
示例2: gui_completion_nickncmpintgui_completion_nickncmp (const char *base_word, const char *nick, int max){ char *base_word2, *nick2; int case_sensitive, return_cmp; case_sensitive = CONFIG_BOOLEAN(config_completion_nick_case_sensitive); if (!CONFIG_STRING(config_completion_nick_ignore_chars) || !CONFIG_STRING(config_completion_nick_ignore_chars)[0] || !base_word[0] || !nick[0] || gui_completion_nick_has_ignored_chars (base_word)) { return (case_sensitive) ? strncmp (base_word, nick, max) : string_strncasecmp (base_word, nick, max); } base_word2 = gui_completion_nick_strdup_ignore_chars (base_word); nick2 = gui_completion_nick_strdup_ignore_chars (nick); return_cmp = (case_sensitive) ? strncmp (base_word2, nick2, utf8_strlen (base_word2)) : string_strncasecmp (base_word2, nick2, utf8_strlen (base_word2)); free (base_word2); free (nick2); return return_cmp;}
开发者ID:weechat,项目名称:weechat,代码行数:30,
示例3: insert_char/** * Insert 'ch' at position 'pos' * * Returns 1 if the line needs to be refreshed, 2 if not * and 0 if nothing was inserted (no room) */static int insert_char(struct current *current, int pos, int ch){ char buf[3]; int n = utf8_getchars(buf, ch); if (has_room(current, n) && pos >= 0 && pos <= current->chars) { int p1, p2; int ret = 1; p1 = utf8_index(current->buf, pos); p2 = p1 + n;#ifdef USE_TERMIOS /* optimise the case where adding a single char to the end and no scrolling is needed */ if (current->pos == pos && current->chars == pos) { if (ch >= ' ' && utf8_strlen(current->prompt, -1) + utf8_strlen(current->buf, current->len) < current->cols - 1) { IGNORE_RC(write(current->fd, buf, n)); ret = 2; } }#endif memmove(current->buf + p2, current->buf + p1, current->len - p1); memcpy(current->buf + p1, buf, n); current->len += n; current->chars++; if (current->pos >= pos) { current->pos++; } return ret; } return 0;}
开发者ID:evanhunter,项目名称:jimtcl,代码行数:39,
示例4: remove_char/** * Removes the char at 'pos'. * * Returns 1 if the line needs to be refreshed, 2 if not * and 0 if nothing was removed */static int remove_char(struct current *current, int pos){ if (pos >= 0 && pos < current->chars) { int p1, p2; int ret = 1; p1 = utf8_index(current->buf, pos); p2 = p1 + utf8_index(current->buf + p1, 1);#ifdef USE_TERMIOS /* optimise remove char in the case of removing the last char */ if (current->pos == pos + 1 && current->pos == current->chars) { if (current->buf[pos] >= ' ' && utf8_strlen(current->prompt, -1) + utf8_strlen(current->buf, current->len) < current->cols - 1) { ret = 2; fd_printf(current->fd, "/b /b"); } }#endif /* Move the null char too */ memmove(current->buf + p1, current->buf + p2, current->len - p2 + 1); current->len -= (p2 - p1); current->chars--; if (current->pos > pos) { current->pos--; } return ret; } return 0;}
开发者ID:evanhunter,项目名称:jimtcl,代码行数:36,
示例5: utf8_strlen_screenintutf8_strlen_screen (const char *string){ int length, num_char; wchar_t *wstring; if (!string) return 0; if (!local_utf8) return utf8_strlen (string); num_char = mbstowcs (NULL, string, 0) + 1; wstring = malloc ((num_char + 1) * sizeof (wstring[0])); if (!wstring) return utf8_strlen (string); if (mbstowcs (wstring, string, num_char) == (size_t)(-1)) { free (wstring); return utf8_strlen (string); } length = wcswidth (wstring, num_char); free (wstring); return length;}
开发者ID:matsuu,项目名称:weechat,代码行数:27,
示例6: gui_completion_list_addvoidgui_completion_list_add (struct t_gui_completion *completion, const char *word, int nick_completion, const char *where){ char buffer[512]; if (!word || !word[0]) return; if (!completion->base_word || !completion->base_word[0] || (nick_completion && (gui_completion_nickncmp (completion->base_word, word, utf8_strlen (completion->base_word)) == 0)) || (!nick_completion && (string_strncasecmp (completion->base_word, word, utf8_strlen (completion->base_word)) == 0))) { if (nick_completion && (completion->base_word_pos == 0)) { snprintf (buffer, sizeof (buffer), "%s%s", word, CONFIG_STRING(config_completion_nick_completer)); weelist_add (completion->completion_list, buffer, where, (nick_completion) ? (void *)1 : (void *)0); } else { weelist_add (completion->completion_list, word, where, (nick_completion) ? (void *)1 : (void *)0); } }}
开发者ID:FauxFaux,项目名称:weechat_old,代码行数:29,
示例7: set_ddram_addressvoid ST7920_Lite_Status_Screen::draw_status_message() { const char *str = ui.status_message; set_ddram_address(DDRAM_LINE_4); begin_data(); #if ENABLED(STATUS_MESSAGE_SCROLLING) uint8_t slen = utf8_strlen(str); if (slen <= LCD_WIDTH) { // String fits the LCD, so just print it write_str(str); for (; slen < LCD_WIDTH; ++slen) write_byte(' '); } else { // String is larger than the available space in screen. // Get a pointer to the next valid UTF8 character const char *stat = str + ui.status_scroll_offset; // Get the string remaining length const uint8_t rlen = utf8_strlen(stat); // If we have enough characters to display if (rlen >= LCD_WIDTH) { // The remaining string fills the screen - Print it write_str(stat, LCD_WIDTH); } else { // The remaining string does not completely fill the screen write_str(stat); // The string leaves space uint8_t chars = LCD_WIDTH - rlen; // Amount of space left in characters write_byte('.'); // Always at 1+ spaces left, draw a dot if (--chars) { // Draw a second dot if there's space write_byte('.'); if (--chars) write_str(str, chars); // Print a second copy of the message } } // Adjust by complete UTF8 characters if (ui.status_scroll_offset < slen) { ui.status_scroll_offset++; while (!START_OF_UTF8_CHAR(str[ui.status_scroll_offset])) ui.status_scroll_offset++; } else ui.status_scroll_offset = 0; } #else uint8_t slen = utf8_strlen(str); write_str(str, LCD_WIDTH); for (; slen < LCD_WIDTH; ++slen) write_byte(' '); #endif}
开发者ID:teemuatlut,项目名称:Marlin,代码行数:59,
示例8: text_buffer_add_text// ----------------------------------------------------------------------------voidtext_buffer_add_text( text_buffer_t * self, vec2 * pen, markup_t * markup, const char * text, size_t length ){ font_manager_t * manager = self->manager; size_t i; const char * prev_character = NULL; if( markup == NULL ) { return; } if( !markup->font ) { markup->font = font_manager_get_from_markup( manager, markup ); if( ! markup->font ) { fprintf( stderr, "Houston, we've got a problem !/n" ); exit( EXIT_FAILURE ); } } if( length == 0 ) { length = utf8_strlen(text); } if( vertex_buffer_size( self->buffer ) == 0 ) { self->origin = *pen; self->line_left = pen->x; self->bounds.left = pen->x; self->bounds.top = pen->y; } else { if (pen->x < self->origin.x) { self->origin.x = pen->x; } if (pen->y != self->last_pen_y) { text_buffer_finish_line(self, pen, false); } } for( i = 0; utf8_strlen( text + i ) && length; i += utf8_surrogate_len( text + i ) ) { text_buffer_add_char( self, pen, markup, text + i, prev_character ); prev_character = text + i; length--; } self->last_pen_y = pen->y;}
开发者ID:gfphoenix,项目名称:freetype-gl,代码行数:57,
示例9: gui_completion_list_addvoidgui_completion_list_add (struct t_gui_completion *completion, const char *word, int nick_completion, const char *where){ struct t_gui_completion_word *completion_word; char buffer[512]; int index; if (!word || !word[0]) return; if (!completion->base_word || !completion->base_word[0] || (nick_completion && (gui_completion_nickncmp (completion->base_word, word, utf8_strlen (completion->base_word)) == 0)) || (!nick_completion && (string_strncasecmp (completion->base_word, word, utf8_strlen (completion->base_word)) == 0))) { completion_word = malloc (sizeof (*completion_word)); if (completion_word) { completion_word->nick_completion = nick_completion; completion_word->count = 0; index = -1; if (strcmp (where, WEECHAT_LIST_POS_BEGINNING) == 0) { completion->list->sorted = 0; index = 0; } else if (strcmp (where, WEECHAT_LIST_POS_END) == 0) { completion->list->sorted = 0; index = -1; } if (nick_completion && (completion->base_word_pos == 0)) { snprintf (buffer, sizeof (buffer), "%s%s", word, CONFIG_STRING(config_completion_nick_completer)); completion_word->word = strdup (buffer); arraylist_insert (completion->list, index, completion_word); completion->add_space = 0; } else { completion_word->word = strdup (word); arraylist_insert (completion->list, index, completion_word); } } }}
开发者ID:weechat,项目名称:weechat,代码行数:52,
示例10: gui_input_history_global_nextvoidgui_input_history_global_next (){ if ((gui_current_window->buffer->input) && (gui_current_window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)) { if (history_global_ptr) { history_global_ptr = history_global_ptr->prev_history; if (history_global_ptr) { gui_current_window->buffer->input_buffer_size = strlen (history_global_ptr->text); gui_current_window->buffer->input_buffer_length = utf8_strlen (history_global_ptr->text); } else { gui_current_window->buffer->input_buffer[0] = '/0'; gui_current_window->buffer->input_buffer_size = 0; gui_current_window->buffer->input_buffer_length = 0; } gui_input_optimize_size (gui_current_window->buffer); gui_current_window->buffer->input_buffer_pos = gui_current_window->buffer->input_buffer_length; gui_current_window->buffer->input_buffer_1st_display = 0; if (history_global_ptr) { strcpy (gui_current_window->buffer->input_buffer, history_global_ptr->text); } gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } }}
开发者ID:matsuu,项目名称:weechat,代码行数:35,
示例11: qstrlenresult_t Regex::test(const char *str, bool &retVal){ int32_t rc = 0; int32_t ovector[RE_SIZE]; int32_t len = (int32_t) qstrlen(str); const char *end = str + len; if (m_bGlobal) { int32_t n = m_nlastIndex; while (n > 0 && utf8_getchar(str, end)) n--; } if (*str) { len = (int32_t) qstrlen(str); rc = pcre_exec(m_re, NULL, str, len, 0, 0, ovector, RE_SIZE); if (rc < 0) { rc = 0; m_nlastIndex = 0; } } if (rc) { retVal = true; if (m_bGlobal) m_nlastIndex += utf8_strlen(str, ovector[2 * rc - 1]); } return 0;}
开发者ID:lzpfmh,项目名称:fibjs,代码行数:35,
示例12: gui_input_history_nextvoidgui_input_history_next (){ if (gui_current_window->buffer->input) { if (gui_current_window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) { if (gui_current_window->buffer->ptr_history) { gui_current_window->buffer->ptr_history = gui_current_window->buffer->ptr_history->prev_history; if (gui_current_window->buffer->ptr_history) { gui_current_window->buffer->input_buffer_size = strlen (gui_current_window->buffer->ptr_history->text); gui_current_window->buffer->input_buffer_length = utf8_strlen (gui_current_window->buffer->ptr_history->text); } else { gui_current_window->buffer->input_buffer[0] = '/0'; gui_current_window->buffer->input_buffer_size = 0; gui_current_window->buffer->input_buffer_length = 0; } gui_input_optimize_size (gui_current_window->buffer); gui_current_window->buffer->input_buffer_pos = gui_current_window->buffer->input_buffer_length; gui_current_window->buffer->input_buffer_1st_display = 0; if (gui_current_window->buffer->ptr_history) { strcpy (gui_current_window->buffer->input_buffer, gui_current_window->buffer->ptr_history->text); } } else { /* add line to history then clear input */ if (gui_current_window->buffer->input_buffer_size > 0) { gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '/0'; gui_history_buffer_add (gui_current_window->buffer, gui_current_window->buffer->input_buffer); gui_history_global_add (gui_current_window->buffer->input_buffer); gui_current_window->buffer->input_buffer[0] = '/0'; gui_current_window->buffer->input_buffer_size = 0; gui_current_window->buffer->input_buffer_length = 0; gui_current_window->buffer->input_buffer_pos = 0; gui_current_window->buffer->input_buffer_1st_display = 0; gui_input_optimize_size (gui_current_window->buffer); } } gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } else { /* search forward in buffer history */ gui_current_window->buffer->text_search = GUI_TEXT_SEARCH_FORWARD; (void) gui_window_search_text (gui_current_window); } }}
开发者ID:matsuu,项目名称:weechat,代码行数:60,
示例13: set_currentstatic void set_current(struct current *current, const char *str){ strncpy(current->buf, str, current->bufmax); current->buf[current->bufmax - 1] = 0; current->len = strlen(current->buf); current->pos = current->chars = utf8_strlen(current->buf, current->len);}
开发者ID:evanhunter,项目名称:jimtcl,代码行数:7,
示例14: acmp_strlen/** * Returns length of given string for parser's encoding */static size_t acmp_strlen(ACMP *parser, const char *str) {#ifdef ACMP_USE_UTF8 return (parser->is_utf8 == 0) ? strlen(str) : utf8_strlen(str);#else return strlen(str);#endif}
开发者ID:AntBean,项目名称:ModSecurity,代码行数:10,
示例15: utf8_strlen_screenintutf8_strlen_screen (const char *string){ int length, num_char; wchar_t *alloc_wstring, *ptr_wstring, wstring[4+2]; if (!string || !string[0]) return 0; if (!local_utf8) return utf8_strlen (string); alloc_wstring = NULL; if (!string[1] || !string[2] || !string[3] || !string[4]) { /* optimization for max 4 chars: no malloc */ num_char = 4 + 1; ptr_wstring = wstring; } else { num_char = mbstowcs (NULL, string, 0) + 1; alloc_wstring = malloc ((num_char + 1) * sizeof (alloc_wstring[0])); if (!alloc_wstring) return utf8_strlen (string); ptr_wstring = alloc_wstring; } if (mbstowcs (ptr_wstring, string, num_char) != (size_t)(-1)) { length = wcswidth (ptr_wstring, num_char); /* * ensure the size is always >= 1, to prevent any display bug * (for example size of UTF-8 char U+26C4 is -1, why? mystery...) */ if (length < 1) length = 1; } else length = utf8_strlen (string); if (alloc_wstring) free (alloc_wstring); return length;}
开发者ID:Ratler,项目名称:weechat,代码行数:47,
示例16: utf8_strcat_utf8_stringvoid utf8_strcat_utf8_string(utf8_string *work, const utf8_string *in){ const int len = utf8_strlen(in); int loop; for(loop=0; loop<len; loop++) add_utf8_to_utf8_string(work, in -> string[loop]);}
开发者ID:Toeger,项目名称:f-irc,代码行数:8,
示例17: linkage_get_word_char_endsize_t linkage_get_word_char_end(const Linkage linkage, WordIdx w){ if (linkage->num_words <= w) return 0; /* bounds-check */ int pos = linkage->wg_path_display[w]->end - linkage->sent->orig_sentence; char *sentchunk = alloca(pos+1); strncpy(sentchunk, linkage->sent->orig_sentence, pos); sentchunk[pos] = '/0'; return utf8_strlen(sentchunk);}
开发者ID:hckiang,项目名称:link-grammar,代码行数:9,
示例18: bufferAppend/* добавить текст в буффер */static voidbufferAppend(char *data, int len, FB2Content *fb) /*, int remove_spaces)*/{ char **buffer; size_t *buffer_size; int *current_index; /*int new_len;*/ if (!data) return; /* добавляем в текущий буффер */ if (fb->current_buffer == DESCRIPTION_BUFFER) { buffer = &(fb->description); buffer_size = &(fb->description_buffer_size); current_index = &(fb->description_current_index); } else if (fb->current_buffer == TEXT_BUFFER) { buffer = &(fb->text); buffer_size = &(fb->text_buffer_size); current_index = &(fb->text_current_index); } else if (fb->current_buffer == BINARY_BUFFER) { buffer = &(fb->binaries[fb->num_binaries]->buffer); buffer_size = &(fb->binaries[fb->num_binaries]->buffer_size); current_index = &(fb->binaries[fb->num_binaries]->current_index); } /* remove spaces *//* if (remove_spaces) { new_len = removeSpaces(data, len); len = new_len; }*/ /* realloc buffer */ if (*current_index+len >= *buffer_size) { while (1) { *buffer_size = *buffer_size*2; *buffer = (char *) realloc(*buffer, *buffer_size); if (*current_index+len < *buffer_size) { break; } } } strncpy((*buffer) + *current_index, data, len); *current_index += len; if (fb->current_buffer == TEXT_BUFFER) { int u_len; u_len = utf8_strlen(data); fb->utf8_current_index += u_len; } return;}
开发者ID:matimatik,项目名称:odin,代码行数:55,
示例19: completeLinestatic int completeLine(struct current *current) { linenoiseCompletions lc = { 0, NULL }; int c = 0; completionCallback(current->buf,&lc,completionUserdata); if (lc.len == 0) { beep(); } else { size_t stop = 0, i = 0; while(!stop) { /* Show completion or original buffer */ if (i < lc.len) { struct current tmp = *current; tmp.buf = lc.cvec[i]; tmp.pos = tmp.len = strlen(tmp.buf); tmp.chars = utf8_strlen(tmp.buf, tmp.len); refreshLine(current->prompt, &tmp); } else { refreshLine(current->prompt, current); } c = fd_read(current); if (c == -1) { break; } switch(c) { case '/t': /* tab */ i = (i+1) % (lc.len+1); if (i == lc.len) beep(); break; case 27: /* escape */ /* Re-show original buffer */ if (i < lc.len) { refreshLine(current->prompt, current); } stop = 1; break; default: /* Update buffer and return */ if (i < lc.len) { set_current(current,lc.cvec[i]); } stop = 1; break; } } } freeCompletions(&lc); return c; /* Return last read character */}
开发者ID:evanhunter,项目名称:jimtcl,代码行数:53,
示例20: op_strlenstatic intop_strlen(int argc, char **argv){ char *opname = *argv++; argc--; if (argc != 1) { dico_log(L_ERR, 0, "%s requires one argument", opname); return 1; } printf("%lu/n", (unsigned long) utf8_strlen(argv[0])); return 0;}
开发者ID:baohaojun,项目名称:dico,代码行数:12,
示例21: SystemintSystem(char *command) /* command is a UTF-8 string */{ STARTUPINFOW sinfo; PROCESS_INFORMATION pinfo; int shell_rval; size_t len; wchar_t *wcmd; memset(&sinfo, 0, sizeof(sinfo)); sinfo.cb = sizeof(sinfo); len = utf8_strlen(command, strlen(command)); wcmd = PL_malloc((len+1)*sizeof(wchar_t)); utf8towcs(wcmd, command); if ( CreateProcessW(NULL, /* module */ wcmd, /* command line */ NULL, /* Security stuff */ NULL, /* Thread security stuff */ FALSE, /* Inherit handles */ CREATE_NO_WINDOW, /* flags */ NULL, /* environment */ NULL, /* CWD */ &sinfo, /* startup info */ &pinfo) ) /* process into */ { BOOL rval; DWORD code; CloseHandle(pinfo.hThread); /* don't need this */ PL_free(wcmd); do { MSG msg; if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) { TranslateMessage(&msg); DispatchMessage(&msg); } else Sleep(50); rval = GetExitCodeProcess(pinfo.hProcess, &code); } while(rval == TRUE && code == STILL_ACTIVE); shell_rval = (rval == TRUE ? code : -1); CloseHandle(pinfo.hProcess); } else { PL_free(wcmd); return shell_rval = -1; } return shell_rval;}
开发者ID:imccoy,项目名称:prechac-droid,代码行数:52,
示例22: text_widthstatic unsigned int text_width(char* str){ if (iconvW == NULL) iconvW = iconv_open("ucs-4be", "utf-8"); if (iconvW == (iconv_t) -1) { return utf8_strlen(str); } else { size_t len = strlen(str); size_t charlen = utf8_strlen(str); unsigned *wmessage; size_t wlen = (len + 1) * sizeof (unsigned); wmessage = (unsigned *) fcitx_malloc0 ((len + 1) * sizeof (unsigned)); char *inp = str; char *outp = (char*) wmessage; iconv(iconvW, &inp, &len, &outp, &wlen); int i = 0; int width = 0; for (i = 0; i < charlen; i ++) { if (is_double_width(wmessage[i])) width += 2; else width += 1; } free(wmessage); return width; }}
开发者ID:lilydjwg,项目名称:fcitx-fbterm,代码行数:36,
示例23: findRstTags/* TODO: parse overlining & underlining as distinct sections. */static void findRstTags (void){ vString *name = vStringNew (); fpos_t filepos; const unsigned char *line; memset(&filepos, 0, sizeof(fpos_t)); memset(kindchars, 0, sizeof kindchars); nestingLevels = nestingLevelsNew(); while ((line = readLineFromInputFile ()) != NULL) { int line_len = strlen((const char*) line); int name_len_bytes = vStringLength(name); int name_len = utf8_strlen(vStringValue(name), name_len_bytes); /* if the name doesn't look like UTF-8, assume one-byte charset */ if (name_len < 0) name_len = name_len_bytes; /* underlines must be the same length or more */ if (line_len >= name_len && name_len > 0 && ispunct(line[0]) && issame((const char*) line)) { char c = line[0]; int kind = get_kind(c); if (kind >= 0) { makeRstTag(name, kind, filepos); continue; } } vStringClear (name); if (!isspace(*line)) { vStringCatS(name, (const char*)line); filepos = getInputFilePosition(); } vStringTerminate(name); } vStringDelete (name); nestingLevelsFree(nestingLevels);}
开发者ID:blackb1rd,项目名称:ctags,代码行数:45,
|