CARVIEW |
Select Language
HTTP/2 200
server: GitHub.com
content-type: text/x-c
last-modified: Tue, 01 Jul 2025 23:28:12 GMT
access-control-allow-origin: *
etag: "68646f0c-4cc"
expires: Sun, 20 Jul 2025 10:22:32 GMT
cache-control: max-age=600
x-proxy-cache: MISS
x-github-request-id: 77B3:27021:FF5CE:13F9D4:687CC110
accept-ranges: bytes
age: 0
date: Sun, 20 Jul 2025 10:12:32 GMT
via: 1.1 varnish
x-served-by: cache-bom4727-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753006352.163325,VS0,VE223
vary: Accept-Encoding
x-fastly-request-id: ff033682d44e822b370ef92370d6bba4433c2ef3
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;
}