Make use of newly introduced string builder
This commit is contained in:
parent
5c004015ce
commit
33d368397f
|
@ -4,6 +4,7 @@
|
||||||
#include "./failure.h"
|
#include "./failure.h"
|
||||||
|
|
||||||
#include "../conversion/stringconversion.h"
|
#include "../conversion/stringconversion.h"
|
||||||
|
#include "../conversion/stringbuilder.h"
|
||||||
#include "../io/path.h"
|
#include "../io/path.h"
|
||||||
#include "../io/ansiescapecodes.h"
|
#include "../io/ansiescapecodes.h"
|
||||||
|
|
||||||
|
@ -250,7 +251,7 @@ void ArgumentReader::read(ArgumentVector &args)
|
||||||
++index, ++argv, argDenotation = nullptr;
|
++index, ++argv, argDenotation = nullptr;
|
||||||
break;
|
break;
|
||||||
case UnknownArgumentBehavior::Fail:
|
case UnknownArgumentBehavior::Fail:
|
||||||
throw Failure("The specified argument \"" + string(*argv) + "\" is unknown and will be ignored.");
|
throw Failure("The specified argument \"" % string(*argv) + "\" is unknown and will be ignored.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // if(!matchingArg)
|
} // if(!matchingArg)
|
||||||
|
@ -1122,10 +1123,10 @@ void ArgumentParser::checkConstraints(const ArgumentVector &args)
|
||||||
for(const Argument *arg : args) {
|
for(const Argument *arg : args) {
|
||||||
const auto occurrences = arg->occurrences();
|
const auto occurrences = arg->occurrences();
|
||||||
if(arg->isParentPresent() && occurrences > arg->maxOccurrences()) {
|
if(arg->isParentPresent() && occurrences > arg->maxOccurrences()) {
|
||||||
throw Failure("The argument \"" + string(arg->name()) + "\" mustn't be specified more than " + numberToString(arg->maxOccurrences()) + (arg->maxOccurrences() == 1 ? " time." : " times."));
|
throw Failure("The argument \"" % string(arg->name()) % "\" mustn't be specified more than " % numberToString(arg->maxOccurrences()) + (arg->maxOccurrences() == 1 ? " time." : " times."));
|
||||||
}
|
}
|
||||||
if(arg->isParentPresent() && occurrences < arg->minOccurrences()) {
|
if(arg->isParentPresent() && occurrences < arg->minOccurrences()) {
|
||||||
throw Failure("The argument \"" + string(arg->name()) + "\" must be specified at least " + numberToString(arg->minOccurrences()) + (arg->minOccurrences() == 1 ? " time." : " times."));
|
throw Failure("The argument \"" % string(arg->name()) % "\" must be specified at least " % numberToString(arg->minOccurrences()) + (arg->minOccurrences() == 1 ? " time." : " times."));
|
||||||
}
|
}
|
||||||
Argument *conflictingArgument = nullptr;
|
Argument *conflictingArgument = nullptr;
|
||||||
if(arg->isMainArgument()) {
|
if(arg->isMainArgument()) {
|
||||||
|
@ -1136,7 +1137,7 @@ void ArgumentParser::checkConstraints(const ArgumentVector &args)
|
||||||
conflictingArgument = arg->conflictsWithArgument();
|
conflictingArgument = arg->conflictsWithArgument();
|
||||||
}
|
}
|
||||||
if(conflictingArgument) {
|
if(conflictingArgument) {
|
||||||
throw Failure("The argument \"" + string(conflictingArgument->name()) + "\" can not be combined with \"" + arg->name() + "\".");
|
throw Failure("The argument \"" % string(conflictingArgument->name()) % "\" can not be combined with \"" + arg->name() + "\".");
|
||||||
}
|
}
|
||||||
for(size_t i = 0; i != occurrences; ++i) {
|
for(size_t i = 0; i != occurrences; ++i) {
|
||||||
if(!arg->allRequiredValuesPresent(i)) {
|
if(!arg->allRequiredValuesPresent(i)) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "./datetime.h"
|
#include "./datetime.h"
|
||||||
|
|
||||||
#include "../conversion/stringconversion.h"
|
#include "../conversion/stringconversion.h"
|
||||||
|
#include "../conversion/stringbuilder.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
@ -168,7 +169,7 @@ std::pair<DateTime, TimeSpan> DateTime::fromIsoString(const char *str)
|
||||||
} else if(c == '\0') {
|
} else if(c == '\0') {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
throw ConversionException(string("unexpected \"") + c + '\"');
|
throw ConversionException(string("unexpected \"") % c + '\"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deltaNegative && (*deltaHourIndex = -*deltaHourIndex);
|
deltaNegative && (*deltaHourIndex = -*deltaHourIndex);
|
||||||
|
|
10
io/path.cpp
10
io/path.cpp
|
@ -123,10 +123,10 @@ bool settingsDirectory(std::string &result, std::string applicationDirectoryName
|
||||||
}
|
}
|
||||||
#if defined(PLATFORM_UNIX) || defined(PLATFORM_MAC)
|
#if defined(PLATFORM_UNIX) || defined(PLATFORM_MAC)
|
||||||
if(char *homeDir = getenv("HOME")) {
|
if(char *homeDir = getenv("HOME")) {
|
||||||
result = string(homeDir);
|
result = homeDir;
|
||||||
} else {
|
} else {
|
||||||
struct passwd *pw = getpwuid(getuid());
|
struct passwd *pw = getpwuid(getuid());
|
||||||
result = string(pw->pw_dir);
|
result = pw->pw_dir;
|
||||||
}
|
}
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
result += "/.config";
|
result += "/.config";
|
||||||
|
@ -136,7 +136,8 @@ bool settingsDirectory(std::string &result, std::string applicationDirectoryName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!applicationDirectoryName.empty()) {
|
if(!applicationDirectoryName.empty()) {
|
||||||
result += "/" + applicationDirectoryName;
|
result += '/';
|
||||||
|
result += applicationDirectoryName;
|
||||||
if(createApplicationDirectory && !(stat(result.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode))) {
|
if(createApplicationDirectory && !(stat(result.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode))) {
|
||||||
if(mkdir(result.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
|
if(mkdir(result.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -147,7 +148,8 @@ bool settingsDirectory(std::string &result, std::string applicationDirectoryName
|
||||||
if(char *appData = getenv("appdata")) {
|
if(char *appData = getenv("appdata")) {
|
||||||
result = appData;
|
result = appData;
|
||||||
if(!applicationDirectoryName.empty()) {
|
if(!applicationDirectoryName.empty()) {
|
||||||
result += "\\" + applicationDirectoryName;
|
result += '\\';
|
||||||
|
result += applicationDirectoryName;
|
||||||
if(createApplicationDirectory) {
|
if(createApplicationDirectory) {
|
||||||
// FIXME: use UTF-16 API to support unicode, or rewrite using fs abstraction lib
|
// FIXME: use UTF-16 API to support unicode, or rewrite using fs abstraction lib
|
||||||
DWORD ftyp = GetFileAttributesA(result.c_str());
|
DWORD ftyp = GetFileAttributesA(result.c_str());
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "./testutils.h"
|
#include "./testutils.h"
|
||||||
|
|
||||||
|
#include "../conversion/stringbuilder.h"
|
||||||
|
|
||||||
#include "../application/argumentparser.h"
|
#include "../application/argumentparser.h"
|
||||||
#include "../application/argumentparserprivate.h"
|
#include "../application/argumentparserprivate.h"
|
||||||
#include "../application/failure.h"
|
#include "../application/failure.h"
|
||||||
|
@ -17,6 +19,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace ApplicationUtilities;
|
using namespace ApplicationUtilities;
|
||||||
|
using namespace ConversionUtilities;
|
||||||
|
|
||||||
using namespace CPPUNIT_NS;
|
using namespace CPPUNIT_NS;
|
||||||
|
|
||||||
|
@ -494,9 +497,9 @@ void ArgumentParserTests::testBashCompletion()
|
||||||
// order for file names is not specified
|
// order for file names is not specified
|
||||||
const string res(buffer.str());
|
const string res(buffer.str());
|
||||||
if(res.find(".mkv") < res.find(".ini")) {
|
if(res.find(".mkv") < res.find(".ini")) {
|
||||||
CPPUNIT_ASSERT_EQUAL("COMPREPLY=('" + mkvFilePath + " '\"'\"'with quote'\"'\"'.mkv' '" + iniFilePath + ".ini' ); compopt -o filenames\n", buffer.str());
|
CPPUNIT_ASSERT_EQUAL("COMPREPLY=('" % mkvFilePath % " '\"'\"'with quote'\"'\"'.mkv' '" % iniFilePath + ".ini' ); compopt -o filenames\n", buffer.str());
|
||||||
} else {
|
} else {
|
||||||
CPPUNIT_ASSERT_EQUAL("COMPREPLY=('" + iniFilePath + ".ini' '" + mkvFilePath + " '\"'\"'with quote'\"'\"'.mkv' ); compopt -o filenames\n", buffer.str());
|
CPPUNIT_ASSERT_EQUAL("COMPREPLY=('" % iniFilePath % ".ini' '" % mkvFilePath + " '\"'\"'with quote'\"'\"'.mkv' ); compopt -o filenames\n", buffer.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// sub arguments
|
// sub arguments
|
||||||
|
|
|
@ -202,7 +202,7 @@ string TestApplication::workingCopyPath(const string &name) const
|
||||||
// copy file
|
// copy file
|
||||||
try {
|
try {
|
||||||
origFile.open(testFilePath(name), ios_base::in | ios_base::binary);
|
origFile.open(testFilePath(name), ios_base::in | ios_base::binary);
|
||||||
string path = m_workingDir + name;
|
const string path = m_workingDir + name;
|
||||||
workingCopy.open(path, ios_base::out | ios_base::binary | ios_base::trunc);
|
workingCopy.open(path, ios_base::out | ios_base::binary | ios_base::trunc);
|
||||||
workingCopy << origFile.rdbuf();
|
workingCopy << origFile.rdbuf();
|
||||||
return path;
|
return path;
|
||||||
|
|
Loading…
Reference in New Issue