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) | 数学関数 | | | `` | ジャンプ処理 | | | `` | シグナル | | diff --git a/reference/clocale.md b/reference/clocale.md new file mode 100644 index 0000000000..32ef1dea4c --- /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`](/reference/clocale/setlocale.md) | ロケールを変更、または現在のロケールを取得する。 | | +| `localeconv` | 現在のロケールに応じた数値・通貨表記情報を取得する。 | | + +## 関連項目 +- [`locale`](locale.md) + +## 参照 +[Synopses for the C library](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0175r1.html) diff --git a/reference/clocale/setlocale.md b/reference/clocale/setlocale.md new file mode 100644 index 0000000000..724ec4420c --- /dev/null +++ b/reference/clocale/setlocale.md @@ -0,0 +1,65 @@ +# 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)を参照のこと。 + +この関数の呼び出しは他スレッドにおける `setlocale()` または現在のロケールを使用する他の関数の呼び出しとデータ競合の可能性がある。 + +プログラム開始時の現在のロケールは `std::setlocale(LC_ALL, "C");` が呼び出されたのと同じ状態に初期化される。 + +## 引数 +- `category`:設定対象のカテゴリ。`LC_ALL`,`LC_CTYPE`などのマクロを使用。 +- `locale`: + * `"C"`:標準のCロケール + * `""`:環境依存のデフォルトロケール + * `NULL`:現在のロケールを取得するだけ + * 処置系定義の文字列 + +## 戻り値 +成功時は設定されたロケール名(文字列)、失敗時は`NULL`。 + +返された文字列をプログラムで変更してはならない。 + +`setlocale()` を呼び出したスレッドが終了した後、もしくは更に次の `setlocale()` の呼び出しの後に返された文字列を使った時の動作は未定義である。 + +## 例 +```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) 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()`関数が使用されるためである。