std::time_get<CharT,InputIt>::get_monthname, std::time_get<CharT,InputIt>::do_get_monthname
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <locale> で定義
|
||
public: iter_type get_monthname( iter_type beg, iter_type end, std::ios_base& str, std::ios_base::iostate& err, std::tm* t) const; |
(1) | |
protected: virtual iter_type do_get_monthname( iter_type beg, iter_type end, std::ios_base& str, std::ios_base::iostate& err, std::tm* t) const; |
(2) | |
1) public メンバ関数。 最も派生したクラスの protected virtual メンバ関数
do_get_monthname を呼びます。2) シーケンス
[beg, end) から連続する文字を読み込み、このロケールによって期待される月の名前のデフォルトの書式を用いて、 (省略形かもしれない) 月の名前を解析します。 デフォルトの書式は関数 std::get_time、 time_get::get および POSIX の関数 strptime() によって使用される "%b" と同じ書式です。省略形の名前が見つかり、その後に完全な名前として有効な文字が続く場合は、完全な名前の文字をすべて消費するか、期待と異なる文字が見つかるまで、読み込みを継続します。 期待と異なる文字が見つかった場合は、たとえ最初の何文字かが有効な省略形であったとしても、解析は失敗します。
解析した月は std::tm のフィールド t->tm_mon に格納されます。
有効な月の名前を読み込む前に終端イテレータに達した場合、この関数は err に std::ios_base::eofbit をセットします。 解析エラーに遭遇した場合、この関数は err に std::ios_base::failbit をセットします。
引数
| beg | - | 解析するシーケンスの開始を指定するイテレータ |
| end | - | 解析するシーケンスの終端イテレータ |
| str | - | 必要なときにロケールのファセットを取得するためにこの関数が使用するストリームオブジェクト (例えばホワイトスペースをスキップするための std::ctype や文字列を比較するための std::collate) |
| err | - | エラーを示すためにこの関数によって変更されるストリームエラーフラグオブジェクト |
| t | - | この関数呼び出しの結果を保持する std::tm オブジェクトへのポインタ |
戻り値
有効な月の名前の一部として認識された [beg, end) 内の最後の文字の次を指すイテレータ。
ノート
この関数は通常、大文字小文字を区別しません。
解析エラーに遭遇した場合、この関数のほとんどの実装は *t を変更しません。
例
Run this code
#include <iostream>
#include <locale>
#include <sstream>
#include <iterator>
#include <ctime>
void try_get_mon(const std::string& s)
{
std::cout << "Parsing the month out of '" << s <<
"' in the locale " << std::locale().name() << '\n';
std::istringstream str(s);
std::ios_base::iostate err = std::ios_base::goodbit;
std::tm t;
std::istreambuf_iterator<char> ret =
std::use_facet<std::time_get<char>>(str.getloc()).get_monthname(
{str}, {}, str, err, &t
);
str.setstate(err);
std::istreambuf_iterator<char> last{};
if(str) {
std::cout << "Successfully parsed, month number is " << t.tm_mon;
if(ret != last) {
std::cout << ". Remaining content: ";
std::copy(ret, last, std::ostreambuf_iterator<char>(std::cout));
} else {
std::cout << ". The input was fully consumed";
}
} else {
std::cout << "Parse failed. Unparsed string: ";
std::copy(ret, last, std::ostreambuf_iterator<char>(std::cout));
}
std::cout << '\n';
}
int main()
{
std::locale::global(std::locale("ja_JP.utf8"));
try_get_mon("2月");
std::locale::global(std::locale("th_TH.utf8"));
try_get_mon("กุมภาพันธ์");
std::locale::global(std::locale("el_GR.utf8"));
try_get_mon("Φεβ");
try_get_mon("Φεβρουάριος");
std::locale::global(std::locale("en_US.utf8"));
try_get_mon("Febrile");
}
出力:
Parsing the month out of '2月' in the locale ja_JP.utf8
Successfully parsed, month number is 1. The input was fully consumed
Parsing the month out of 'กุมภาพันธ์' in the locale th_TH.utf8
Successfully parsed, month number is 1. The input was fully consumed
Parsing the month out of 'Φεβ' in the locale el_GR.utf8
Successfully parsed, month number is 1. The input was fully consumed
Parsing the month out of 'Φεβρουάριος' in the locale el_GR.utf8
Successfully parsed, month number is 1. The input was fully consumed
Parsing the month out of 'Febrile' in the locale en_US.utf8
Parse failed. Unparsed string: ile
関連項目
(C++11) |
指定された書式の日付/時刻の値をパースします (関数テンプレート) |