From b31dcf79f55d89384df6dceefdc9f41558a1faaa Mon Sep 17 00:00:00 2001 From: TheSkyWinds Date: Wed, 18 Dec 2024 14:06:15 +0100 Subject: [PATCH] Initial commit --- CMakeLists.txt | 6 ++ Errorseal.h | 64 +++++++++++++++++++++ main.cpp | 151 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 221 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 Errorseal.h create mode 100644 main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..19a8c29 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.30) +project(Astral-codex) + +set(CMAKE_CXX_STANDARD 20) + +add_executable(Astral-codex main.cpp) diff --git a/Errorseal.h b/Errorseal.h new file mode 100644 index 0000000..71ce426 --- /dev/null +++ b/Errorseal.h @@ -0,0 +1,64 @@ +// +// Created by TheSkyWinds on 10/25/24. +// + +// TODO: Add documentation on how it is used. + +#ifndef ERRORSEAL_H +#define ERRORSEAL_H + +#include +#include + +namespace error { +// Clears the buffer for std::cin. + inline void ignoreLine() { + + std::cin.ignore(std::numeric_limits::max(), '\n'); + + } + +/* + * cinError() returns true if an error occurs. + * cinError() also clears up the error and buffer, so that the program can continue to work. + */ + inline bool cinError(){ + bool errorState{false}; + if (!std::cin) { + + if (std::cin.eof()) { + std::exit(0); // Shut down the program now + } + + std::cin.clear(); + ignoreLine(); + errorState = true; + } + return errorState; + } + +/* + * Throws a generic, undefined error message, but does the same as the function above. + * Primarily used for quick and easy debugging. + */ + + inline bool cinErrorVerbose() { + bool errorState{false}; + if (!std::cin) { + + if (std::cin.eof()) { + std::exit(0); + } + + std::cin.clear(); + ignoreLine(); + + std::cerr << "Whoops, you broke the program!\n"; + errorState = true; + } + return errorState; + } +} + + +#endif //ERRORSEAL_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..a93f271 --- /dev/null +++ b/main.cpp @@ -0,0 +1,151 @@ +#include +#include +#include "Errorseal.h" + +/* + * Coder: TheSkyWinds + * Translator: MewTheNekomata + * + * Created: 12/16/24. + */ + +// Mew's translations: +// A=; B=x C=* D=x E=& F=( G=x H=) I=[ J=x K=x L=Line M=x N=/ O=? P=+ Q=x R=] S={ T=} U=. V=x W=- X=x Y=x Z=x + +// Sky's translations: +// A=; B=@ C=* D=< E=& F=( G=" H=) I=[ J=x K=x L=Line M=x N=/ O=? P=+ Q=x R=] S={ T=} U=. V=x W=- X=x Y=x Z=x + +std::string translateInput(const std::string& input) { + std::string translatedText{}; + + for (std::size_t i = 0; i < input.length(); i++) { + switch (input[i]) { + case ';': + translatedText.push_back('a'); + break; + + case '@': + translatedText.push_back('b'); + break; + + case '*': + translatedText.push_back('c'); + break; + + case '<': + translatedText.push_back('d'); + break; + + case '&': + translatedText.push_back('e'); + break; + + case '(': + translatedText.push_back('f'); + break; + + case '"': + translatedText.push_back('g'); + break; + + case ')': + translatedText.push_back('h'); + break; + + case '[': + translatedText.push_back('i'); + break; + + // MISSING J + + // MISSING K + + case '|': + translatedText.push_back('l'); + break; + + // MISSING M + + case '/': + translatedText.push_back('n'); + break; + + case '?': + translatedText.push_back('o'); + break; + + case '+': + translatedText.push_back('p'); + break; + + // MISSING Q + + case ']': + translatedText.push_back('r'); + break; + + case '{': + translatedText.push_back('s'); + break; + + case '}': + translatedText.push_back('t'); + break; + + case '.': + translatedText.push_back('u'); + break; + + // MISSING V + + case 'w': + translatedText.push_back('w'); + break; + + // MISSING X + + // MISSING Y + + // MISSING Z + + case ' ': + translatedText.push_back(' '); + break; + + default: + translatedText.push_back('E'); + break; + } + } + return translatedText; +} + +std::string usrInput() { + + std::string input{}; + + // Ensures that whitespace is preserved. + std::cout << "Enter the untranslated text: "; + std::getline(std::cin, input); + + // Checks if there's any error & clears the buffer. + error::cinErrorVerbose(); + + return input; +} + + + +int main() { + std::string untranslatedText{}; + + while (true) { + untranslatedText = {usrInput()}; + + if (untranslatedText == "exit") { + break; + } + + std::cout << "Translation: " << translateInput(untranslatedText) << std::endl; + } +} \ No newline at end of file