Skip to content

Commit fe4697c

Browse files
committed
Add cvt.imbue() and cvt.getloc()
1 parent 639e5a3 commit fe4697c

3 files changed

Lines changed: 26 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org).
1515
- Added - cvt.toString() support for wchar_t and wstring
1616
- Added - cli.toArgv() and cli.toCmdline() variants that report errors on
1717
cvt.toString() failures.
18+
- Added - Convert configuration options: cvt.imbue() and cvt.getloc()
1819

1920
## dimcli 7.5.0 (2025-11-20)
2021
- Added - cli.success() and cli.fail() overloads with just the exit code

libs/dimcli/cli.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,16 @@ CliLocal::CliLocal()
480480
*
481481
***/
482482

483+
//===========================================================================
484+
locale Cli::Convert::imbue(const locale & loc) {
485+
return m_interpreter.imbue(loc);
486+
}
487+
488+
//===========================================================================
489+
std::locale Cli::Convert::getloc() const {
490+
return m_interpreter.getloc();
491+
}
492+
483493
//===========================================================================
484494
template<>
485495
bool Cli::Convert::toString_impl<std::wstring>(
@@ -690,11 +700,6 @@ Cli::OptBase::OptBase(const string & names, bool flag)
690700
ndx.index(*this);
691701
}
692702

693-
//===========================================================================
694-
locale Cli::OptBase::imbue(const locale & loc) {
695-
return m_interpreter.imbue(loc);
696-
}
697-
698703
//===========================================================================
699704
string Cli::OptBase::defaultPrompt() const {
700705
auto name = (string) m_fromName;
@@ -723,7 +728,7 @@ bool Cli::OptBase::withUnits(
723728
const unordered_map<string, long double> & units,
724729
int flags
725730
) const {
726-
auto & f = use_facet<ctype<char>>(m_interpreter.getloc());
731+
auto & f = use_facet<ctype<char>>(getloc());
727732

728733
auto pos = val.size();
729734
for (;;) {

libs/dimcli/cli.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,18 @@ class DIMCLI_LIB_DECL CliLocal : public Cli {
11951195

11961196
class DIMCLI_LIB_DECL Cli::Convert {
11971197
public:
1198+
//-----------------------------------------------------------------------
1199+
// CONFIGURATION
1200+
1201+
// Change the locale used when parsing values via iostream. Defaults to
1202+
// the user's preferred locale (aka locale("")) for arithmetic types and
1203+
// the "C" locale for everything else.
1204+
std::locale imbue(const std::locale & loc);
1205+
std::locale getloc() const;
1206+
1207+
//-----------------------------------------------------------------------
1208+
// CONVERSIONS
1209+
11981210
// Converts from string to T.
11991211
template <typename T>
12001212
[[nodiscard]] bool fromString(T & out, const std::string & value) const;
@@ -1204,9 +1216,6 @@ class DIMCLI_LIB_DECL Cli::Convert {
12041216
template <typename T>
12051217
[[nodiscard]] bool toString(std::string & out, const T & src) const;
12061218

1207-
protected:
1208-
mutable std::stringstream m_interpreter;
1209-
12101219
private:
12111220
template <typename T>
12121221
auto fromString_impl(T & out, const std::string & src, int, int, int) const
@@ -1244,6 +1253,8 @@ class DIMCLI_LIB_DECL Cli::Convert {
12441253

12451254
template <typename T>
12461255
bool toString_impl(std::string & out, const T & src, long, long) const;
1256+
1257+
mutable std::stringstream m_interpreter;
12471258
};
12481259

12491260
//===========================================================================
@@ -1500,14 +1511,6 @@ class DIMCLI_LIB_DECL Cli::OptBase : public Cli::Convert {
15001511
OptBase(const std::string & names, bool flag);
15011512
virtual ~OptBase() {}
15021513

1503-
//-----------------------------------------------------------------------
1504-
// CONFIGURATION
1505-
1506-
// Change the locale used when parsing values via iostream. Defaults to
1507-
// the user's preferred locale (aka locale("")) for arithmetic types and
1508-
// the "C" locale for everything else.
1509-
std::locale imbue(const std::locale & loc);
1510-
15111514
//-----------------------------------------------------------------------
15121515
// QUERIES
15131516

0 commit comments

Comments
 (0)