Skip to content

Commit

Permalink
enhanced pwsh complete
Browse files Browse the repository at this point in the history
  • Loading branch information
silverqx committed Jun 24, 2022
1 parent 8f20121 commit 6b968b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion include/orm/tiny/utils/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ namespace Orm::Tiny::Utils
/*! Convert a value to studly caps case. */
static QString studly(QString string);

/*! Count number of the given character before the given position. */
static QString::size_type countBefore(QString string, QChar character,
QString::size_type position);

#if !defined(TINYORM_DISABLE_TOM) || !defined(TINYORM_DISABLE_ORM)
/*! Check if the given string is the number, signed or unsigned. */
static bool isNumber(QStringView string, bool allowFloating = false);
#endif

#if !defined(TINYORM_DISABLE_TOM)
#ifndef TINYORM_DISABLE_TOM
/*! Split a string by the given width (not in the middle of a word). */
static std::vector<QString>
splitStringByWidth(const QString &string, int width);
Expand Down
8 changes: 8 additions & 0 deletions src/orm/tiny/utils/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ std::vector<QString> String::splitStringByWidth(const QString &string, const int

return lines;
}

QString::size_type String::countBefore(QString string, QChar character,
QString::size_type position)
{
string.truncate(position);

return string.count(character);
}
#endif

#ifndef TINYORM_DISABLE_ORM
Expand Down
7 changes: 5 additions & 2 deletions tom/src/tom/commands/completecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <range/v3/view/transform.hpp>

#include <orm/constants.hpp>
#include <orm/tiny/utils/string.hpp>

#include "tom/application.hpp"
#include "tom/tomutils.hpp"
Expand All @@ -24,6 +25,8 @@ using Orm::Constants::NOSPACE;
using Orm::Constants::SPACE;
using Orm::Constants::database_;

using StringUtils = Orm::Tiny::Utils::String;

using Tom::Constants::DoubleDash;
using Tom::Constants::Env;
using Tom::Constants::Help;
Expand Down Expand Up @@ -131,8 +134,8 @@ int CompleteCommand::run() // NOLINT(readability-function-cognitive-complexity)
--- */
#ifdef _MSC_VER
if (!isOptionArgument(wordArg) && !wordArg.isEmpty() &&
positionArg >= commandlineArgSize &&
(commandlineArg.count(SPACE) == 1 || currentCommandArg == Help)
(StringUtils::countBefore(commandlineArg, SPACE, positionArg) == 1 ||
currentCommandArg == Help)
)
#else
if (!isOptionArgument(wordArg) && !wordArg.isEmpty() &&
Expand Down

0 comments on commit 6b968b9

Please sign in to comment.