|
2 | 2 | <feed xmlns="http://www.w3.org/2005/Atom"> |
3 | 3 | <title>cpprefjp - C++日本語リファレンス</title> |
4 | 4 | <link href="https://cpprefjp.github.io" /> |
5 | | - <updated>2025-12-03T02:06:48.634878</updated> |
6 | | - <id>71c1a548-b061-4dd2-ab63-acaae111a361</id> |
| 5 | + <updated>2025-12-03T02:38:54.092558</updated> |
| 6 | + <id>4deec914-f52d-4a68-9c12-86b87ead6827</id> |
7 | 7 |
|
8 | 8 |
|
| 9 | + <entry> |
| 10 | + <title>mblen -- fix(cstdio/mblen): nullptr を指定した時の戻り値を修正</title> |
| 11 | + <link href="https://cpprefjp.github.io/reference/cstdlib/mblen.html"/> |
| 12 | + <id>5be326287421c777a7b0a9a8223950623687d8a9:reference/cstdlib/mblen.md</id> |
| 13 | + <updated>2025-12-03T11:34:02+09:00</updated> |
| 14 | + |
| 15 | + <summary type="html"><pre><code>diff --git a/reference/cstdlib/mblen.md b/reference/cstdlib/mblen.md |
| 16 | +index 92d48d4a7..f099de580 100644 |
| 17 | +--- a/reference/cstdlib/mblen.md |
| 18 | ++++ b/reference/cstdlib/mblen.md |
| 19 | +@@ -25,7 +25,7 @@ namespace std { |
| 20 | + |
| 21 | + ## 戻り値 |
| 22 | + - 正常に動作する場合、文字の占めるバイト数を返す。 |
| 23 | +-- `str`が`nullptr`の時、内部状態を初期化し`0`を返す。 |
| 24 | ++- `str`が`nullptr`の時、内部状態を初期化する。現在のエンコーディングが状態を持つ場合は非ゼロの値を返し、それ以外の場合は`0`を返す。 |
| 25 | + - 無効な文字列、または`n`が不足している場合、`-1`を返す。 |
| 26 | + |
| 27 | + ## 例 |
| 28 | +</code></pre></summary> |
| 29 | + |
| 30 | + <author> |
| 31 | + <name>Koichi Murase</name> |
| 32 | + <email>myoga.murase@gmail.com</email> |
| 33 | + </author> |
| 34 | + </entry> |
| 35 | + |
9 | 36 | <entry> |
10 | 37 | <title>mblen -- fix(cstdlib/mblen): 内部状態と std::mbrlen を言及</title> |
11 | 38 | <link href="https://cpprefjp.github.io/reference/cstdlib/mblen.html"/> |
12 | | - <id>19e6007105abc63f99cc77fa449adfbc06bb4839:reference/cstdlib/mblen.md</id> |
| 39 | + <id>37f204718ff35392356b1e175b13aff1697a6006:reference/cstdlib/mblen.md</id> |
13 | 40 | <updated>2025-12-03T10:48:37+09:00</updated> |
14 | 41 |
|
15 | 42 | <summary type="html"><pre><code>diff --git a/reference/cstdlib/mblen.md b/reference/cstdlib/mblen.md |
16 | | -index 384e04c58..6e5abd47e 100644 |
| 43 | +index 384e04c58..92d48d4a7 100644 |
17 | 44 | --- a/reference/cstdlib/mblen.md |
18 | 45 | +++ b/reference/cstdlib/mblen.md |
19 | | -@@ -18,6 +18,10 @@ namespace std { |
| 46 | +@@ -18,6 +18,11 @@ namespace std { |
20 | 47 |
|
21 | 48 | `n`は解析に使用する最大バイト数を指定する。 |
22 | 49 |
|
23 | 50 | +この関数は `std::mbstate_t` に等価な静的記憶域の内部状態を保持し、前回の `mblen` 関数呼び出しの続きとして処理を行う。 |
24 | 51 | +従って、この関数はスレッドセーフではない。 |
25 | | -+スレッドセーフに処理する場合は、`std::mbstate_t` を受け取る [`std::mbrlen`](../cwchar/mbrlen.md.nolink) (`&lt;cwchar&gt;`) を使い、呼び出し元でデコード状態の記録場所 `std::mbstate_t` を用意する。 |
| 52 | ++スレッドセーフに処理する場合は、`std::mbstate_t` を受け取る [`std::mbrlen`](../cwchar/mbrlen.md.nolink) (`&lt;cwchar&gt;`) を使い、呼び出し元でデコード状態の記録場所 `std::mbstate_t` を用意する必要がある。 |
| 53 | ++新しいコードでは、特に理由がない限り `std::mblen` ではなく `std::mbrlen` を用いるべきである。 |
26 | 54 | + |
27 | 55 | ## 戻り値 |
28 | 56 | - 正常に動作する場合、文字の占めるバイト数を返す。 |
29 | 57 | - `str`が`nullptr`の時、内部状態を初期化し`0`を返す。 |
30 | | -@@ -77,8 +81,15 @@ int main() { |
| 58 | +@@ -77,8 +82,15 @@ int main() { |
31 | 59 | } |
32 | 60 | ``` |
33 | 61 |
|
@@ -148,63 +176,6 @@ index 838ee668b..4cdcd924d 100644 |
148 | 176 | const char* str = &#34;こんにちは世界&#34;; |
149 | 177 | std::cout &lt;&lt; &#34;文字列: &#34; &lt;&lt; str &lt;&lt; &#34;\n&#34;; |
150 | 178 | std::cout &lt;&lt; &#34;文字数: &#34; &lt;&lt; count_chars_mblen(str) &lt;&lt; &#34;\n&#34;; |
151 | | -</code></pre></summary> |
152 | | - |
153 | | - <author> |
154 | | - <name>Akira Takahashi</name> |
155 | | - <email>faithandbrave@gmail.com</email> |
156 | | - </author> |
157 | | - </entry> |
158 | | - |
159 | | - <entry> |
160 | | - <title>mblen -- mblen : インデントを4から2に変更</title> |
161 | | - <link href="https://cpprefjp.github.io/reference/cstdlib/mblen.html"/> |
162 | | - <id>f73e9f6b98d891f84a1ba174e5243e41ed2ac897:reference/cstdlib/mblen.md</id> |
163 | | - <updated>2025-12-03T10:11:02+09:00</updated> |
164 | | - |
165 | | - <summary type="html"><pre><code>diff --git a/reference/cstdlib/mblen.md b/reference/cstdlib/mblen.md |
166 | | -index 3154cca3c..838ee668b 100644 |
167 | | ---- a/reference/cstdlib/mblen.md |
168 | | -+++ b/reference/cstdlib/mblen.md |
169 | | -@@ -51,24 +51,24 @@ int main() { |
170 | | - #include &lt;clocale&gt; |
171 | | - |
172 | | - int count_chars_mblen(const char* s) { |
173 | | -- std::setlocale(LC_ALL, &#34;ja_JP.UTF-8&#34;); |
174 | | -- int count = 0; |
175 | | -- size_t i = 0; |
176 | | -- while (s[i] != &#39;\0&#39;) { |
177 | | -- int len = std::mblen(&amp;s[i], MB_CUR_MAX); |
178 | | -- if (len &lt; 0) { |
179 | | -- len = 1; |
180 | | -- } |
181 | | -- i += len; |
182 | | -- count++; |
183 | | -+ std::setlocale(LC_ALL, &#34;ja_JP.UTF-8&#34;); |
184 | | -+ int count = 0; |
185 | | -+ size_t i = 0; |
186 | | -+ while (s[i] != &#39;\0&#39;) { |
187 | | -+ int len = std::mblen(&amp;s[i], MB_CUR_MAX); |
188 | | -+ if (len &lt; 0) { |
189 | | -+ len = 1; |
190 | | - } |
191 | | -- return count; |
192 | | -+ i += len; |
193 | | -+ count++; |
194 | | -+ } |
195 | | -+ return count; |
196 | | - } |
197 | | - |
198 | | - int main() { |
199 | | -- const char* str = &#34;こんにちは世界&#34;; |
200 | | -- std::cout &lt;&lt; &#34;文字列: &#34; &lt;&lt; str &lt;&lt; &#34;\n&#34;; |
201 | | -- std::cout &lt;&lt; &#34;文字数: &#34; &lt;&lt; count_chars_mblen(str) &lt;&lt; &#34;\n&#34;; |
202 | | -+ const char* str = &#34;こんにちは世界&#34;; |
203 | | -+ std::cout &lt;&lt; &#34;文字列: &#34; &lt;&lt; str &lt;&lt; &#34;\n&#34;; |
204 | | -+ std::cout &lt;&lt; &#34;文字数: &#34; &lt;&lt; count_chars_mblen(str) &lt;&lt; &#34;\n&#34;; |
205 | | - } |
206 | | - ``` |
207 | | - |
208 | 179 | </code></pre></summary> |
209 | 180 |
|
210 | 181 | <author> |
|
0 commit comments