std::experimental::filesystem:: u8path
|
定義済みヘッダー
<experimental/filesystem>
|
||
|
template
<
class
Source
>
path u8path ( const Source & source ) ; |
(1) | (filesystem TS) |
|
template
<
class
InputIt
>
path u8path ( InputIt first, InputIt last ) ; |
(2) | (filesystem TS) |
UTF-8エンコードされた
char
シーケンスからパス
p
を構築します。シーケンスは、
std::string
として、またはヌル終端マルチバイト文字列として、あるいは[
first
,
last
) イテレータペアとして供給されます。
-
path::value_typeが char でネイティブエンコーディングが UTF-8 の場合、 path ( source ) または path ( first, last ) によって直接 path を構築します。注記: これは Linux などの Unicode を使用する POSIX システムにおける典型的な状況です。 -
それ以外の場合、
path::value_typeが wchar_t でネイティブエンコーディングが UTF-16(Windows 環境での状況)、またはpath::value_typeが char16_t (ネイティブエンコーディングが UTF-16 保証)、または char32_t (ネイティブエンコーディングが UTF-32 保証)の場合、まず UTF-8 文字シーケンスをpath::string_type型の一時文字列tmpに変換し、その後 path ( tmp ) によって新しい path を構築します。 -
それ以外の場合(非 UTF-8 ナロー文字エンコーディングおよび非 UTF-16 wchar_t の場合)、まず UTF-8 文字シーケンスを
std::
u32string
型の一時的な UTF-32 エンコード文字列
tmpに変換し、その後 path ( tmp ) によって新しい path を構築します(この経路は、非 Unicode のマルチバイトまたはシングルバイトエンコードファイルシステムを使用する POSIX システムで採用されます)。
目次 |
パラメータ
| source | - | UTF-8エンコードされた std::string 、ヌル終端マルチバイト文字列へのポインタ、またはヌル終端マルチバイト文字列を指すchar値型の入力イテレータ |
| first, last | - | UTF-8エンコードされた文字シーケンスを指定する LegacyInputIterator のペア |
| 型要件 | ||
-
InputIt
は
LegacyInputIterator
の要件を満たさなければならない
|
||
-
InputIt
の値型は
char
でなければならない
|
||
戻り値
入力文字列をUTF-8からファイルシステムのネイティブ文字エンコーディングに変換した後に構築されるパス。
例外
基盤となるOS APIエラーが発生した場合 filesystem_error をスローする可能性があり、メモリ確保に失敗した場合は std:: bad_alloc をスローする可能性があります。
注記
ネイティブパス形式が汎用パス形式と異なるシステムでは(WindowsシステムもPOSIXシステムもそのようなOSの例ではありません)、この関数への引数が汎用形式を使用している場合、ネイティブ形式に変換されます。
例
#include <clocale> #include <cstdio> #include <experimental/filesystem> #include <fstream> #include <iostream> namespace fs = std::experimental::filesystem; int main() { std::setlocale(LC_ALL, "en_US.utf8"); std::locale::global(std::locale("en_US.utf8")); fs::path p = fs::u8path(u8"要らない.txt"); // ネイティブ文字列表現はOS APIで使用可能 std::ofstream(p) << "File contents"; // これはoperator string()を使用 if (std::FILE* f = std::fopen(p.c_str(), "r")) { int ch; while ((ch=fgetc(f))!= EOF) putchar(ch); std::fclose(f); } // マルチバイトおよびワイド表現は出力に使用可能 std::cout.imbue(std::locale()); std::cout << "\nFile name in narrow multibyte encoding: " << p.string() << '\n'; std::wcerr.imbue(std::locale()); std::wcerr << "File name in wide encoding: " << p.wstring() << '\n'; fs::remove(p); }
出力例:
File contents File name in narrow multibyte encoding: 要らない.txt File name in wide encoding: 要らない.txt
関連項目
|
パスを表す
(クラス) |