.\" -*- coding: UTF-8 -*- '\" t .\" Copyright (c) Bruno Haible .\" and Copyright 2014 Michael Kerrisk .\" .\" SPDX-License-Identifier: GPL-2.0-or-later .\" .\" References consulted: .\" GNU glibc-2 source code and manual .\" Dinkumware C library reference http://www.dinkumware.com/ .\" OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html .\" ISO/IEC 9899:1999 .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH mbstowcs 3 "15 июня 2024 г." "Справочные страницы Linux 6.9.1" .SH НАИМЕНОВАНИЕ mbstowcs \- преобразует многобайтовую строку в строку широких символов .SH БИБЛИОТЕКА Стандартная библиотека языка C (\fIlibc\fP, \fI\-lc\fP) .SH ОБЗОР .nf \fB#include \fP .P \fBsize_t mbstowcs(wchar_t \fP\fIdest\fP\fB[restrict .\fP\fIdsize\fP\fB], const char *restrict \fP\fIsrc\fP\fB,\fP \fB size_t \fP\fIdsize\fP\fB);\fP .fi .SH ОПИСАНИЕ If \fIdest\fP is not NULL, convert the multibyte string \fIsrc\fP to a wide\-character string starting at \fIdest\fP. At most \fIdsize\fP wide characters are written to \fIdest\fP. The sequence of characters in the string \fIsrc\fP shall begin in the initial shift state. The conversion can stop for three reasons: .IP \[bu] 3 Во входных данных находится неправильная многобайтовая последовательность. В этом случае возвращается \fI(size_t)\ \-1\fP. .IP \[bu] \fIdsize\fP non\-L\[aq]\[rs]0\[aq] wide characters have been stored at \fIdest\fP. In this case, the number of wide characters written to \fIdest\fP is returned, but the shift state at this point is lost. .IP \[bu] The multibyte string has been completely converted, including the terminating null character (\[aq]\[rs]0\[aq]). In this case, the number of wide characters written to \fIdest\fP, excluding the terminating null wide character, is returned. .P Если \fIdest\fP равно NULL, \fIdsize\fP игнорируется, и преобразование продолжается, как описано выше, за исключением того, что преобразованные широкие символы не записываются в память, и что ограничений по длине не существует. .P In order to avoid the case 2 above, the programmer should make sure \fIdsize\fP is greater than or equal to \fImbstowcs(NULL,src,0)+1\fP. .P Программист должен убедиться, что в \fIdest\fP есть место для символов шириной не менее \fIdsize\fP. .SH "ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ" The number of wide characters that make up the converted part of the wide\-character string, not including the terminating null wide character. If an invalid multibyte sequence was encountered, \fI(size_t)\ \-1\fP is returned. .SH АТРИБУТЫ Описание терминов данного раздела смотрите в \fBattributes\fP(7). .TS allbox; lbx lb lb l l l. Интерфейс Атрибут Значение T{ .na .nh \fBmbstowcs\fP() T} Безвредность в нитях MT\-Safe .TE .SH ВЕРСИИ Функция \fBmbsrtowcs\fP(3) предоставляет лучший интерфейс с теми же возможностями. .SH СТАНДАРТЫ C11, POSIX.1\-2008. .SH ИСТОРИЯ POSIX.1\-2001, C99. .SH ПРИМЕЧАНИЯ Поведение \fBmbstowcs\fP() зависит от категории \fBLC_CTYPE\fP текущей локали. .SH ПРИМЕРЫ В программе, представленной ниже, показано использование \fBmbstowcs\fP(), а также некоторые функции классификации широких символов. Пример запуска: .P .in +4n .EX $ ./t_mbstowcs de_DE.UTF\-8 Grüße! Length of source string (excluding terminator): 8 bytes 6 multibyte characters \& Wide character string is: Grüße! (6 characters) G alpha upper r alpha lower ü alpha lower ß alpha lower e alpha lower ! !alpha .EE .in .SS "Исходный код программы" .\" SRC BEGIN (mbstowcs.c) \& .EX #include #include #include #include #include #include \& int main(int argc, char *argv[]) { size_t mbslen; /* Number of multibyte characters in source */ wchar_t *wcs; /* Pointer to converted wide character string */ \& if (argc < 3) { fprintf(stderr, "Usage: %s \[rs]n", argv[0]); exit(EXIT_FAILURE); } \& /* Apply the specified locale. */ \& if (setlocale(LC_ALL, argv[1]) == NULL) { perror("setlocale"); exit(EXIT_FAILURE); } \& /* Calculate the length required to hold argv[2] converted to a wide character string. */ \& mbslen = mbstowcs(NULL, argv[2], 0); if (mbslen == (size_t) \-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } \& /* Describe the source string to the user. */ \& printf("Length of source string (excluding terminator):\[rs]n"); printf(" %zu bytes\[rs]n", strlen(argv[2])); printf(" %zu multibyte characters\[rs]n\[rs]n", mbslen); \& /* Allocate wide character string of the desired size. Add 1 to allow for terminating null wide character (L\[aq]\[rs]0\[aq]). */ \& wcs = calloc(mbslen + 1, sizeof(*wcs)); if (wcs == NULL) { perror("calloc"); exit(EXIT_FAILURE); } \& /* Convert the multibyte character string in argv[2] to a wide character string. */ \& if (mbstowcs(wcs, argv[2], mbslen + 1) == (size_t) \-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } \& printf("Wide character string is: %ls (%zu characters)\[rs]n", wcs, mbslen); \& /* Now do some inspection of the classes of the characters in the wide character string. */ \& for (wchar_t *wp = wcs; *wp != 0; wp++) { printf(" %lc ", (wint_t) *wp); \& if (!iswalpha(*wp)) printf("!"); printf("alpha "); \& if (iswalpha(*wp)) { if (iswupper(*wp)) printf("upper "); \& if (iswlower(*wp)) printf("lower "); } \& putchar(\[aq]\[rs]n\[aq]); } \& exit(EXIT_SUCCESS); } .EE .\" SRC END .SH "СМОТРИТЕ ТАКЖЕ" \fBmblen\fP(3), \fBmbsrtowcs\fP(3), \fBmbtowc\fP(3), \fBwcstombs\fP(3), \fBwctomb\fP(3) .PP .SH ПЕРЕВОД Русский перевод этой страницы руководства разработал(и) aereiae , Alexey , Azamat Hackimov , Dmitriy S. Seregin , Dmitry Bolkhovskikh , ITriskTI , Max Is , Yuri Kozlov , Иван Павлов , Малянов Евгений Викторович и Kirill Rekhov . .PP Этот перевод является свободной программной документацией; он распространяется на условиях общедоступной лицензии GNU (GNU General Public License - GPL, .UR https://www.gnu.org/licenses/gpl-3.0.html .UE версии 3 или более поздней) в отношении авторского права, но БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ. .PP Если вы обнаружите какие-либо ошибки в переводе этой страницы руководства, пожалуйста, сообщите об этом разработчику(ам) по его(их) адресу(ам) электронной почты или по адресу .MT списка рассылки русских переводчиков .ME .