Skip to content

Commit 02e1917

Browse files
author
Dan Smith
committed
str::format changes from CODA-OSS
1 parent e4b5c45 commit 02e1917

15 files changed

Lines changed: 124 additions & 58 deletions

File tree

externals/coda-oss/modules/c++/cli/include/cli/Value.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ class CODA_OSS_API Value
106106
{
107107
if (index >= mValues.size())
108108
throw except::IndexOutOfRangeException(
109-
Ctxt(
110-
FmtX(
111-
"Invalid index: %d",
112-
index)));
109+
Ctxt(FmtX("Invalid index: %d", index)));
113110
return str::toType<T>(mValues[index]);
114111
}
115112

externals/coda-oss/modules/c++/cli/source/ArgumentParser.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ std::unique_ptr<cli::Results> cli::ArgumentParser::parse(const std::string& prog
317317
std::map<std::string, Argument*>& flagMap =
318318
(subOption ? shortOptionsFlags : shortFlags);
319319
if (flagMap.find(op) != flagMap.end())
320-
parseError(FmtX("Conflicting option: %c%s", mPrefixChar,
321-
op.c_str()));
320+
parseError(FmtX("Conflicting option: %c%s", mPrefixChar, op));
322321
flagMap[op] = arg;
323322
}
324323
for (std::vector<std::string>::const_iterator it =
@@ -328,8 +327,7 @@ std::unique_ptr<cli::Results> cli::ArgumentParser::parse(const std::string& prog
328327
std::map<std::string, Argument*>& flagMap =
329328
(subOption ? longOptionsFlags : longFlags);
330329
if (flagMap.find(op) != flagMap.end())
331-
parseError(FmtX("Conflicting option: %c%c%s", mPrefixChar,
332-
mPrefixChar, op.c_str()));
330+
parseError(FmtX("Conflicting option: %c%c%s", mPrefixChar, mPrefixChar, op));
333331
flagMap[op] = arg;
334332
}
335333
}
@@ -458,8 +456,7 @@ std::unique_ptr<cli::Results> cli::ArgumentParser::parse(const std::string& prog
458456
}
459457
else
460458
{
461-
throw except::Exception(Ctxt(
462-
FmtX("Invalid option: [%s]", argStr.c_str())));
459+
throw except::Exception(Ctxt(FmtX("Invalid option: [%s]", argStr)));
463460
}
464461
}
465462
}
@@ -500,8 +497,7 @@ std::unique_ptr<cli::Results> cli::ArgumentParser::parse(const std::string& prog
500497
}
501498
else
502499
{
503-
throw except::Exception(Ctxt(
504-
FmtX("Invalid option: [%s]", argStr.c_str())));
500+
throw except::Exception(Ctxt(FmtX("Invalid option: [%s]", argStr)));
505501
}
506502

507503
}
@@ -549,10 +545,7 @@ std::unique_ptr<cli::Results> cli::ArgumentParser::parse(const std::string& prog
549545
}
550546

551547
if (!added)
552-
parseError(
553-
FmtX(
554-
"option requires value or has exceeded its max: [%s]",
555-
argVar.c_str()));
548+
parseError(FmtX("option requires value or has exceeded its max: [%s]", argVar));
556549

557550
currentResults->put(argVar, v);
558551
break;
@@ -677,11 +670,9 @@ std::unique_ptr<cli::Results> cli::ArgumentParser::parse(const std::string& prog
677670
if (arg->isRequired() || numGiven > 0)
678671
{
679672
if (minArgs > 0 && numGiven < static_cast<size_t>(minArgs))
680-
parseError(FmtX("not enough arguments, %d required: [%s]",
681-
minArgs, argId.c_str()));
673+
parseError(FmtX("not enough arguments, %d required: [%s]", minArgs, argId));
682674
if (maxArgs >= 0 && numGiven > static_cast<size_t>(maxArgs))
683-
parseError(FmtX("too many arguments, %d supported: [%s]",
684-
maxArgs, argId.c_str()));
675+
parseError(FmtX("too many arguments, %d supported: [%s]", maxArgs, argId));
685676
}
686677

687678

externals/coda-oss/modules/c++/pch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ CODA_OSS_disable_warning_pop
103103
// change we want to rebuild everything anyway.
104104
#include "gsl/gsl.h"
105105
#include "config/Exports.h"
106+
#include "mem/SharedPtr.h"
107+
#include "sys/filesystem.h"
106108
#include "except/Throwable.h"
107109
#include "sys/Conf.h"
108-
#include "sys/filesystem.h"
109-
#include "mem/SharedPtr.h"
110110

111111
#include "xml/lite/xerces_.h"
112112
#pragma comment(lib, "xerces-c")

externals/coda-oss/modules/c++/plugin/include/plugin/BasicPluginManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ template<typename T> class BasicPluginManager
279279
for (unsigned int i = 0; ops[i] != nullptr; i++)
280280
oss << ops[i] << ":";
281281
eh->onPluginVersionUnsupported(
282-
FmtX("For plugin supporting ops %s version [%d.%d] not supported (%d.%d)",
282+
str::Format("For plugin supporting ops %s version [%d.%d] not supported (%d.%d)",
283283
oss.str().c_str(), majorVersion, minorVersion,
284284
mMajorVersion, mMinorVersion
285285
)

externals/coda-oss/modules/c++/str/include/str/Format.h

Lines changed: 94 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,20 @@
2121
*/
2222

2323

24-
#ifndef __STR_FORMAT_H__
25-
#define __STR_FORMAT_H__
24+
#pragma once
25+
#ifndef CODA_OSS_str_Format_h_INCLUDED_
26+
#define CODA_OSS_str_Format_h_INCLUDED_
2627

2728
#include <stdarg.h>
29+
#include<stdint.h>
30+
#include<stddef.h>
31+
2832
#include <string>
2933

3034
#include "config/Exports.h"
3135

3236
namespace str
3337
{
34-
35-
/*!
36-
* \param format The format
37-
* \param ... Any printf like thing
38-
*/
39-
CODA_OSS_API std::string format(const char* format, ...);
40-
4138
struct CODA_OSS_API Format final
4239
{
4340
Format(const char* format, ...);
@@ -47,14 +44,95 @@ struct CODA_OSS_API Format final
4744
return mString;
4845
}
4946

50-
operator std::string& () noexcept
51-
{
52-
return mString;
53-
}
54-
55-
protected:
47+
private:
5648
std::string mString;
5749
};
5850

51+
/*!
52+
* \param format The format
53+
* \param ... Any printf like thing
54+
*/
55+
//CODA_OSS_API std::string format(const char* format, ...);
56+
57+
inline std::string format(const char* format)
58+
{
59+
return Format(format);
60+
}
61+
62+
inline std::string format(const char* format, const char* pStr)
63+
{
64+
return Format(format, pStr);
65+
}
66+
inline std::string format(const char* format, const std::string& s)
67+
{
68+
return Format(format, s.c_str());
69+
}
70+
inline std::string format(const char* format, int i)
71+
{
72+
return Format(format, i);
73+
}
74+
inline std::string format(const char* format, uint32_t i)
75+
{
76+
return Format(format, i);
77+
}
78+
inline std::string format(const char* format, ptrdiff_t l)
79+
{
80+
return Format(format, l);
81+
}
82+
inline std::string format(const char* format, size_t ul)
83+
{
84+
return Format(format, ul);
85+
}
86+
inline std::string format(const char* format, float f)
87+
{
88+
return Format(format, f);
89+
}
90+
91+
inline std::string format(const char* format, char ch, const char* pStr)
92+
{
93+
return Format(format, ch, pStr);
94+
}
95+
inline std::string format(const char* format, char ch, const std::string& s)
96+
{
97+
return Format(format, ch, s.c_str());
98+
}
99+
inline std::string format(const char* format, const std::string& s1, const std::string& s2)
100+
{
101+
return Format(format, s1.c_str(), s2.c_str());
102+
}
103+
inline std::string format(const char* format, const std::string& s, size_t ul)
104+
{
105+
return Format(format, s.c_str(), ul);
106+
}
107+
inline std::string format(const char* format, char ch1, char ch2)
108+
{
109+
return Format(format, ch1, ch2);
110+
}
111+
inline std::string format(const char* format, size_t ul1, size_t ul2)
112+
{
113+
return Format(format, ul1, ul2);
114+
}
115+
inline std::string format(const char* format, int i, const std::string& s)
116+
{
117+
return Format(format, i, s.c_str());
118+
}
119+
inline std::string format(const char* format, int i, const char* pStr)
120+
{
121+
return Format(format, i, pStr);
122+
}
123+
124+
inline std::string format(const char* format, char ch1, char ch2, const std::string& s)
125+
{
126+
return Format(format, ch1, ch2, s.c_str());
127+
}
128+
inline std::string format(const char* format, int i1, int i2, unsigned long ul)
129+
{
130+
return Format(format, i1, i2, ul);
131+
}
132+
inline std::string format(const char* format, const std::string& s1, const std::string& s2, uint32_t ui)
133+
{
134+
return Format(format, s1.c_str(), s2.c_str(), ui);
135+
}
136+
59137
}
60-
#endif
138+
#endif // CODA_OSS_str_Format_h_INCLUDED_

externals/coda-oss/modules/c++/str/source/Format.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ inline void va_end_(va_list& args)
5151
CODA_OSS_disable_warning_pop
5252
}
5353

54-
std::string str::format(const char *format, ...)
55-
{
56-
va_list args;
57-
va_start(args, format);
58-
auto retval = vformat(format, args);
59-
va_end_(args);
60-
return retval;
61-
}
54+
//std::string str::format(const char *format, ...)
55+
//{
56+
// va_list args;
57+
// va_start(args, format);
58+
// auto retval = vformat(format, args);
59+
// va_end_(args);
60+
// return retval;
61+
//}
6262

6363
str::Format::Format(const char* format, ...)
6464
{

externals/coda-oss/modules/c++/sys/source/OSUnix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ std::string sys::OSUnix::getPlatformName() const
143143
if (uname(&name) == -1)
144144
throw sys::SystemException("Uname failed");
145145

146-
return FmtX("%s (%s): %s [build: %s]", name.sysname, name.machine,
146+
return str::Format("%s (%s): %s [build: %s]", name.sysname, name.machine,
147147
name.release, name.version);
148148
}
149149

externals/coda-oss/modules/c++/sys/source/OSWin32.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ std::string sys::OSWin32::getPlatformName() const
5858
{
5959
platform = "Unknown Windows OS";
6060
}
61-
return FmtX("%s: %d.%d [build: %d], %s", platform.c_str(),
61+
return str::Format("%s: %d.%d [build: %d], %s", platform.c_str(),
6262
info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber,
6363
info.szCSDVersion);
6464
}

externals/coda-oss/modules/c++/xml.lite/source/Attributes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ std::string xml::lite::Attributes::getValue(const QName& qname) const
152152
{
153153
const auto uri = qname.getUri().value;
154154
const auto localName = qname.getName();
155-
throw except::NoSuchKeyException(Ctxt(FmtX("(uri: %s, localName: %s",
156-
uri.c_str(), localName.c_str())));
155+
throw except::NoSuchKeyException(Ctxt(FmtX("(uri: %s, localName: %s", uri, localName)));
157156
}
158157
return retval;
159158
}

externals/nitro/modules/c++/nitf/include/nitf/Enum.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <new> // std::nothrow
3333

3434
#include "str/Manip.h"
35+
#include "str/Encoding.h"
3536

3637
namespace nitf
3738
{

0 commit comments

Comments
 (0)