File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -14,13 +14,13 @@ namespace std {
1414
1515先頭以外の文字に関するバイト数は計算されない。
1616
17- この関数は現在のロケールに依存してマルチバイト文字を解釈する 。
17+ この関数は現在のロケールカテゴリー `LC_CTYPE` に依存してマルチバイト文字を解釈する 。
1818
1919`n`は解析に使用する最大バイト数を指定する。
2020
2121## 戻り値
2222- 正常に動作する場合、文字の占めるバイト数を返す。
23- - `str`が`nullptr`の時、内部状態を初期化し `0`を返す。
23+ - `str`が`nullptr`の時、内部状態を初期化する。現在のエンコーディングが状態を持つ場合は非ゼロの値を返し、それ以外の場合は `0`を返す。
2424- 無効な文字列、または`n`が不足している場合、`-1`を返す。
2525
2626## 例
@@ -51,8 +51,11 @@ int main() {
5151#include < clocale>
5252
5353int count_chars_mblen (const char* s) {
54+ // std::mblen 内部の std::mbstate_t を初期化する必要あり
55+ std::mblen(nullptr, 0);
56+
5457 int count = 0;
55- size_t i = 0;
58+ std:: size_t i = 0;
5659 while (s[ i] != '\0') {
5760 int len = std::mblen(&s[ i] , MB_CUR_MAX);
5861 if (len < 0) {
You can’t perform that action at this time.
0 commit comments