1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
.\" t -*- coding: UTF-8 -*-
.\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
.\" and Copyright 2014 Michael Kerrisk <mtk.manpages@gmail.com>
.\"
.\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\" %%%LICENSE_END
.\"
.\" 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.
.\"
.\"*******************************************************************
.\"
.\" Japanese Version Copyright (c) 1999 HANATAKA Shinya
.\" all rights reserved.
.\" Translated Tue Jan 11 00:56:04 JST 2000
.\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\"
.TH MBSTOWCS 3 2014\-03\-18 GNU "Linux Programmer's Manual"
.SH 名前
mbstowcs \- マルチバイト文字列をワイド文字列に変換する
.SH 書式
.nf
\fB#include <stdlib.h>\fP
.sp
\fBsize_t mbstowcs(wchar_t *\fP\fIdest\fP\fB, const char *\fP\fIsrc\fP\fB, size_t \fP\fIn\fP\fB);\fP
.fi
.SH 説明
\fIdest\fP が NULL でなければ \fBmbstowcs\fP() 関数は マルチバイト文字列 \fI*src\fP を \fIdest\fP
から始まるワイド文字列に 変換する。\fIdest\fP には最大で \fIn\fP 文字のワイド文字が 書き込まれる。変換は初期状態で開始され、
以下の三つのいずれかの条件で停止する:
.IP 1. 3
不正なマルチバイト列に遭遇した。この場合には \fI(size_t)\ \-1\fP を返す。
.IP 2.
\fIn\fP 文字の L\(aq\e0\(aq 以外のワイド文字を \fIdest\fP に格納した場合。 この場合は \fI*src\fP
が次に変換されるマルチバイト列を指すようにして、 \fIdest\fP に書き込まれたワイド文字の数を返す。しかしこの指している 場所のシフト状態は失われる。
.IP 3.
マルチバイト文字列が終端のヌルワイド文字 (\(aq\e0\(aq) まで含めて完全に 変換された場合。この場合は終端のヌルワイド文字を除いて
\fIdest\fP に書き込まれた文字数を返す。
.PP
プログラマーは \fIdest\fP に最低でも \fIn\fP ワイド文字を書き込むこ とができる空間があることを保証しなければならない。
.PP
\fIdest\fP が NULL の場合、\fIn\fP は無視され、上記と同様の変換が 行われるが、変換されたワイド文字はメモリーに書き込まれず、変換先の上限
が存在しない。
.PP
上記の 2. の場合を避けるためにプログラマーは \fIn\fP が \fImbstowcs(NULL,src,0)+1\fP 以上であることを保証すべきである。
.SH 返り値
\fBmbstowcs\fP() 関数はワイド文字列に変換完了したワイド文字の数を返す。
終端のヌルワイド文字は含まない。不正なマルチバイト列に遭遇した場合には \fI(size_t)\ \-1\fP を返す。
.SH 準拠
C99.
.SH 注意
\fBmbstowcs\fP() の動作は現在のロケールの \fBLC_CTYPE\fP カテゴリーに依存している。
.PP
\fBmbsrtowcs\fP(3) 関数は同じ機能のより良いインターフェースを提供する。
.SH 例
下記のプログラムは \fBmbstowcs\fP() といくつかのワイド文字分類関数の使用方法を示したものである。実行例は以下のようになる。
.in +4n
.nf
$ ./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
.fi
.in
.SS プログラムのソース
.nf
#include <locale.h>
#include <wchar.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
size_t mbslen; /* Number of multibyte characters in source */
wchar_t *wcs; /* Pointer to converted wide character string */
wchar_t *wp;
if (argc < 3) {
fprintf(stderr, "Usage: %s <locale> <string>\en", 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):\en");
printf(" %zu bytes\en", strlen(argv[2]));
printf(" %zu multibyte characters\en\en", mbslen);
/* Allocate wide character string of the desired size. Add 1
to allow for terminating null wide character (L\(aq\e0\(aq). */
wcs = calloc(mbslen + 1, sizeof(wchar_t));
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)\en",
wcs, mbslen);
/* Now do some inspection of the classes of the characters in
the wide character string */
for (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\en\(aq);
}
exit(EXIT_SUCCESS);
}
.fi
.SH 関連項目
\fBmblen\fP(3), \fBmbsrtowcs\fP(3), \fBmbtowc\fP(3), \fBwctomb\fP(3), \fBwcstombs\fP(3)
.SH この文書について
この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部
である。プロジェクトの説明とバグ報告に関する情報は
http://www.kernel.org/doc/man\-pages/ に書かれている。
|