这篇教程C++ wctomb函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中wctomb函数的典型用法代码示例。如果您正苦于以下问题:C++ wctomb函数的具体用法?C++ wctomb怎么用?C++ wctomb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了wctomb函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: downcase_is_in_dictstatic int downcase_is_in_dict(Dictionary dict, char * word){ int i, rc; char low[MB_LEN_MAX]; char save[MB_LEN_MAX]; wchar_t c; int nbl, nbh; if (!is_utf8_upper(word)) return FALSE; nbh = mbtowc (&c, word, 4); c = towlower(c); nbl = wctomb(low, c); if (nbh != nbl) { fprintf(stderr, "Error: can't downcase multi-byte string!/n"); return FALSE; } /* Downcase */ for (i=0; i<nbl; i++) { save[i] = word[i]; word[i] = low[i]; } /* Look it up, then restore old value */ rc = boolean_dictionary_lookup(dict, word); for (i=0; i<nbh; i++) { word[i] = save[i]; } return rc; }
开发者ID:arv100kri,项目名称:linkparser,代码行数:28,
示例2: localeconvbool CInputField::ValidChar(wchar_t *ch){ if (IsTAB(*ch) || !iswprint(*ch)) return false; if ((m_eInputType == INT) || (m_eInputType == FLOAT)) { lconv *lc = localeconv(); if (strchr(lc->decimal_point, ',')) { if (*ch == L'.') *ch = L','; } std::string legal = LegalNrTokens((m_eInputType == FLOAT), m_Text, GetStrPosition()); char mb[MB_CUR_MAX]; int ret = wctomb(mb, *ch); mb[ret] = 0; if (legal.find(mb) == std::string::npos) return false; // Illegal char } return true;}
开发者ID:BackupTheBerlios,项目名称:nixstaller-svn,代码行数:26,
示例3: assert/* c is a multibyte non-control character. We return that multibyte * character. If crep is an invalid multibyte sequence, it will be * replaced with Unicode 0xFFFD (Replacement Character). */char *mbrep(const char *c, char *crep, int *crep_len){ assert(c != NULL && crep != NULL && crep_len != NULL);#ifdef ENABLE_UTF8 if (use_utf8) { wchar_t wc; /* Reject invalid Unicode characters. */ if (mbtowc(&wc, c, MB_CUR_MAX) < 0 || !is_valid_unicode(wc)) { mbtowc_reset(); *crep_len = bad_mbchar_len; strncpy(crep, bad_mbchar, *crep_len); } else { *crep_len = wctomb(crep, wc); if (*crep_len < 0) { wctomb_reset(); *crep_len = 0; } } } else {#endif *crep_len = 1; *crep = *c;#ifdef ENABLE_UTF8 }#endif return crep;}
开发者ID:mahyarap,项目名称:nano,代码行数:34,
示例4: cswitchstatic voidcswitch(char *dst, int *dn, const char *src, int *sn){ int c;#ifdef MB if (mb_cur_max > 1) { nextc(c, src, *sn); if (c & INVBIT) { *dst = *src; *dn = *sn = 1; } else { if (iswupper(c)) c = towlower(c); else if (iswlower(c)) c = towupper(c); if ((*dn = wctomb(dst, c)) > *sn) { *dst = *src; *dn = *sn = 1; } } } else#endif /* MB */ { c = *src & 0377; if (isupper(c)) *dst = tolower(c); else if (islower(c)) *dst = toupper(c); else *dst = c; *dn = *sn = 1; }}
开发者ID:n-t-roff,项目名称:heirloom-ex-vi,代码行数:34,
示例5: while//(None-windows-specific) Convert wchar_* to stringvoid CTextFileBase::ConvertWcharToString(const wchar_t* from, string &to, bool* datalost, char unknownchar){ to = ""; char* temp = new char[MB_CUR_MAX]; while(*from != L'/0') { size_t len = wctomb(temp, *from); //Found end if(len == 0) break; else if(len == (size_t)-1) { //Replace with unknown character to += unknownchar; if(datalost != NULL) *datalost=true; } else { //Copy all characters for(size_t i=0; i<len; i++) to += temp[i]; } from++; } delete [] temp;}
开发者ID:solidusex,项目名称:wirelesscontroller,代码行数:34,
示例6: write_html_escape_charstatic void write_html_escape_char(ang_file *fp, wchar_t c){ switch (c) { case L'<': file_putf(fp, "<"); break; case L'>': file_putf(fp, ">"); break; case L'&': file_putf(fp, "&"); break; default: { char *mbseq = (char*) mem_alloc(sizeof(char)*(MB_CUR_MAX+1)); byte len; len = wctomb(mbseq, c); if (len > MB_CUR_MAX) len = MB_CUR_MAX; mbseq[len] = '/0'; file_putf(fp, "%s", mbseq); mem_free(mbseq); break; } }}
开发者ID:creidieki,项目名称:angband,代码行数:27,
示例7: MultiByteToWideCharCBasicEventListener::EAction CBasicEventListener::OnChar(HWND hWnd, WPARAM wParam){ if (gEnv && gEnv->pInput) { // TODO: This code doesn't belong here, should be integrated into CKeyboard to make OnInputEvent and OnInputEventUI consistent across all devices and when in the editor SInputEvent event; event.modifiers = gEnv->pInput->GetModifiers(); event.deviceId = eDI_Keyboard; event.state = eIS_UI; event.value = 1.0f; event.pSymbol = 0;//m_rawKeyboard->GetSymbol((lParam>>16)&0xff); if (event.pSymbol) event.keyId = event.pSymbol->keyId; wchar_t tmp[2] = { 0 }; MultiByteToWideChar(CP_ACP, 0, (char*)&wParam, 1, tmp, 2); char szKeyName[4] = {0}; if (wctomb(szKeyName, (WCHAR)wParam) != -1) { if (szKeyName[1]==0 && ((unsigned char)szKeyName[0])>=32) { event.inputChar = tmp[0]; event.keyName = szKeyName; gEnv->pInput->PostInputEvent(event); } } } return eA_Default;}
开发者ID:PiratesAhoy,项目名称:HeartsOfOak-Core,代码行数:31,
示例8: wctombstd::ostream & operator<<(std::ostream & o, wchar_t const c){ char buf[MB_LEN_MAX]; int const i = wctomb(buf, c); if(i < 0) o << '?'; else std::copy(buf, buf + i, std::ostreambuf_iterator<char>(o)); return o;}
开发者ID:sweptr,项目名称:geordi,代码行数:8,
示例9: wcrtombsize_t wcrtomb(FAR char *s, wchar_t wc, FAR mbstate_t *ps){ int retval = 0; char buf[10]; if (s == NULL) { retval = wctomb((char *)buf, L'/0'); } else { retval = wctomb(s, wc); } if (retval == -1) { return (size_t)(-1); } else { return (size_t) retval; }}
开发者ID:drashti304,项目名称:TizenRT,代码行数:17,
示例10: walkUTF8String/** * @internal walk the given UTF8 string, looking for non-ASCII characters. * @return 0 if none were found, or, if non-ASCII strings were found, * answer the length of the buffer if it were converted to platform * encoding * * @note this relies on the assumption that wide chars are Unicode. * If not, the platform will need different support for this */static IDATAwalkUTF8String (const U_8 * buf, IDATA nbytes){ const U_8 *end = buf + nbytes; const U_8 *cursor = buf; IDATA newLength = 0; int hasHighChars = 0; /* reset the shift state */ wctomb (NULL, 0); while (cursor < end) { if ((*cursor & 0x80) == 0x80) { char temp[MB_CUR_MAX]; int wcresult; U_16 unicode; U_32 numberU8Consumed = decodeUTF8CharN (cursor, &unicode, end - cursor); if (numberU8Consumed == 0) { /* an illegal encoding was encountered! Don't try to decode the string */ return 0; } cursor += numberU8Consumed; /* calculate the encoded length of this character */ wcresult = wctomb (temp, (wchar_t) unicode); if (wcresult == -1) { /* an un-encodable char was encountered */ newLength += 1; } else { newLength += wcresult; } hasHighChars = 1; } else { newLength += 1; cursor += 1; } } return hasHighChars ? newLength : 0;}
开发者ID:freeVM,项目名称:freeVM,代码行数:54,
示例11: h_mbtowcstatic voidh_mbtowc(const char *locale, const char *illegal, const char *legal){ char buf[64]; size_t stateful, ret; char *str; ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C");#ifdef __NetBSD__ ATF_REQUIRE(setlocale(LC_CTYPE, locale) != NULL);#else if (setlocale(LC_CTYPE, locale) == NULL) { fprintf(stderr, "Locale %s not found./n", locale); return; }#endif ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL); (void)printf("Using locale: %s/n", str); stateful = wctomb(NULL, L'/0'); (void)printf("Locale is state-%sdependent/n", stateful ? "in" : ""); /* initialize internal state */ ret = mbtowc(NULL, NULL, 0); ATF_REQUIRE(stateful ? ret : !ret); (void)strvis(buf, illegal, VIS_WHITE | VIS_OCTAL); (void)printf("Checking illegal sequence: /"%s/"/n", buf); ret = mbtowc(NULL, illegal, strlen(illegal)); (void)printf("mbtowc() returned: %zd/n", ret); ATF_REQUIRE_EQ(ret, (size_t)-1); (void)printf("errno: %s/n", strerror(errno)); ATF_REQUIRE_EQ(errno, EILSEQ); /* if this is stateless encoding, this re-initialization is not required. */ if (stateful) { /* re-initialize internal state */ ret = mbtowc(NULL, NULL, 0); ATF_REQUIRE(stateful ? ret : !ret); } /* valid multibyte sequence case */ (void)strvis(buf, legal, VIS_WHITE | VIS_OCTAL); (void)printf("Checking legal sequence: /"%s/"/n", buf); errno = 0; ret = mbtowc(NULL, legal, strlen(legal)); (void)printf("mbtowc() returned: %zd/n", ret); ATF_REQUIRE(ret != (size_t)-1); (void)printf("errno: %s/n", strerror(errno)); ATF_REQUIRE_EQ(errno, 0); (void)printf("Ok./n");}
开发者ID:2trill2spill,项目名称:freebsd,代码行数:57,
示例12: fputwcwint_t fputwc(wchar_t c, struct FILE *fp){ char ch[5]; wctomb(ch, c); if (fputs(ch, fp) == 0) return c; else return WEOF;}
开发者ID:1tgr,项目名称:mobius,代码行数:9,
示例13: wctobint wctob(wint_t wc){ unsigned char pmb[MB_LEN_MAX]; if (wc == WEOF) { return EOF; } return wctomb((char *)pmb, wc) == 1 ? (int)pmb[0] : EOF;}
开发者ID:drashti304,项目名称:TizenRT,代码行数:10,
示例14: wputcstatic intwputc(int c, FILE *f){ char buf[MB_CUR_MAX]; int i, len = wctomb(buf, c); for(i=0; i<len; i++) putc(buf[i], f); return c;}
开发者ID:CapelliC,项目名称:packages-sgml,代码行数:10,
示例15: get_character_stringstatic const char* get_character_string(int character){ static char result[6 + 1]; int length = wctomb(result, character); if (length == -1) length = 0; result[length] = '/0'; return result;}
开发者ID:ArturSoczek,项目名称:OpenGLInsightsCode,代码行数:11,
示例16: PutWideCharstatic void PutWideChar(wchar_t const wc){ char buf[MB_CUR_MAX+1]; int len; len = wctomb(buf, wc); if (len > 0) { buf[len] = 0; fputs(buf, stdout); }}
开发者ID:hoijui,项目名称:Remind,代码行数:11,
示例17: get_character_stringstatic const char* get_character_string(int codepoint){ // This assumes UTF-8, which is stupid static char result[6 + 1]; int length = wctomb(result, codepoint); if (length == -1) length = 0; result[length] = '/0'; return result;}
开发者ID:ColinGilbert,项目名称:noobEngine,代码行数:12,
示例18: wctombvoid DataProvider::printCharTable() { char mbs[16]; int nBytes; for (auto it = char2int_.begin(); it != char2int_.end(); ++it) { nBytes = wctomb(mbs, it->first); printf("%lc : %x : %d : ", it->first, it->first, it->second); for (int i=0; i<nBytes; i++) { printf("%x ", 0xff & mbs[i]); } printf("/n"); }}
开发者ID:NobodyInAmerica,项目名称:Conditional-character-based-RNN,代码行数:12,
示例19: wctobintwctob (wint_t wc){ char buf[64]; if (!(MB_CUR_MAX <= sizeof (buf))) abort (); if (wctomb (buf, wc) == 1) return (unsigned char) buf[0]; else return EOF;}
开发者ID:Distrotech,项目名称:libprelude,代码行数:12,
示例20: wcs_mb_size/* For some obscure reason, there's no standard function for this (Linux's wctombs does it, but it's not standard) */int wcs_mb_size(const wchar_t *wstr)/* Returns: number of bytes to be allocated for a C string buffer that will successfully hold the result of wcstombs(buffer, wstr, ?), or -1 if wstr cannot be converted*/{ size_t len = 0; char tmp[MB_CUR_MAX]; wctomb(NULL, 0); while (*wstr) { int mblen = wctomb(tmp, *wstr++); if (mblen < 0) return -1; len += mblen; } return len + 1;}
开发者ID:HengeSense,项目名称:nesc,代码行数:23,
示例21: tstostrchar *tstostr(char *to, tchar *from){ tchar *ptc; wchar_t wc; char *pmb; int len; if (to == (char *)NULL) { /* Need to xalloc(). */ int i; int i1; char junk[MB_LEN_MAX]; /* Get sum of byte counts for each char in from. */ i = 0; ptc = from; while (wc = (wchar_t)((*ptc++)&TRIM)) { if ((i1 = wctomb(junk, wc)) <= 0) { i1 = 1; } i += i1; } /* Allocate that much. */ to = (char *)xalloc(i + 1); } ptc = from; pmb = to; while (wc = (wchar_t)((*ptc++)&TRIM)) { if ((len = wctomb(pmb, wc)) <= 0) { *pmb = (unsigned char)wc; len = 1; } pmb += len; } *pmb = (char)0; return (to);}
开发者ID:AlainODea,项目名称:illumos-gate,代码行数:39,
示例22: putchrstatic voidputchr(wchar_t c){ char mb[MB_LEN_MAX]; int i, n; if (mb_cur_max > 1) { n = wctomb(mb, c); for (i = 0; i < n; i++) putchar(mb[i] & 0377); } else putchar(c&0377);}
开发者ID:Sunshine-OS,项目名称:svr4-userland,代码行数:13,
示例23: _Xaw_iswalnumint_Xaw_iswalnum(wchar_t ch){#ifdef HAVE_ISWALNUM return iswalnum(ch);#else unsigned char mb[MB_LEN_MAX]; wctomb((char*)mb, ch); return (isalnum(*mb));#endif}
开发者ID:erdincay,项目名称:vcxsrv-linux2windows,代码行数:13,
示例24: fromXMLStringstd::string fromXMLString(const XMLString& str){ std::string result; result.reserve(str.size()); for (XMLString::const_iterator it = str.begin(); it != str.end(); ++it) { char c; wctomb(&c, *it); result += c; } return result;}
开发者ID:beneon,项目名称:MITK,代码行数:13,
示例25: wctobintwctob (wint_t wc){ char buf[64]; if (!(MB_CUR_MAX <= sizeof (buf))) abort (); /* Handle the case where WEOF is a value that does not fit in a wchar_t. */ if (wc == (wchar_t)wc) if (wctomb (buf, (wchar_t)wc) == 1) return (unsigned char) buf[0]; return EOF;}
开发者ID:Prelude-SIEM,项目名称:libidmef,代码行数:13,
示例26: ARCH_STRING::ARCH_STRING(){ s_mutex = ARCH->newMutex();#if HAVE_LOCALE_H // see if we can convert a Latin-1 character char mb[MB_LEN_MAX]; if (wctomb(mb, 0xe3) == -1) { // can't convert. try another locale so we can convert latin-1. setlocale(LC_CTYPE, "en_US"); }#endif}
开发者ID:axelson,项目名称:synergy-plus-depracated,代码行数:13,
示例27: h_wctombstatic voidh_wctomb(const struct test *t, char tc){ wchar_t wcs[16 + 2]; char buf[128]; char cs[MB_LEN_MAX]; const char *pcs; char *str; mbstate_t st; mbstate_t *stp = NULL; size_t sz, ret, i; ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL); (void)strvis(buf, t->data, VIS_WHITE | VIS_OCTAL); (void)printf("Checking sequence: /"%s/"/n", buf); ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL); (void)printf("Using locale: %s/n", str); if (tc == TC_WCRTOMB_ST) { (void)memset(&st, 0, sizeof(st)); stp = &st; } wcs[t->wclen] = L'X'; /* poison */ pcs = t->data; sz = mbsrtowcs(wcs, &pcs, t->wclen + 2, NULL); ATF_REQUIRE_EQ_MSG(sz, t->wclen, "mbsrtowcs() returned: " "%zu, expected: %zu", sz, t->wclen); ATF_REQUIRE_EQ(wcs[t->wclen], 0); for (i = 0; i < t->wclen + 1; i++) { if (tc == TC_WCTOMB) ret = wctomb(cs, wcs[i]); else ret = wcrtomb(cs, wcs[i], stp); if (ret == t->mblen[i]) continue; (void)printf("At position %zd:/n", i); (void)printf(" expected: %zd/n", t->mblen[i]); (void)printf(" got : %zd/n", ret); atf_tc_fail("Test failed"); /* NOTREACHED */ } (void)printf("Ok./n");}
开发者ID:Hooman3,项目名称:minix,代码行数:51,
示例28: WideToCharMap// Convert and restore mapped inconvertible Unicode characters. // We use it for extended ASCII names in Unix.bool WideToCharMap(const wchar *Src,char *Dest,size_t DestSize,bool &Success){ // String with inconvertible characters mapped to private use Unicode area // must have the mark code somewhere. if (wcschr(Src,(wchar)MappedStringMark)==NULL) return false; Success=true; uint SrcPos=0,DestPos=0; while (DestPos<DestSize-MB_CUR_MAX) { if (Src[SrcPos]==0) { Dest[DestPos]=0; break; } if (uint(Src[SrcPos])==MappedStringMark) { SrcPos++; continue; } // For security reasons do not retore low ASCII codes, so mapping cannot // be used to hide control codes like path separators. if (uint(Src[SrcPos])>=MapAreaStart+0x80 && uint(Src[SrcPos])<MapAreaStart+0x100) Dest[DestPos++]=char(uint(Src[SrcPos++])-MapAreaStart); else { ignore_result( wctomb(NULL,0) ); // Reset shift state. if (wctomb(Dest+DestPos,Src[SrcPos])==-1) Success=false; SrcPos++; ignore_result( mblen(NULL,0) ); // Reset shift state. int Length=mblen(Dest+DestPos,MB_CUR_MAX); DestPos+=Max(Length,1); } } return true;}
开发者ID:BSzili,项目名称:aros-stuff,代码行数:40,
注:本文中的wctomb函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ wcwidth函数代码示例 C++ wcswidth函数代码示例 |