Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
BasedOnStyle: Google
AccessModifierOffset: -2
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
ConstructorInitializerIndentWidth: 2
BracedInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
IndentAccessModifiers: false
InsertNewlineAtEOF: true
LambdaBodyIndentation: Signature
AlignAfterOpenBracket: BlockIndent
AllowShortIfStatementsOnASingleLine: Never
BinPackArguments: false
BinPackParameters: false
AllowShortLambdasOnASingleLine: All
SpacesBeforeTrailingComments: 1
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
IndentBraces: false
BeforeWhile: true
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
IncludeCategories:
- Regex: '^<.*>'
Priority: 1
- Regex: '^"maddy/.*'
Priority: 3
- Regex: '.*'
Priority: 2
SortIncludes: true
IncludeBlocks: Regroup
InsertTrailingCommas: Wrapped
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{h,hh,hpp,c,cc,cpp,cxx,yml}]
[*.{h,hh,hpp,c,cc,cpp,cxx,yml,py,md}]
indent_size = 2

[CMakeLists.txt]
indent_size = 2
25 changes: 25 additions & 0 deletions .github/workflows/run-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: run-checks

on:
push:
branches:
- master
pull_request:

jobs:
run-clang-format:
runs-on: ubuntu-24.04

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'

- name: Run format script with dry_run
run: |
clang-format --version
python tools/format.py dry_run
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ maddy uses [semver versioning](https://semver.org/).
## Upcoming

* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) Updated google test to v1.15.0.
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) clang-format

## version 1.3.0 2023-08-26

Expand Down
69 changes: 29 additions & 40 deletions include/maddy/blockparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <sstream>
#include <string>
// windows compatibility includes
#include <cctype>
#include <algorithm>
#include <cctype>

// -----------------------------------------------------------------------------

Expand All @@ -36,11 +36,13 @@ class BlockParser
*
* @method
* @param {std::function<void(std::string&)>} parseLineCallback
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
* line)>} getBlockParserForLineCallback
*/
BlockParser(
std::function<void(std::string&)> parseLineCallback,
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback
std::function<std::shared_ptr<BlockParser>(const std::string& line)>
getBlockParserForLineCallback
)
: result("", std::ios_base::ate | std::ios_base::in | std::ios_base::out)
, childParser(nullptr)
Expand All @@ -64,8 +66,7 @@ class BlockParser
* @param {std::string&} line
* @return {void}
*/
virtual void
AddLine(std::string& line)
virtual void AddLine(std::string& line)
{
this->parseBlock(line);

Expand Down Expand Up @@ -113,11 +114,7 @@ class BlockParser
* @method
* @return {std::stringstream}
*/
std::stringstream&
GetResult()
{
return this->result;
}
std::stringstream& GetResult() { return this->result; }

/**
* Clear
Expand All @@ -129,11 +126,7 @@ class BlockParser
* @method
* @return {void}
*/
void
Clear()
{
this->result.str("");
}
void Clear() { this->result.str(""); }

protected:
std::stringstream result;
Expand All @@ -143,47 +136,42 @@ class BlockParser
virtual bool isLineParserAllowed() const = 0;
virtual void parseBlock(std::string& line) = 0;

void
parseLine(std::string& line)
void parseLine(std::string& line)
{
if (parseLineCallback)
{
parseLineCallback(line);
}
}

uint32_t
getIndentationWidth(const std::string& line) const
uint32_t getIndentationWidth(const std::string& line) const
{
bool hasMetNonSpace = false;

uint32_t indentation = static_cast<uint32_t>(
std::count_if(
line.begin(),
line.end(),
[&hasMetNonSpace](unsigned char c)
uint32_t indentation = static_cast<uint32_t>(std::count_if(
line.begin(),
line.end(),
[&hasMetNonSpace](unsigned char c)
{
if (hasMetNonSpace)
{
if (hasMetNonSpace)
{
return false;
}

if (std::isspace(c))
{
return true;
}

hasMetNonSpace = true;
return false;
}
)
);

if (std::isspace(c))
{
return true;
}

hasMetNonSpace = true;
return false;
}
));

return indentation;
}

std::shared_ptr<BlockParser>
getBlockParserForLine(const std::string& line)
std::shared_ptr<BlockParser> getBlockParserForLine(const std::string& line)
{
if (getBlockParserForLineCallback)
{
Expand All @@ -195,7 +183,8 @@ class BlockParser

private:
std::function<void(std::string&)> parseLineCallback;
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback;
std::function<std::shared_ptr<BlockParser>(const std::string& line)>
getBlockParserForLineCallback;
}; // class BlockParser

// -----------------------------------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions include/maddy/breaklineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

// -----------------------------------------------------------------------------

#include <string>
#include <regex>
#include <string>

#include "maddy/lineparser.h"

Expand Down Expand Up @@ -36,8 +36,7 @@ class BreakLineParser : public LineParser
* @param {std::string&} line The line to interpret
* @return {void}
*/
void
Parse(std::string& line) override
void Parse(std::string& line) override
{
static std::regex re(R"((\r\n|\r))");
static std::string replacement = "<br>";
Expand Down
43 changes: 15 additions & 28 deletions include/maddy/checklistparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ class ChecklistParser : public BlockParser
*
* @method
* @param {std::function<void(std::string&)>} parseLineCallback
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
* @param {std::function<std::shared_ptr<BlockParser>(const std::string&
* line)>} getBlockParserForLineCallback
*/
ChecklistParser(
ChecklistParser(
std::function<void(std::string&)> parseLineCallback,
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback
std::function<std::shared_ptr<BlockParser>(const std::string& line)>
getBlockParserForLineCallback
)
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
, isStarted(false)
Expand All @@ -51,8 +53,7 @@ class ChecklistParser : public BlockParser
* @param {const std::string&} line
* @return {bool}
*/
static bool
IsStartingLine(const std::string& line)
static bool IsStartingLine(const std::string& line)
{
static std::regex re(R"(^- \[[x| ]\] .*)");
return std::regex_match(line, re);
Expand All @@ -64,27 +65,14 @@ class ChecklistParser : public BlockParser
* @method
* @return {bool}
*/
bool
IsFinished() const override
{
return this->isFinished;
}
bool IsFinished() const override { return this->isFinished; }

protected:
bool
isInlineBlockAllowed() const override
{
return true;
}
bool isInlineBlockAllowed() const override { return true; }

bool
isLineParserAllowed() const override
{
return true;
}
bool isLineParserAllowed() const override { return true; }

void
parseBlock(std::string& line) override
void parseBlock(std::string& line) override
{
bool isStartOfNewListItem = IsStartingLine(line);
uint32_t indentation = getIndentationWidth(line);
Expand All @@ -97,7 +85,8 @@ class ChecklistParser : public BlockParser
line = std::regex_replace(line, emptyBoxRegex, emptyBoxReplacement);

static std::regex boxRegex(R"(^\[x\])");
static std::string boxReplacement = "<input type=\"checkbox\" checked=\"checked\"/>";
static std::string boxReplacement =
"<input type=\"checkbox\" checked=\"checked\"/>";
line = std::regex_replace(line, boxRegex, boxReplacement);

if (!this->isStarted)
Expand All @@ -113,11 +102,9 @@ class ChecklistParser : public BlockParser
return;
}

if (
line.empty() ||
line.find("</label></li><li><label>") != std::string::npos ||
line.find("</label></li></ul>") != std::string::npos
)
if (line.empty() ||
line.find("</label></li><li><label>") != std::string::npos ||
line.find("</label></li></ul>") != std::string::npos)
{
line = "</label></li></ul>" + line;
this->isFinished = true;
Expand Down
Loading