CARVIEW |
Select Language
HTTP/2 200
server: GitHub.com
content-type: text/x-c
last-modified: Mon, 21 Jul 2025 12:14:30 GMT
access-control-allow-origin: *
etag: "687e2f26-4cc"
expires: Mon, 21 Jul 2025 15:39:47 GMT
cache-control: max-age=600
x-proxy-cache: MISS
x-github-request-id: CE18:998A1:52CC:5FCC:687E5CEA
accept-ranges: bytes
age: 0
date: Mon, 21 Jul 2025 15:29:47 GMT
via: 1.1 varnish
x-served-by: cache-bom4734-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753111788.720065,VS0,VE221
vary: Accept-Encoding
x-fastly-request-id: 326e0836d4eb773cfd4c4ba0e3a5aa7d3b859918
content-length: 1228
// © 2025 and later: Unicode, Inc. and others.
// License & terms of use: https://www.unicode.org/copyright.html
#include
#include "unicode/utypes.h"
#include "unicode/calendar.h"
#include "unicode/errorcode.h"
#include "unicode/locid.h"
#include "unicode/messageformat2.h"
using namespace icu;
int main() {
ErrorCode errorCode;
UParseError parseError;
icu::Calendar* cal(Calendar::createInstance(errorCode));
cal->set(2025, Calendar::JANUARY, 28);
UDate date = cal->getTime(errorCode);
message2::MessageFormatter::Builder builder(errorCode);
message2::MessageFormatter mf = builder
.setPattern("Hello {$user}, today is {$now :date style=long}!", parseError, errorCode)
.setLocale(Locale("en_US"))
.build(errorCode);
std::map argsBuilder;
argsBuilder["user"] = message2::Formattable("John");
argsBuilder["now"] = message2::Formattable::forDate(date);
message2::MessageArguments arguments(argsBuilder, errorCode);
icu::UnicodeString result = mf.formatToString(arguments, errorCode);
std::string strResult;
result.toUTF8String(strResult);
std::cout << strResult << std::endl;
}