晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
| DIR:/opt/alt/alt-nodejs18/root/usr/include/unicode/ |
| Current File : //opt/alt/alt-nodejs18/root/usr/include/unicode/simplenumberformatter.h |
// © 2022 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
#ifndef __SIMPLENUMBERFORMATTERH__
#define __SIMPLENUMBERFORMATTERH__
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/dcfmtsym.h"
#include "unicode/usimplenumberformatter.h"
#include "unicode/formattednumber.h"
/**
* \file
* \brief C++ API: Simple number formatting focused on low memory and code size.
*
* These functions render locale-aware number strings but without the bells and whistles found in
* other number formatting APIs such as those in numberformatter.h, like units and currencies.
*
* <pre>
* SimpleNumberFormatter snf = SimpleNumberFormatter::forLocale("de-CH", status);
* FormattedNumber result = snf.formatInt64(-1000007, status);
* assertEquals("", u"-1’000’007", result.toString(status));
* </pre>
*/
U_NAMESPACE_BEGIN
namespace number { // icu::number
namespace impl {
class UFormattedNumberData;
struct SimpleMicroProps;
class AdoptingSignumModifierStore;
} // icu::number::impl
#ifndef U_HIDE_DRAFT_API
/**
* An input type for SimpleNumberFormatter.
*
* This class is mutable and not intended for public subclassing. This class is movable but not copyable.
*
* @draft ICU 73
*/
class U_I18N_API SimpleNumber : public UMemory {
public:
/**
* Creates a SimpleNumber for an integer.
*
* @draft ICU 73
*/
static SimpleNumber forInt64(int64_t value, UErrorCode& status);
/**
* Changes the value of the SimpleNumber by a power of 10.
*
* This function immediately mutates the inner value.
*
* @draft ICU 73
*/
void multiplyByPowerOfTen(int32_t power, UErrorCode& status);
/**
* Rounds the value currently stored in the SimpleNumber to the given power of 10.
*
* This function immediately mutates the inner value.
*
* @draft ICU 73
*/
void roundTo(int32_t power, UNumberFormatRoundingMode roundingMode, UErrorCode& status);
/**
* Truncates the most significant digits to the given maximum number of integer digits.
*
* This function immediately mutates the inner value.
*
* @draft ICU 73
*/
void truncateStart(uint32_t maximumIntegerDigits, UErrorCode& status);
/**
* Pads the beginning of the number with zeros up to the given minimum number of integer digits.
*
* This setting is applied upon formatting the number.
*
* @draft ICU 73
*/
void setMinimumIntegerDigits(uint32_t minimumIntegerDigits, UErrorCode& status);
/**
* Pads the end of the number with zeros up to the given minimum number of fraction digits.
*
* This setting is applied upon formatting the number.
*
* @draft ICU 73
*/
void setMinimumFractionDigits(uint32_t minimumFractionDigits, UErrorCode& status);
/**
* Sets the sign of the number: an explicit plus sign, explicit minus sign, or no sign.
*
* This setting is applied upon formatting the number.
*
* NOTE: This does not support accounting sign notation.
*
* @draft ICU 73
*/
void setSign(USimpleNumberSign sign, UErrorCode& status);
/**
* Creates a new, empty SimpleNumber that does not contain a value.
*
* NOTE: This number will fail to format; use forInt64() to create a SimpleNumber with a value.
*
* @draft ICU 73
*/
SimpleNumber() = default;
/**
* Destruct this SimpleNumber, cleaning up any memory it might own.
*
* @draft ICU 73
*/
~SimpleNumber() {
cleanup();
}
/**
* SimpleNumber move constructor.
*
* @draft ICU 73
*/
SimpleNumber(SimpleNumber&& other) noexcept {
fData = other.fData;
fSign = other.fSign;
other.fData = nullptr;
}
/**
* SimpleNumber move assignment.
*
* @draft ICU 73
*/
SimpleNumber& operator=(SimpleNumber&& other) noexcept {
cleanup();
fData = other.fData;
fSign = other.fSign;
other.fData = nullptr;
return *this;
}
private:
SimpleNumber(impl::UFormattedNumberData* data, UErrorCode& status);
SimpleNumber(const SimpleNumber&) = delete;
SimpleNumber& operator=(const SimpleNumber&) = delete;
void cleanup();
impl::UFormattedNumberData* fData = nullptr;
USimpleNumberSign fSign = UNUM_SIMPLE_NUMBER_NO_SIGN;
friend class SimpleNumberFormatter;
};
/**
* A special NumberFormatter focused on smaller binary size and memory use.
*
* SimpleNumberFormatter is capable of basic number formatting, including grouping separators,
* sign display, and rounding. It is not capable of currencies, compact notation, or units.
*
* This class is immutable and not intended for public subclassing. This class is movable but not copyable.
*
* @draft ICU 73
*/
class U_I18N_API SimpleNumberFormatter : public UMemory {
public:
/**
* Creates a new SimpleNumberFormatter with all locale defaults.
*
* @draft ICU 73
*/
static SimpleNumberFormatter forLocale(
const icu::Locale &locale,
UErrorCode &status);
/**
* Creates a new SimpleNumberFormatter, overriding the grouping strategy.
*
* @draft ICU 73
*/
static SimpleNumberFormatter forLocaleAndGroupingStrategy(
const icu::Locale &locale,
UNumberGroupingStrategy groupingStrategy,
UErrorCode &status);
/**
* Creates a new SimpleNumberFormatter, overriding the grouping strategy and symbols.
*
* IMPORTANT: For efficiency, this function borrows the symbols. The symbols MUST remain valid
* for the lifetime of the SimpleNumberFormatter.
*
* @draft ICU 73
*/
static SimpleNumberFormatter forLocaleAndSymbolsAndGroupingStrategy(
const icu::Locale &locale,
const DecimalFormatSymbols &symbols,
UNumberGroupingStrategy groupingStrategy,
UErrorCode &status);
/**
* Formats a value using this SimpleNumberFormatter.
*
* The SimpleNumber argument is "consumed". A new SimpleNumber object should be created for
* every formatting operation.
*
* @draft ICU 73
*/
FormattedNumber format(SimpleNumber value, UErrorCode &status) const;
/**
* Formats an integer using this SimpleNumberFormatter.
*
* For more control over the formatting, use SimpleNumber.
*
* @draft ICU 73
*/
FormattedNumber formatInt64(int64_t value, UErrorCode &status) const {
return format(SimpleNumber::forInt64(value, status), status);
}
#ifndef U_HIDE_INTERNAL_API
/**
* Run the formatter with the internal types.
* @internal
*/
void formatImpl(impl::UFormattedNumberData* data, USimpleNumberSign sign, UErrorCode& status) const;
#endif // U_HIDE_INTERNAL_API
/**
* Destruct this SimpleNumberFormatter, cleaning up any memory it might own.
*
* @draft ICU 73
*/
~SimpleNumberFormatter() {
cleanup();
}
/**
* Creates a shell, initialized but non-functional SimpleNumberFormatter.
*
* @draft ICU 73
*/
SimpleNumberFormatter() = default;
/**
* SimpleNumberFormatter: Move constructor.
*
* @draft ICU 73
*/
SimpleNumberFormatter(SimpleNumberFormatter&& other) noexcept {
fGroupingStrategy = other.fGroupingStrategy;
fOwnedSymbols = other.fOwnedSymbols;
fMicros = other.fMicros;
fPatternModifier = other.fPatternModifier;
other.fOwnedSymbols = nullptr;
other.fMicros = nullptr;
other.fPatternModifier = nullptr;
}
/**
* SimpleNumberFormatter: Move assignment.
*
* @draft ICU 73
*/
SimpleNumberFormatter& operator=(SimpleNumberFormatter&& other) noexcept {
cleanup();
fGroupingStrategy = other.fGroupingStrategy;
fOwnedSymbols = other.fOwnedSymbols;
fMicros = other.fMicros;
fPatternModifier = other.fPatternModifier;
other.fOwnedSymbols = nullptr;
other.fMicros = nullptr;
other.fPatternModifier = nullptr;
return *this;
}
private:
void initialize(
const icu::Locale &locale,
const DecimalFormatSymbols &symbols,
UNumberGroupingStrategy groupingStrategy,
UErrorCode &status);
void cleanup();
SimpleNumberFormatter(const SimpleNumberFormatter&) = delete;
SimpleNumberFormatter& operator=(const SimpleNumberFormatter&) = delete;
UNumberGroupingStrategy fGroupingStrategy = UNUM_GROUPING_AUTO;
// Owned Pointers:
DecimalFormatSymbols* fOwnedSymbols = nullptr; // can be empty
impl::SimpleMicroProps* fMicros = nullptr;
impl::AdoptingSignumModifierStore* fPatternModifier = nullptr;
};
#endif // U_HIDE_DRAFT_API
} // namespace number
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // __SIMPLENUMBERFORMATTERH__
|