Skip to content

Commit

Permalink
Portability preparation and download command
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomilist committed Jun 9, 2022
1 parent 91caaae commit 5908acf
Show file tree
Hide file tree
Showing 25 changed files with 446 additions and 343 deletions.
10 changes: 8 additions & 2 deletions include/CharacterSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ namespace mcon
{
nlohmann::json json_character_set = LoadJSON(a_file_path);

std::set<std::pair<std::string, std::set<std::wstring>*>> character_sets = {
std::set<std::pair<std::string, std::set<String>*>> character_sets = {
{"whitespace", &whitespace},
{"letter", &letter},
{"number", &number},
{"symbol", &symbol}
};

#ifdef WINDOWS
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
#endif

// Iterate over the four character sets
for (auto& set : character_sets)
Expand All @@ -59,7 +61,11 @@ namespace mcon
for (auto& character : json_character_set.at(set.first).items())
{
// Insert new character if not present already
set.second->insert(converter.from_bytes(character.value()));
#ifdef WINDOWS
set.second->insert(converter.from_bytes(character.value()));
#else
set.second->insert(character.value());
#endif
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions include/CharacterSet.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __CHARACTERSET_H__
#define __CHARACTERSET_H__

#include "definitions.hpp"

// Standard libraries
#include <iostream>
#include <fstream>
Expand All @@ -27,11 +29,11 @@ namespace mcon
void LoadFromFolder(std::string a_folder_path);
void LoadFromFile(std::string a_file_path);

std::set<std::wstring> end_of_stream = {L"\0", L"", std::wstring(1, char(0))};
std::set<std::wstring> whitespace;
std::set<std::wstring> letter;
std::set<std::wstring> number;
std::set<std::wstring> symbol;
std::set<String> end_of_stream = {STR("\0"), STR(""), String(1, char(0))};
std::set<String> whitespace;
std::set<String> letter;
std::set<String> number;
std::set<String> symbol;

private:

Expand Down
14 changes: 7 additions & 7 deletions include/CharacterStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace mcon
{
CharacterStream::CharacterStream(std::wstring a_buffer)
CharacterStream::CharacterStream(String a_buffer)
: buffer(a_buffer)
{ }

CharacterStream::~CharacterStream()
{ }

void CharacterStream::Read(std::wstring a_input)
void CharacterStream::Read(String a_input)
{
index = 0;
buffer = a_input;
Expand Down Expand Up @@ -41,7 +41,7 @@ namespace mcon

if (&clipboard_text != nullptr)
{
buffer = std::wstring(clipboard_text);
buffer = String(clipboard_text);
GlobalUnlock(clip_handle);
}
else
Expand All @@ -61,16 +61,16 @@ namespace mcon

// Return the character at the position (index + a_offset) in "buffer",
// or the null character if the position is out of bounds.
std::wstring CharacterStream::Peek(uint8_t a_offset)
String CharacterStream::Peek(uint8_t a_offset)
{
return std::wstring(1, (index + a_offset) < buffer.size() ? buffer[index + a_offset] : char(0));
return String(1, (index + a_offset) < buffer.size() ? buffer[index + a_offset] : char(0));
}

// Return the character at the position {index + a_offset} in "buffer",
// and set {index = index + a_offset}.
std::wstring CharacterStream::Consume(uint8_t a_offset)
String CharacterStream::Consume(uint8_t a_offset)
{
std::wstring character = Peek(a_offset);
String character = Peek(a_offset);
index += a_offset + 1;
return character;
}
Expand Down
12 changes: 7 additions & 5 deletions include/CharacterStream.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __CHARACTERSTREAM_H__
#define __CHARACTERSTREAM_H__

#include "definitions.hpp"

// Standard libraries
#include <string>
#include <iostream>
Expand All @@ -13,15 +15,15 @@ namespace mcon
class CharacterStream
{
public:
CharacterStream(std::wstring a_buffer = L"");
CharacterStream(String a_buffer = STR(""));
~CharacterStream();

void Read(std::wstring a_input);
void Read(String a_input);
void ReadFromClipboard();
std::wstring Peek(uint8_t a_offset);
std::wstring Consume(uint8_t a_offset);
String Peek(uint8_t a_offset);
String Consume(uint8_t a_offset);

std::wstring buffer;
String buffer;

private:
uint64_t index = 0;
Expand Down
8 changes: 4 additions & 4 deletions include/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace mcon
Token temp_token(TokenType::StartOfStream);

// Pair up the character sets and their corresponding token types for easy iteration
std::set<std::pair<TokenType, std::set<std::wstring>>> character_sets = {
std::set<std::pair<TokenType, std::set<String>>> character_sets = {
{TokenType::EndOfStream, character_set->end_of_stream},
{TokenType::Whitespace, character_set->whitespace},
{TokenType::Text, character_set->letter},
Expand All @@ -38,7 +38,7 @@ namespace mcon
bool character_appended = false;

// Obtain the current character
std::wstring current_character = character_stream->Peek(0);
String current_character = character_stream->Peek(0);

// Iterate over the character sets
for (auto& set : character_sets)
Expand Down Expand Up @@ -76,8 +76,8 @@ namespace mcon
temp_token.Append(character_stream->Consume(0));

// Report the error to the console
std::wcout << L"Unknown character: " << current_character << L"\n"
<< L"The character was not found in any of the supplied character sets." << L"\n"
ERROR_OUTPUT << STR("Unknown character: ") << current_character << STR("\n")
<< STR("The character was not found in any of the supplied character sets.\n")
<< std::endl;
}
}
Expand Down
2 changes: 2 additions & 0 deletions include/Lexer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __LEXER_H__
#define __LEXER_H__

#include "definitions.hpp"

// Standard libraries
#include <string>
#include <vector>
Expand Down
18 changes: 9 additions & 9 deletions include/MconHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
namespace mcon
{
// Wrapper function for SendInput to send an entire unicode string
void SendInputString(std::wstring str)
void SendInputString(String str)
{
std::vector<INPUT> characters;
INPUT input_base;
input_base.type = INPUT_KEYBOARD;
WORD current_character;
WORD previous_character = L'\0';
WORD previous_character = STR('\0');

// Release modifier keys SHIFT, CONTROL and ALT to avoid conflicts with user-pressed keys
input_base.ki.dwFlags = KEYEVENTF_KEYUP;
Expand Down Expand Up @@ -75,11 +75,11 @@ namespace mcon
// Register hotkey ALT + G or print error if it fails to register
if (RegisterHotKey(NULL, MCON_HOTKEY_SEND, MOD_CONTROL | MOD_SHIFT, 'V'))
{
std::wcout << L"Hotkey registered successfully.\n" << std::endl;
STRING_OUTPUT << STR("Hotkey registered successfully.\n") << std::endl;
}
else
{
std::wcerr << L"Hotkey registration error.\n" << std::endl;
ERROR_OUTPUT << STR("Hotkey registration error.\n") << std::endl;
return;
}

Expand All @@ -99,12 +99,12 @@ namespace mcon
{
case DecimalSeparator::Period:
{
parsing_tree->decimal_separator = L".";
parsing_tree->decimal_separator = STR(".");
break;
}
case DecimalSeparator::Comma:
{
parsing_tree->decimal_separator = L",";
parsing_tree->decimal_separator = STR(",");
break;
}
}
Expand All @@ -119,8 +119,8 @@ namespace mcon
parsing_tree->Clean(parsing_tree->root_node);
parsing_tree->generator->Generate(parsing_tree);
parsing_tree->generator->Substitute(parsing_tree);
std::wcout << L"Input: " << parsing_tree->parser->lexer->character_stream->buffer << std::endl;
std::wcout << L"Output: " << parsing_tree->output << L"\n" << std::endl;
STRING_OUTPUT << STR("Input: ") << parsing_tree->parser->lexer->character_stream->buffer << std::endl;
STRING_OUTPUT << STR("Output: ") << parsing_tree->output << STR("\n") << std::endl;
mcon::SendInputString(parsing_tree->output);
}
}
Expand All @@ -132,7 +132,7 @@ namespace mcon
std::shared_ptr<std::mutex> a_settings_mutex
)
{
std::wstring input;
String input;

while (true)
{
Expand Down
9 changes: 7 additions & 2 deletions include/MconHelpers.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#ifndef __MCONHELPERS_H__
#define __MCONHELPERS_H__

#include "definitions.hpp"

// Standard libraries
#include <string>
#include <iostream>
#include <stdexcept>
#include <windows.h>
#include <memory>
#include <mutex>

#ifdef WINDOWS
#include <windows.h>
#endif

// JSON header
#include <nlohmann/json.hpp>

Expand All @@ -33,7 +38,7 @@ namespace mcon
class Parser;
class Generator;

void SendInputString(std::wstring str);
void SendInputString(String str);
void MathConversionHotkey(std::shared_ptr<Settings> a_settings, std::shared_ptr<std::mutex> a_settings_mutex);
void ConfigInput(std::shared_ptr<Settings> a_settings, std::shared_ptr<std::mutex> a_settings_mutex);
}
Expand Down
Loading

0 comments on commit 5908acf

Please sign in to comment.