Improvements for markdown parsing.
This commit is contained in:
parent
fc44290e3f
commit
8705859115
40 changed files with 957 additions and 537 deletions
|
@ -48,3 +48,13 @@ std::string CommandLineArgs::getArg(std::size_t index) const
|
|||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::vector<std::string> CommandLineArgs::getUserArgs() const
|
||||
{
|
||||
std::vector<std::string> user_args;
|
||||
for(unsigned idx=1; idx<mArugments.size(); idx++)
|
||||
{
|
||||
user_args.push_back(mArugments[idx]);
|
||||
}
|
||||
return user_args;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ public:
|
|||
|
||||
void recordLaunchPath();
|
||||
|
||||
std::vector<std::string> getUserArgs() const;
|
||||
|
||||
private:
|
||||
std::vector<std::string> mArugments;
|
||||
std::filesystem::path mLaunchPath;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "StringUtils.h"
|
||||
|
||||
#include <locale>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
@ -8,19 +9,17 @@
|
|||
#include "Windows.h"
|
||||
#endif
|
||||
|
||||
bool StringUtils::IsAlphaNumeric(char c)
|
||||
bool StringUtils::isAlphaNumeric(char c)
|
||||
{
|
||||
std::locale loc;
|
||||
return std::isalnum(c, loc);
|
||||
return std::isalnum(c);
|
||||
}
|
||||
|
||||
bool StringUtils::IsSpace(char c)
|
||||
bool StringUtils::isSpace(char c)
|
||||
{
|
||||
std::locale loc;
|
||||
return std::isspace(c, loc);
|
||||
return std::isspace(c);
|
||||
}
|
||||
|
||||
bool StringUtils::IsAlphabetical(char c)
|
||||
bool StringUtils::isAlphabetical(char c)
|
||||
{
|
||||
return std::isalpha(c);
|
||||
}
|
||||
|
@ -46,7 +45,44 @@ std::vector<std::string> StringUtils::toLines(const std::string& input)
|
|||
return result;
|
||||
}
|
||||
|
||||
std::string StringUtils::strip(const std::string& input)
|
||||
bool StringUtils::isWhitespaceOnly(const std::string& input)
|
||||
{
|
||||
if (input.empty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::all_of(input.cbegin(), input.cend(), [](char c){ return std::isspace(c); });
|
||||
}
|
||||
}
|
||||
|
||||
unsigned StringUtils::countFirstConsecutiveHits(const std::string& input, char c)
|
||||
{
|
||||
auto found_id = input.find(c);
|
||||
if(found_id == std::string::npos)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned count = 1;
|
||||
for(unsigned idx=found_id+1; idx<input.size(); idx++)
|
||||
{
|
||||
if(input[idx] == c)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
std::string StringUtils::stripSurroundingWhitepsace(const std::string& input)
|
||||
{
|
||||
if (input.empty())
|
||||
{
|
||||
|
@ -110,12 +146,10 @@ std::vector<std::string> StringUtils::split(const std::string& input)
|
|||
return substrings;
|
||||
}
|
||||
|
||||
|
||||
std::string StringUtils::ToLower(const std::string& s)
|
||||
std::string StringUtils::toLower(const std::string& s)
|
||||
{
|
||||
std::string ret;
|
||||
std::transform(s.begin(), s.end(), ret.begin(),
|
||||
[](unsigned char c){ return std::tolower(c); });
|
||||
std::transform(s.begin(), s.end(), ret.begin(), [](unsigned char c){ return std::tolower(c); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -139,7 +173,7 @@ std::string StringUtils::convert(const std::wstring& input)
|
|||
#endif
|
||||
}
|
||||
|
||||
std::string StringUtils::ToPaddedString(unsigned numBytes, unsigned entry)
|
||||
std::string StringUtils::toPaddedString(unsigned numBytes, unsigned entry)
|
||||
{
|
||||
std::stringstream sstr;
|
||||
sstr << std::setfill('0') << std::setw(numBytes) << entry;
|
||||
|
@ -165,20 +199,35 @@ std::string StringUtils::stripQuotes(const std::string& input)
|
|||
return input.substr(start_index, end_index - start_index + 1);
|
||||
}
|
||||
|
||||
std::string StringUtils::replaceWith(const std::string& inputString, const std::string& searchString, const std::string& replaceString)
|
||||
{
|
||||
return inputString;
|
||||
}
|
||||
|
||||
std::string StringUtils::removeUpTo(const std::string& input, const std::string& prefix)
|
||||
{
|
||||
std::size_t found = input.find(prefix);
|
||||
if (found!=std::string::npos)
|
||||
if (found != std::string::npos)
|
||||
{
|
||||
return input.substr(found, prefix.size());
|
||||
return input.substr(found + prefix.size(), input.size()-found);
|
||||
}
|
||||
else
|
||||
{
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
bool StringUtils::startsWith(const std::string& input, const std::string& prefix, bool ignoreWhitespace)
|
||||
{
|
||||
if(ignoreWhitespace)
|
||||
{
|
||||
const auto loc = input.find(prefix);
|
||||
if (loc == std::string::npos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return isWhitespaceOnly(input.substr(0, loc));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return input.find(prefix) == 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,26 +16,35 @@ public:
|
|||
static constexpr char SINGLE_QUOTE = '\'';
|
||||
static constexpr char COLON = ':';
|
||||
|
||||
static bool IsAlphaNumeric(char c);
|
||||
static unsigned countFirstConsecutiveHits(const std::string& input, char c);
|
||||
|
||||
static bool IsAlphabetical(char c);
|
||||
|
||||
static bool IsSpace(char c);
|
||||
static std::string ToLower(const std::string& s);
|
||||
static std::string convert(const std::wstring& input);
|
||||
static std::string ToPaddedString(unsigned numBytes, unsigned entry);
|
||||
static std::vector<std::string> split(const std::string& input);
|
||||
static std::string strip(const std::string& input);
|
||||
|
||||
static bool isAlphaNumeric(char c);
|
||||
|
||||
static bool isAlphabetical(char c);
|
||||
|
||||
static bool isSpace(char c);
|
||||
|
||||
static bool isWhitespaceOnly(const std::string& input);
|
||||
|
||||
static std::string removeUpTo(const std::string& input, const std::string& prefix);
|
||||
|
||||
static std::vector<std::string> toLines(const std::string& input);
|
||||
static std::vector<std::string> split(const std::string& input);
|
||||
|
||||
static bool startsWith(const std::string& input, const std::string& prefix, bool ignoreWhitespace = false);
|
||||
|
||||
static std::string stripSurroundingWhitepsace(const std::string& input);
|
||||
|
||||
static std::string stripQuotes(const std::string& input);
|
||||
|
||||
static std::vector<unsigned char> toBytes(const std::string& input);
|
||||
|
||||
static std::string toLower(const std::string& s);
|
||||
|
||||
static std::vector<std::string> toLines(const std::string& input);
|
||||
|
||||
static std::string toPaddedString(unsigned numBytes, unsigned entry);
|
||||
|
||||
static std::string toString(const std::vector<unsigned char>& bytes);
|
||||
|
||||
static std::string replaceWith(const std::string& inputString, const std::string& searchString, const std::string& replaceString);
|
||||
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ FileFormat::ExtensionMap FileFormat::mExtensions = []
|
|||
|
||||
bool FileFormat::isFormat(const std::string& extension, Format format)
|
||||
{
|
||||
return StringUtils::ToLower(extension) == mExtensions[format];
|
||||
return StringUtils::toLower(extension) == mExtensions[format];
|
||||
}
|
||||
|
||||
FileFormat::Format FileFormat::inferFormat(const std::string& query)
|
||||
|
|
|
@ -25,7 +25,6 @@ public:
|
|||
};
|
||||
|
||||
using ExtensionMap = std::map<Format, std::string>;
|
||||
|
||||
public:
|
||||
static bool isFormat(const std::string& extension, Format format);
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ void HttpRequest::parseFirstLine(const std::string& line)
|
|||
const auto c = line[idx];
|
||||
if (inPath)
|
||||
{
|
||||
if (StringUtils::IsSpace(c))
|
||||
if (StringUtils::isSpace(c))
|
||||
{
|
||||
inPath = false;
|
||||
inMethod = true;
|
||||
|
@ -50,7 +50,7 @@ void HttpRequest::parseFirstLine(const std::string& line)
|
|||
}
|
||||
else if (inMethod)
|
||||
{
|
||||
if (StringUtils::IsSpace(c))
|
||||
if (StringUtils::isSpace(c))
|
||||
{
|
||||
inMethod = false;
|
||||
inProtocol = true;
|
||||
|
|
|
@ -12,7 +12,6 @@ public:
|
|||
void parseMessage(const std::string& message);
|
||||
|
||||
private:
|
||||
|
||||
void parseFirstLine(const std::string& line);
|
||||
|
||||
HttpHeader mHeader;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue