From 34aa9cdb170052977aed3c9671c4e4ea21436636 Mon Sep 17 00:00:00 2001 From: K10-K10 Date: Wed, 3 Dec 2025 21:38:13 +0900 Subject: [PATCH 1/6] =?UTF-8?q?clocale=20=E3=83=A9=E3=82=A4=E3=83=96?= =?UTF-8?q?=E3=83=A9=E3=83=AA=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reference/clocale.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 reference/clocale.md diff --git a/reference/clocale.md b/reference/clocale.md new file mode 100644 index 0000000000..63facbd3fa --- /dev/null +++ b/reference/clocale.md @@ -0,0 +1,35 @@ +# clocale +* clocale[meta header] + +``ヘッダでは、ローカライゼーション(地域化)に関するクラス・関数を定義する。 + +これらの機能は基本的には、`std`名前空間に属することを除いてC言語の標準ライブラリ``ヘッダと同じである。 + +## マクロ + +| 名前 | 説明 | 対応バージョン | +| ------------- | ----------------------------------------- | ------- | +| [`NULL`](/reference/cstddef/null.md) | ヌルポインタ定数に展開されるマクロ | | +| `LC_ALL` | すべてのロケールカテゴリを一括指定するための定数 | | +| `LC_COLLATE` | 文字列の照合(比較)規則に関するロケールカテゴリ | | +| `LC_CTYPE` | 文字分類(大文字/小文字、数字、空白など)やマルチバイト文字の扱いに関するカテゴリ | | +| `LC_MONETARY` | 通貨表記に関するロケールカテゴリ | | +| `LC_NUMERIC` | 数値表記に関するロケールカテゴリ(小数点記号など) | | +| `LC_TIME` | 日付および時刻表記に関するロケールカテゴリ | | + +## 構造体 +| 名前 | 説明 | 対応バージョン | +| ------------- | ----------------------------------------- | ------- | +| `lconv` | 数値・通貨表示の書式設定をまとめた型 | | + +## 関数 +| 名前 | 説明 | 対応バージョン | +| ------------- | ----------------------------------------- | ------- | +| `setlocale` | ロケールを変更、または現在のロケールを取得する。 | | +| `localeconv` | 現在のロケールに応じた数値・通貨表記情報を取得する。 | | + +## 関連項目 +- [`locale`](locale.md) + +## 参照 +[Synopses for the C library](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0175r1.html) From 195f008c45fdaf77c2fd10c18b8b09d2e72c083b Mon Sep 17 00:00:00 2001 From: K10-K10 Date: Wed, 3 Dec 2025 21:42:40 +0900 Subject: [PATCH 2/6] =?UTF-8?q?reference:=20clocale=20=E3=81=B8=E3=81=AE?= =?UTF-8?q?=E3=83=91=E3=82=B9=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference.md b/reference.md index d5a94adb21..b052c1bf97 100644 --- a/reference.md +++ b/reference.md @@ -227,7 +227,7 @@ | `` | 固定精度整数のための書式指定マクロ | C++11 (C99) | | `` | `&&`に対する別名`and`のような、各種演算子に対するマクロを定義する。
ただしC++ではこれらの別名はキーワードとして定義されるため、このヘッダでは何も定義されない。 | C++20で削除 | | [``](/reference/climits.md) | 整数型の最小値、最大値を表すマクロ | | -| `` | ロケール | | +| [``](/reference/clocale.md) | ロケール | | | [``](/reference/cmath.md) | 数学関数 | | | `` | ジャンプ処理 | | | `` | シグナル | | From 4329bd56e985b0e9558c42622956319a3b788a78 Mon Sep 17 00:00:00 2001 From: K10-K10 Date: Wed, 3 Dec 2025 22:38:50 +0900 Subject: [PATCH 3/6] =?UTF-8?q?setlocale:=20=E9=96=A2=E6=95=B0=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reference/clocale/setlocale.md | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 reference/clocale/setlocale.md diff --git a/reference/clocale/setlocale.md b/reference/clocale/setlocale.md new file mode 100644 index 0000000000..e2934913fa --- /dev/null +++ b/reference/clocale/setlocale.md @@ -0,0 +1,56 @@ +# setlocale +* clocale[meta header] +* std[meta namespace] +* function[meta id-type] + +```cpp +namespace std { + char* setlocale(int category, const char* locale); +} +``` + +## 概要 +指定したカテゴリのロケールを設定、または現在のロケールを取得する。 + +指定できるロケール文字列は[以下のページ](/article/platform/locales.md)である。 + +## 引数 +- `category`:設定対象のカテゴリ。`LC_ALL`,`LC_CTYPE`などのマクロを使用。 +- `locale`: + * "C":標準のCロケール + * "":環境依存のデフォルトロケール + * `NULL`:現在のロケールを取得するだけ + +## 戻り値 +成功時は設定されたロケール名(文字列)、失敗時は`NULL`。 + +## 例 +```cpp example +#include +#include + +int main(){ + // 日本語ロケールに設定 + if (!std::setlocale(LC_ALL, "ja_JP.UTF-8")) { + std::cerr << "Failed to set locale\n"; + return 1; + } + + // 現在の全カテゴリのロケールを取得 + std::cout << "Current locale: " << std::setlocale(LC_ALL, NULL) << "\n"; + + // 数値カテゴリだけ確認 + std::cout << "Numeric locale: " << std::setlocale(LC_NUMERIC, NULL) << "\n"; +} + +``` + +### 出力 +``` +Current locale: ja_JP.UTF-8 +Numeric locale: ja_JP.UTF-8 +``` + +## 関連項目 +- [ ロケール文字一覧 ](/article/platform/locales.md) +- [ `std::locale` ](/reference/locale/locale.md) From 3da3fbcb87e30401583bf5ac3e11a6fbfb51f0c1 Mon Sep 17 00:00:00 2001 From: K10-K10 Date: Wed, 3 Dec 2025 22:42:25 +0900 Subject: [PATCH 4/6] =?UTF-8?q?setlocale=E3=81=B8=E3=81=AE=E3=83=91?= =?UTF-8?q?=E3=82=B9=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reference/clocale.md | 2 +- reference/cstdlib/mb_cur_max.md | 2 +- reference/string/stod.md | 2 +- reference/string/stof.md | 2 +- reference/string/stoi.md | 2 +- reference/string/stol.md | 2 +- reference/string/stold.md | 2 +- reference/string/stoll.md | 2 +- reference/string/stoul.md | 2 +- reference/string/stoull.md | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/reference/clocale.md b/reference/clocale.md index 63facbd3fa..32ef1dea4c 100644 --- a/reference/clocale.md +++ b/reference/clocale.md @@ -25,7 +25,7 @@ ## 関数 | 名前 | 説明 | 対応バージョン | | ------------- | ----------------------------------------- | ------- | -| `setlocale` | ロケールを変更、または現在のロケールを取得する。 | | +| [`setlocale`](/reference/clocale/setlocale.md) | ロケールを変更、または現在のロケールを取得する。 | | | `localeconv` | 現在のロケールに応じた数値・通貨表記情報を取得する。 | | ## 関連項目 diff --git a/reference/cstdlib/mb_cur_max.md b/reference/cstdlib/mb_cur_max.md index f3bb3fafa4..41738ed23c 100644 --- a/reference/cstdlib/mb_cur_max.md +++ b/reference/cstdlib/mb_cur_max.md @@ -44,7 +44,7 @@ Locale: ja_JP.UTF-8, MB_CUR_MAX: 6 ## 関連項目 - [`MB_LEN_MAX`](/reference/climits/mb_len_max.md): 全ロケールでのマルチバイト文字の最大バイト数 -- `setlocale`: ロケールを変更する +- [`setlocale`](/reference/clocale/setlocale.md): ロケールを変更する ## 参照 - [mb_cur_max(3) - Linux man page](https://linux.die.net/man/3/mb_cur_max) diff --git a/reference/string/stod.md b/reference/string/stod.md index 2d61a8c0cf..da23fcaa7e 100644 --- a/reference/string/stod.md +++ b/reference/string/stod.md @@ -38,7 +38,7 @@ namespace std { - Clang (libc++) 3.3では、この関数の呼び出し前後で`errno`の値は変化しない。 ### グローバルロケールの影響 -この関数は、`setlocale()`関数により挙動が変化する。 +この関数は、[`setlocale()`](/reference/clocale/setlocale.md)関数により挙動が変化する。 - `strtod()`関数での文字列先頭の空白を読み飛ばす処理に、``の`isspace()`関数が使用される。 - 小数点記号は`LC_NUMERIC`で指定されたものが使用される。 diff --git a/reference/string/stof.md b/reference/string/stof.md index 95ab2cb9cb..ff2594f6fd 100644 --- a/reference/string/stof.md +++ b/reference/string/stof.md @@ -38,7 +38,7 @@ namespace std { - Clang (libc++) 3.3では、この関数の呼び出し前後で`errno`の値は変化しない。 ### グローバルロケールの影響 -この関数は、`setlocale()`関数により挙動が変化する。 +この関数は、[`setlocale()`](/reference/clocale/setlocale.md)関数により挙動が変化する。 - `strtof()`関数での文字列先頭の空白を読み飛ばす処理に、``の`isspace()`関数が使用される。 - 小数点記号は`LC_NUMERIC`で指定されたものが使用される。 diff --git a/reference/string/stoi.md b/reference/string/stoi.md index 66b15defd3..fcd6b887f5 100644 --- a/reference/string/stoi.md +++ b/reference/string/stoi.md @@ -43,7 +43,7 @@ namespace std { - Clang (libc++) 3.3では、この関数の呼び出し前後で`errno`の値は変化しない。 ### グローバルロケールの影響 -この関数は、`setlocale()`関数により挙動が変化する。 +この関数は、[`setlocale()`](/reference/clocale/setlocale.md)関数により挙動が変化する。 `strtol()`関数での文字列先頭の空白を読み飛ばす処理に、``の`isspace()`関数が使用されるためである。 diff --git a/reference/string/stol.md b/reference/string/stol.md index 0b9401b257..6b270ba8a4 100644 --- a/reference/string/stol.md +++ b/reference/string/stol.md @@ -43,7 +43,7 @@ namespace std { - Clang (libc++) 3.3では、この関数の呼び出し前後で`errno`の値は変化しない。 ### グローバルロケールの影響 -この関数は、`setlocale()`関数により挙動が変化する。 +この関数は、[`setlocale()`](/reference/clocale/setlocale.md)関数により挙動が変化する。 `strtol()`関数での文字列先頭の空白を読み飛ばす処理に、``の`isspace()`関数が使用されるためである。 diff --git a/reference/string/stold.md b/reference/string/stold.md index 8481acdddc..aa4260c42e 100644 --- a/reference/string/stold.md +++ b/reference/string/stold.md @@ -38,7 +38,7 @@ namespace std { - Clang (libc++) 3.3では、この関数の呼び出し前後で`errno`の値は変化しない。 ### グローバルロケールの影響 -この関数は、`setlocale()`関数により挙動が変化する。 +この関数は、[`setlocale()`](/reference/clocale/setlocale.md)関数により挙動が変化する。 - `strtold()`関数での文字列先頭の空白を読み飛ばす処理に、``の`isspace()`関数が使用される。 - 小数点記号は`LC_NUMERIC`で指定されたものが使用される。 diff --git a/reference/string/stoll.md b/reference/string/stoll.md index e310cb6019..e606ca6100 100644 --- a/reference/string/stoll.md +++ b/reference/string/stoll.md @@ -48,7 +48,7 @@ namespace std { - Clang (libc++) 3.3では、この関数の呼び出し前後で`errno`の値は変化しない。 ### グローバルロケールの影響 -この関数は、`setlocale()`関数により挙動が変化する。 +この関数は、[`setlocale()`](/reference/clocale/setlocale.md)関数により挙動が変化する。 `strtoll()`関数での文字列先頭の空白を読み飛ばす処理に、``の`isspace()`関数が使用されるためである。 diff --git a/reference/string/stoul.md b/reference/string/stoul.md index 6c156599c3..32c29da686 100644 --- a/reference/string/stoul.md +++ b/reference/string/stoul.md @@ -48,7 +48,7 @@ namespace std { - Clang (libc++) 3.3では、この関数の呼び出し前後で`errno`の値は変化しない。 ### グローバルロケールの影響 -この関数は、`setlocale()`関数により挙動が変化する。 +この関数は、[`setlocale()`](/reference/clocale/setlocale.md)関数により挙動が変化する。 `strtoul()`関数での文字列先頭の空白を読み飛ばす処理に、``の`isspace()`関数が使用されるためである。 diff --git a/reference/string/stoull.md b/reference/string/stoull.md index 4396231668..b41860e0d5 100644 --- a/reference/string/stoull.md +++ b/reference/string/stoull.md @@ -48,7 +48,7 @@ namespace std { - Clang (libc++) 3.3では、この関数の呼び出し前後で`errno`の値は変化しない。 ### グローバルロケールの影響 -この関数は、`setlocale()`関数により挙動が変化する。 +この関数は、[`setlocale()`](/reference/clocale/setlocale.md)関数により挙動が変化する。 `strtoull()`関数での文字列先頭の空白を読み飛ばす処理に、``の`isspace()`関数が使用されるためである。 From 1cf31acb644fd3585d103572247dc2f8bbb36ef9 Mon Sep 17 00:00:00 2001 From: K10-K10 Date: Thu, 4 Dec 2025 00:13:16 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=E6=8C=87=E6=91=98=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=81=9F=E7=82=B9=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reference/clocale/setlocale.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/reference/clocale/setlocale.md b/reference/clocale/setlocale.md index e2934913fa..2fe7636c15 100644 --- a/reference/clocale/setlocale.md +++ b/reference/clocale/setlocale.md @@ -5,31 +5,35 @@ ```cpp namespace std { - char* setlocale(int category, const char* locale); + char* setlocale(int category, const char* locale); } ``` ## 概要 指定したカテゴリのロケールを設定、または現在のロケールを取得する。 -指定できるロケール文字列は[以下のページ](/article/platform/locales.md)である。 +指定できる処理系定義のロケール文字列は[使用できるロケール文字列](/article/platform/locales.md)を参照のこと。 ## 引数 - `category`:設定対象のカテゴリ。`LC_ALL`,`LC_CTYPE`などのマクロを使用。 - `locale`: - * "C":標準のCロケール - * "":環境依存のデフォルトロケール + * `"C"`:標準のCロケール + * `""`:環境依存のデフォルトロケール * `NULL`:現在のロケールを取得するだけ ## 戻り値 成功時は設定されたロケール名(文字列)、失敗時は`NULL`。 +返された文字列をプログラムで変更してはならない。 + +`setlocale()` を呼び出したスレッドが終了した後、もしくは更に次の `setlocale()` の呼び出しの後に返された文字列を使った時の動作は未定義である。 + ## 例 ```cpp example #include #include -int main(){ +int main() { // 日本語ロケールに設定 if (!std::setlocale(LC_ALL, "ja_JP.UTF-8")) { std::cerr << "Failed to set locale\n"; @@ -52,5 +56,5 @@ Numeric locale: ja_JP.UTF-8 ``` ## 関連項目 -- [ ロケール文字一覧 ](/article/platform/locales.md) +- [ ロケール文字列一覧 ](/article/platform/locales.md) - [ `std::locale` ](/reference/locale/locale.md) From cef2a2cc234b9556b2645a3688ea1ed78812bac6 Mon Sep 17 00:00:00 2001 From: K10-K10 Date: Wed, 3 Dec 2025 16:11:56 +0000 Subject: [PATCH 6/6] Update setlocale.md --- reference/clocale/setlocale.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/reference/clocale/setlocale.md b/reference/clocale/setlocale.md index 2fe7636c15..724ec4420c 100644 --- a/reference/clocale/setlocale.md +++ b/reference/clocale/setlocale.md @@ -14,12 +14,17 @@ namespace std { 指定できる処理系定義のロケール文字列は[使用できるロケール文字列](/article/platform/locales.md)を参照のこと。 +この関数の呼び出しは他スレッドにおける `setlocale()` または現在のロケールを使用する他の関数の呼び出しとデータ競合の可能性がある。 + +プログラム開始時の現在のロケールは `std::setlocale(LC_ALL, "C");` が呼び出されたのと同じ状態に初期化される。 + ## 引数 - `category`:設定対象のカテゴリ。`LC_ALL`,`LC_CTYPE`などのマクロを使用。 - `locale`: * `"C"`:標準のCロケール * `""`:環境依存のデフォルトロケール * `NULL`:現在のロケールを取得するだけ + * 処置系定義の文字列 ## 戻り値 成功時は設定されたロケール名(文字列)、失敗時は`NULL`。