/* Calculate the number of characters between begin and end, and return * it. */ size_t get_totsize(const filestruct *begin, const filestruct *end) { size_t totsize = 0; const filestruct *f; /* Go through the lines from begin to end->prev, if we can. */ for (f = begin; f != end && f != NULL; f = f->next) { /* Count the number of characters on this line. */ totsize += mbstrlen(f->data); /* Count the newline if we have one. */ if (f->next != NULL) totsize++; } /* Go through the line at end, if we can. */ if (f != NULL) { /* Count the number of characters on this line. */ totsize += mbstrlen(f->data); /* Count the newline if we have one. */ if (f->next != NULL) totsize++; } return totsize; }
/* This function is equivalent to strcasestr() for multibyte strings. */ char *mbstrcasestr(const char *haystack, const char *needle) { #ifdef ENABLE_UTF8 if (use_utf8) { size_t haystack_len, needle_len; assert(haystack != NULL && needle != NULL); if (*needle == '\0') return (char *)haystack; haystack_len = mbstrlen(haystack); needle_len = mbstrlen(needle); for (; *haystack != '\0' && haystack_len >= needle_len; haystack += move_mbright(haystack, 0), haystack_len--) { if (mbstrncasecmp(haystack, needle, needle_len) == 0) return (char *)haystack; } return NULL; } else #endif return strcasestr(haystack, needle); }
/* This function is equivalent to strcasestr() for multibyte strings, * except in that it scans the string in reverse, starting at rev_start. */ char *mbrevstrcasestr(const char *haystack, const char *needle, const char *rev_start) { #ifdef ENABLE_UTF8 if (use_utf8) { size_t rev_start_len, needle_len; if (*needle == '\0') return (char *)rev_start; needle_len = mbstrlen(needle); if (mbstrlen(haystack) < needle_len) return NULL; rev_start_len = mbstrlen(rev_start); while (TRUE) { if (rev_start_len >= needle_len && mbstrncasecmp(rev_start, needle, needle_len) == 0) return (char *)rev_start; /* If we've reached the head of the haystack, we found nothing. */ if (rev_start == haystack) return NULL; rev_start = haystack + move_mbleft(haystack, rev_start - haystack); rev_start_len++; } } else #endif return revstrcasestr(haystack, needle, rev_start); }
/* Search for a match to one of the two characters in bracket_set. If * reverse is TRUE, search backwards for the leftmost bracket. * Otherwise, search forwards for the rightmost bracket. Return TRUE if * we found a match, and FALSE otherwise. */ bool find_bracket_match(bool reverse, const char *bracket_set) { linestruct *fileptr = openfile->current; const char *rev_start = NULL, *found = NULL; ssize_t current_y_find = openfile->current_y; assert(mbstrlen(bracket_set) == 2); /* rev_start might end up 1 character before the start or after the * end of the line. This won't be a problem because we'll skip over * it below in that case, and rev_start will be properly set when * the search continues on the previous or next line. */ rev_start = reverse ? fileptr->data + (openfile->current_x - 1) : fileptr->data + (openfile->current_x + 1); /* Look for either of the two characters in bracket_set. rev_start * can be 1 character before the start or after the end of the line. * In either case, just act as though no match is found. */ while (TRUE) { found = ((rev_start > fileptr->data && *(rev_start - 1) == '\0') || rev_start < fileptr->data) ? NULL : (reverse ? mbrevstrpbrk(fileptr->data, bracket_set, rev_start) : mbstrpbrk(rev_start, bracket_set)); if (found != NULL) /* We've found a potential match. */ break; if (reverse) { fileptr = fileptr->prev; current_y_find--; } else { fileptr = fileptr->next; current_y_find++; } if (fileptr == NULL) /* We've reached the start or end of the buffer, so get out. */ return FALSE; rev_start = fileptr->data; if (reverse) rev_start += strlen(fileptr->data); } /* We've definitely found something. */ openfile->current = fileptr; openfile->current_x = found - fileptr->data; openfile->placewewant = xplustabs(); openfile->current_y = current_y_find; return TRUE; }
/* This function is equivalent to strcasestr() for multibyte strings, * except in that it scans the string in reverse, starting at * rev_start. */ char *mbrevstrcasestr(const char *haystack, const char *needle, const char *rev_start) { #ifdef ENABLE_UTF8 if (use_utf8) { bool begin_line = FALSE; size_t rev_start_len, needle_len; assert(haystack != NULL && needle != NULL && rev_start != NULL); if (*needle == '\0') return (char *)rev_start; needle_len = mbstrlen(needle); if (mbstrlen(haystack) < needle_len) return NULL; rev_start_len = mbstrlen(rev_start); while (!begin_line) { if (rev_start_len >= needle_len && mbstrncasecmp(rev_start, needle, needle_len) == 0 && mblen(rev_start, MB_CUR_MAX) > 0) return (char *)rev_start; if (rev_start == haystack) begin_line = TRUE; else { rev_start = haystack + move_mbleft(haystack, rev_start - haystack); rev_start_len++; } } return NULL; } else #endif return revstrcasestr(haystack, needle, rev_start); }
int strmax(int val, char** src) { int i = 0, len = 0, max = 0; for (i = 0; i < val; i++) { len = mbstrlen(src[i]); if (max < len) max = len; } return max; }
int strmax(int val, char** src) { int i = 0, len = 0, max = 0; while (i < val) { len = mbstrlen(src[i]); if (max < len) max = len; i++; } return max; }
NMButton::NMButton(const char* text, NEvent* pevent, ...) : NStaticText(NRect(3, 20, getmaxy(stdscr)/2-3/2,getmaxx(stdscr)/2-20/2)) { appendstring(getcolorpair(COLOR_WHITE, COLOR_CYAN)," "); appendstring(getcolorpair(COLOR_WHITE, COLOR_CYAN) | A_BOLD ,text); appendstring(getcolorpair(COLOR_WHITE, COLOR_CYAN)," "); this->pevent = pevent; //размер кнопки resize(1, mbstrlen(text) + 2); //список клавиш на которые реагирует эта кнопка va_list pk; va_start(pk, pevent); int ch = va_arg(pk, int); while ( ch != 0) { keys.push_back((char)ch); ch = va_arg(pk, int); //следующий ключ } va_end(pk); }
/* Search for a match to one of the two characters in bracket_set. If * reverse is TRUE, search backwards for the leftmost bracket. * Otherwise, search forwards for the rightmost bracket. Return TRUE if * we found a match, and FALSE otherwise. */ bool find_statusbar_bracket_match(bool reverse, const char *bracket_set) { const char *rev_start = NULL, *found = NULL; assert(mbstrlen(bracket_set) == 2); /* rev_start might end up 1 character before the start or after the * end of the line. This won't be a problem because we'll skip over * it below in that case. */ rev_start = reverse ? answer + (statusbar_x - 1) : answer + (statusbar_x + 1); while (TRUE) { /* Look for either of the two characters in bracket_set. * rev_start can be 1 character before the start or after the * end of the line. In either case, just act as though no match * is found. */ found = ((rev_start > answer && *(rev_start - 1) == '\0') || rev_start < answer) ? NULL : (reverse ? mbrevstrpbrk(answer, bracket_set, rev_start) : mbstrpbrk(rev_start, bracket_set)); /* We've found a potential match. */ if (found != NULL) break; /* We've reached the start or end of the statusbar text, so * get out. */ return FALSE; } /* We've definitely found something. */ statusbar_x = found - answer; statusbar_pww = statusbar_xplustabs(); return TRUE; }
/* This function is equivalent to strcasestr() for multibyte strings. */ char *mbstrcasestr(const char *haystack, const char *needle) { #ifdef ENABLE_UTF8 if (use_utf8) { size_t needle_len; if (*needle == '\0') return (char *)haystack; needle_len = mbstrlen(needle); while (*haystack != '\0') { if (mbstrncasecmp(haystack, needle, needle_len) == 0) return (char *)haystack; haystack += move_mbright(haystack, 0); } return NULL; } else #endif return (char *) strcasestr(haystack, needle); }
static void CheckCharToWchar16(const char *input) { size_t inputlen = mbstrlen(input); if(input[0] != '\0') MU_ASSERT(inputlen != 0); wchar16_t *allocated = malloc((inputlen + 1) * sizeof(wchar16_t)); MU_ASSERT(allocated != NULL); size_t converted = mbstowc16s(allocated, input, inputlen + 1); MU_ASSERT(converted == inputlen); MU_ASSERT(wc16slen(allocated) == inputlen); free(allocated); allocated = ambstowc16s(input); MU_ASSERT(allocated != NULL); MU_ASSERT(wc16slen(allocated) == inputlen); char *convertedback = awc16stombs(allocated); MU_ASSERT(convertedback != NULL); MU_ASSERT(!strcmp(input, convertedback)); free(convertedback); free(allocated); }
/* Step through each replace word and prompt user before replacing. * Parameters real_current and real_current_x are needed in order to * allow the cursor position to be updated when a word before the cursor * is replaced by a shorter word. * * needle is the string to seek. We replace it with answer. Return -1 * if needle isn't found, else the number of replacements performed. If * canceled isn't NULL, set it to TRUE if we canceled. */ ssize_t do_replace_loop( #ifndef DISABLE_SPELLER bool whole_word_only, #endif bool *canceled, const linestruct *real_current, size_t *real_current_x, const char *needle) { ssize_t numreplaced = -1; size_t match_len; bool replaceall = FALSE; #ifndef NANO_TINY bool old_mark_set = openfile->mark_set; linestruct *top, *bot; size_t top_x, bot_x; bool right_side_up = FALSE; /* TRUE if (mark_begin, mark_begin_x) is the top of the mark, * FALSE if (current, current_x) is. */ if (old_mark_set) { /* If the mark is on, frame the region, and turn the mark off. */ mark_order((const linestruct **)&top, &top_x, (const linestruct **)&bot, &bot_x, &right_side_up); openfile->mark_set = FALSE; /* Start either at the top or the bottom of the marked region. */ if (!ISSET(BACKWARDS_SEARCH)) { openfile->current = top; openfile->current_x = (top_x == 0 ? 0 : top_x - 1); } else { openfile->current = bot; openfile->current_x = bot_x; } } #endif /* !NANO_TINY */ if (canceled != NULL) *canceled = FALSE; findnextstr_wrap_reset(); while (findnextstr( #ifndef DISABLE_SPELLER whole_word_only, #endif real_current, *real_current_x, needle, &match_len)) { int i = 0; #ifndef NANO_TINY if (old_mark_set) { /* When we've found an occurrence outside of the marked region, * stop the fanfare. */ if (openfile->current->lineno > bot->lineno || openfile->current->lineno < top->lineno || (openfile->current == bot && openfile->current_x > bot_x) || (openfile->current == top && openfile->current_x < top_x)) break; } #endif /* Indicate that we found the search string. */ if (numreplaced == -1) numreplaced = 0; if (!replaceall) { size_t xpt = xplustabs(); char *exp_word = display_string(openfile->current->data, xpt, strnlenpt(openfile->current->data, openfile->current_x + match_len) - xpt, FALSE); edit_refresh(); curs_set(0); do_replace_highlight(TRUE, exp_word); /* TRANSLATORS: This is a prompt. */ i = do_yesno_prompt(TRUE, _("Replace this instance?")); do_replace_highlight(FALSE, exp_word); free(exp_word); curs_set(1); if (i == -1) { /* We canceled the replace. */ if (canceled != NULL) *canceled = TRUE; break; } } if (i > 0 || replaceall) { /* Yes, replace it!!!! */ char *copy; size_t length_change; #ifndef NANO_TINY add_undo(REPLACE); #endif if (i == 2) replaceall = TRUE; copy = replace_line(needle); length_change = strlen(copy) - strlen(openfile->current->data); #ifndef NANO_TINY /* If the mark was on and (mark_begin, mark_begin_x) was the * top of it, don't change mark_begin_x. */ if (!old_mark_set || !right_side_up) { /* Keep mark_begin_x in sync with the text changes. */ if (openfile->current == openfile->mark_begin && openfile->mark_begin_x > openfile->current_x) { if (openfile->mark_begin_x < openfile->current_x + match_len) openfile->mark_begin_x = openfile->current_x; else openfile->mark_begin_x += length_change; bot_x = openfile->mark_begin_x; } } /* If the mark was on and (current, current_x) was the top * of it, don't change real_current_x. */ if (!old_mark_set || right_side_up) { #endif /* Keep real_current_x in sync with the text changes. */ if (openfile->current == real_current && openfile->current_x <= *real_current_x) { if (*real_current_x < openfile->current_x + match_len) *real_current_x = openfile->current_x + match_len; *real_current_x += length_change; #ifndef NANO_TINY bot_x = *real_current_x; } #endif } /* Set the cursor at the last character of the replacement * text, so searching will resume after the replacement * text. Note that current_x might be set to (size_t)-1 * here. */ #ifndef NANO_TINY if (!ISSET(BACKWARDS_SEARCH)) #endif openfile->current_x += match_len + length_change - 1; /* Clean up. */ openfile->totsize += mbstrlen(copy) - mbstrlen(openfile->current->data); free(openfile->current->data); openfile->current->data = copy; #ifndef DISABLE_COLOR /* Reset the precalculated multiline-regex hints only when * the first replacement has been made. */ if (numreplaced == 0) reset_multis(openfile->current, TRUE); #endif if (!replaceall) { #ifndef DISABLE_COLOR /* If color syntaxes are available and turned on, we * need to call edit_refresh(). */ if (openfile->colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX)) edit_refresh(); else #endif update_line(openfile->current, openfile->current_x); } set_modified(); numreplaced++; } } if (numreplaced == -1) not_found_msg(needle); #ifndef NANO_TINY if (old_mark_set) openfile->mark_set = TRUE; #endif /* If the NO_NEWLINES flag isn't set, and text has been added to the * magicline, make a new magicline. */ if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0') new_magicline(); return numreplaced; }
/* Search for a match to the bracket at the current cursor position, if * there is one. */ void do_find_bracket(void) { linestruct *current_save; size_t current_x_save, pww_save; const char *ch; /* The location in matchbrackets of the bracket at the current * cursor position. */ int ch_len; /* The length of ch in bytes. */ const char *wanted_ch; /* The location in matchbrackets of the bracket complementing * the bracket at the current cursor position. */ int wanted_ch_len; /* The length of wanted_ch in bytes. */ char *bracket_set; /* The pair of characters in ch and wanted_ch. */ size_t i; /* Generic loop variable. */ size_t matchhalf; /* The number of single-byte characters in one half of * matchbrackets. */ size_t mbmatchhalf; /* The number of multibyte characters in one half of * matchbrackets. */ size_t count = 1; /* The initial bracket count. */ bool reverse; /* The direction we search. */ char *found_ch; /* The character we find. */ assert(mbstrlen(matchbrackets) % 2 == 0); ch = openfile->current->data + openfile->current_x; if (ch == '\0' || (ch = mbstrchr(matchbrackets, ch)) == NULL) { statusbar(_("Not a bracket")); return; } /* Save where we are. */ current_save = openfile->current; current_x_save = openfile->current_x; pww_save = openfile->placewewant; /* If we're on an opening bracket, which must be in the first half * of matchbrackets, we want to search forwards for a closing * bracket. If we're on a closing bracket, which must be in the * second half of matchbrackets, we want to search backwards for an * opening bracket. */ matchhalf = 0; mbmatchhalf = mbstrlen(matchbrackets) / 2; for (i = 0; i < mbmatchhalf; i++) matchhalf += parse_mbchar(matchbrackets + matchhalf, NULL, NULL); reverse = ((ch - matchbrackets) >= matchhalf); /* If we're on an opening bracket, set wanted_ch to the character * that's matchhalf characters after ch. If we're on a closing * bracket, set wanted_ch to the character that's matchhalf * characters before ch. */ wanted_ch = ch; while (mbmatchhalf > 0) { if (reverse) wanted_ch = matchbrackets + move_mbleft(matchbrackets, wanted_ch - matchbrackets); else wanted_ch += move_mbright(wanted_ch, 0); mbmatchhalf--; } ch_len = parse_mbchar(ch, NULL, NULL); wanted_ch_len = parse_mbchar(wanted_ch, NULL, NULL); /* Fill bracket_set in with the values of ch and wanted_ch. */ bracket_set = charalloc((mb_cur_max() * 2) + 1); strncpy(bracket_set, ch, ch_len); strncpy(bracket_set + ch_len, wanted_ch, wanted_ch_len); null_at(&bracket_set, ch_len + wanted_ch_len); found_ch = charalloc(mb_cur_max() + 1); while (TRUE) { if (find_bracket_match(reverse, bracket_set)) { /* If we found an identical bracket, increment count. If we * found a complementary bracket, decrement it. */ parse_mbchar(openfile->current->data + openfile->current_x, found_ch, NULL); count += (strncmp(found_ch, ch, ch_len) == 0) ? 1 : -1; /* If count is zero, we've found a matching bracket. Update * the screen and get out. */ if (count == 0) { edit_redraw(current_save, pww_save); break; } } else { /* We didn't find either an opening or closing bracket. * Indicate this, restore where we were, and get out. */ statusbar(_("No matching bracket")); openfile->current = current_save; openfile->current_x = current_x_save; openfile->placewewant = pww_save; break; } } /* Clean up. */ free(bracket_set); free(found_ch); }
size_t IconvWrapper::SrcStrLen(const char* str) { return mbstrlen(str, fromNulLen); }
int print_string(int msgs, char** msg) { int i = 0, j = 0, len = 0, maxlen = strmax(msgs, msg); /* get max length */ /* * single line */ putchar(' '); while (i <= maxlen) { putchar('_'); i++; } if (msgs == 1) { fprintf(stdout, "\n< %s >\n ", msg[0]); while (maxlen >= 0) { putchar('-'); maxlen--; } putchar('\n'); return 0; } /* * multi line */ i = 0; while (i < msgs) { j = 0; len = mbstrlen(msg[i]); if (i == 0) fprintf(stdout, "\n/ %s", msg[i]); else if (i == (msgs -1)) fprintf(stdout, "\\ %s", msg[i]); else fprintf(stdout, "| %s", msg[i]); while (j < (maxlen - len)) { putchar(' '); j++; } if (i == 0) fprintf(stdout, " \\\n"); else if (i == (msgs - 1)) fprintf(stdout, " /\n "); else fprintf(stdout, " |\n"); i++; } while (maxlen >= 0) { putchar('-'); maxlen--; } putchar('\n'); return 0; }
/* Parse the rcfile, once it has been opened successfully at rcstream, * and close it afterwards. If syntax_only is TRUE, only allow the file * to contain color syntax commands: syntax, color, and icolor. */ void parse_rcfile(FILE *rcstream #ifdef ENABLE_COLOR , bool syntax_only #endif ) { char *buf = NULL; ssize_t len; size_t n; while ((len = getline(&buf, &n, rcstream)) > 0) { char *ptr, *keyword, *option; int set = 0; size_t i; /* Ignore the newline. */ if (buf[len - 1] == '\n') buf[len - 1] = '\0'; lineno++; ptr = buf; while (isblank(*ptr)) ptr++; /* If we have a blank line or a comment, skip to the next * line. */ if (*ptr == '\0' || *ptr == '#') continue; /* Otherwise, skip to the next space. */ keyword = ptr; ptr = parse_next_word(ptr); /* Try to parse the keyword. */ if (strcasecmp(keyword, "set") == 0) { #ifdef ENABLE_COLOR if (syntax_only) rcfile_error( N_("Command \"%s\" not allowed in included file"), keyword); else #endif set = 1; } else if (strcasecmp(keyword, "unset") == 0) { #ifdef ENABLE_COLOR if (syntax_only) rcfile_error( N_("Command \"%s\" not allowed in included file"), keyword); else #endif set = -1; } #ifdef ENABLE_COLOR else if (strcasecmp(keyword, "include") == 0) { if (syntax_only) rcfile_error( N_("Command \"%s\" not allowed in included file"), keyword); else parse_include(ptr); } else if (strcasecmp(keyword, "syntax") == 0) { if (endsyntax != NULL && endcolor == NULL) rcfile_error(N_("Syntax \"%s\" has no color commands"), endsyntax->desc); parse_syntax(ptr); } else if (strcasecmp(keyword, "header") == 0) parse_headers(ptr); else if (strcasecmp(keyword, "color") == 0) parse_colors(ptr, FALSE); else if (strcasecmp(keyword, "icolor") == 0) parse_colors(ptr, TRUE); else if (strcasecmp(keyword, "bind") == 0) parse_keybinding(ptr); #endif /* ENABLE_COLOR */ else rcfile_error(N_("Command \"%s\" not understood"), keyword); if (set == 0) continue; if (*ptr == '\0') { rcfile_error(N_("Missing flag")); continue; } option = ptr; ptr = parse_next_word(ptr); for (i = 0; rcopts[i].name != NULL; i++) { if (strcasecmp(option, rcopts[i].name) == 0) { #ifdef DEBUG fprintf(stderr, "parse_rcfile(): name = \"%s\"\n", rcopts[i].name); #endif if (set == 1) { if (rcopts[i].flag != 0) /* This option has a flag, so it doesn't take an * argument. */ SET(rcopts[i].flag); else { /* This option doesn't have a flag, so it takes * an argument. */ if (*ptr == '\0') { rcfile_error( N_("Option \"%s\" requires an argument"), rcopts[i].name); break; } option = ptr; if (*option == '"') option++; ptr = parse_argument(ptr); option = mallocstrcpy(NULL, option); #ifdef DEBUG fprintf(stderr, "option = \"%s\"\n", option); #endif /* Make sure option is a valid multibyte * string. */ if (!is_valid_mbstring(option)) { rcfile_error( N_("Option is not a valid multibyte string")); break; } #ifndef DISABLE_OPERATINGDIR if (strcasecmp(rcopts[i].name, "operatingdir") == 0) operating_dir = option; else #endif #ifndef DISABLE_WRAPJUSTIFY if (strcasecmp(rcopts[i].name, "fill") == 0) { if (!parse_num(option, &wrap_at)) { rcfile_error( N_("Requested fill size \"%s\" is invalid"), option); wrap_at = -CHARS_FROM_EOL; } else free(option); } else #endif #ifndef NANO_TINY if (strcasecmp(rcopts[i].name, "matchbrackets") == 0) { matchbrackets = option; if (has_blank_mbchars(matchbrackets)) { rcfile_error( N_("Non-blank characters required")); free(matchbrackets); matchbrackets = NULL; } } else if (strcasecmp(rcopts[i].name, "whitespace") == 0) { whitespace = option; if (mbstrlen(whitespace) != 2 || strlenpt(whitespace) != 2) { rcfile_error( N_("Two single-column characters required")); free(whitespace); whitespace = NULL; } else { whitespace_len[0] = parse_mbchar(whitespace, NULL, NULL); whitespace_len[1] = parse_mbchar(whitespace + whitespace_len[0], NULL, NULL); } } else #endif #ifndef DISABLE_JUSTIFY if (strcasecmp(rcopts[i].name, "punct") == 0) { punct = option; if (has_blank_mbchars(punct)) { rcfile_error( N_("Non-blank characters required")); free(punct); punct = NULL; } } else if (strcasecmp(rcopts[i].name, "brackets") == 0) { brackets = option; if (has_blank_mbchars(brackets)) { rcfile_error( N_("Non-blank characters required")); free(brackets); brackets = NULL; } } else if (strcasecmp(rcopts[i].name, "quotestr") == 0) quotestr = option; else #endif #ifndef NANO_TINY if (strcasecmp(rcopts[i].name, "backupdir") == 0) backup_dir = option; else #endif #ifndef DISABLE_SPELLER if (strcasecmp(rcopts[i].name, "speller") == 0) alt_speller = option; else #endif if (strcasecmp(rcopts[i].name, "tabsize") == 0) { if (!parse_num(option, &tabsize) || tabsize <= 0) { rcfile_error( N_("Requested tab size \"%s\" is invalid"), option); tabsize = -1; } else free(option); } else assert(FALSE); } #ifdef DEBUG fprintf(stderr, "flag = %ld\n", rcopts[i].flag); #endif } else if (rcopts[i].flag != 0) UNSET(rcopts[i].flag); else rcfile_error(N_("Cannot unset flag \"%s\""), rcopts[i].name); break; } } if (rcopts[i].name == NULL) rcfile_error(N_("Unknown flag \"%s\""), option); } #ifdef ENABLE_COLOR if (endsyntax != NULL && endcolor == NULL) rcfile_error(N_("Syntax \"%s\" has no color commands"), endsyntax->desc); #endif free(buf); fclose(rcstream); lineno = 0; check_vitals_mapped(); return; }
DWORD RegCopyValueAToW( IN REG_DATA_TYPE dwType, IN PVOID pData, IN DWORD cbData, OUT PVOID* ppOutData, OUT PDWORD pcbOutDataLen ) { DWORD dwError = 0; PVOID pOutData = NULL; DWORD cbOutDataLen = 0; BOOLEAN bIsStrType = FALSE; if (dwType == REG_MULTI_SZ) { if (!pData) { pData = (PBYTE) ""; } if (cbData == 0) { cbData = 1; } } if (pData) { if (REG_MULTI_SZ == dwType) { dwError = RegConvertByteStreamA2W((PBYTE)pData, cbData, (PBYTE*)&pOutData, &cbOutDataLen); BAIL_ON_REG_ERROR(dwError); bIsStrType = TRUE; } else if (REG_SZ == dwType) { /* Verify correct null termination of input data */ if (strlen((char *) pData) != (cbData-1)) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_REG_ERROR(dwError); } dwError = RegWC16StringAllocateFromCString((PWSTR*)&pOutData, pData); BAIL_ON_REG_ERROR(dwError); cbOutDataLen = (mbstrlen((const char*) pData)+1) * sizeof(WCHAR); bIsStrType = TRUE; } } if (!bIsStrType && cbData) { dwError = RegAllocateMemory(cbData, &pOutData); BAIL_ON_REG_ERROR(dwError); if (pData) { memcpy(pOutData, pData, cbData); cbOutDataLen = cbData; } } *ppOutData = pOutData; *pcbOutDataLen = cbOutDataLen; cleanup: return dwError; error: LWREG_SAFE_FREE_MEMORY(pOutData); *ppOutData = NULL; *pcbOutDataLen = 0; goto cleanup; }
size_t IconvWrapper::DstStrLen(const char* str) { return mbstrlen(str, toNulLen); }