Initial commit

This commit is contained in:
TheSkyWinds 2024-12-18 14:06:15 +01:00
parent 1c9d621d7f
commit b31dcf79f5
3 changed files with 221 additions and 0 deletions

6
CMakeLists.txt Normal file
View File

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.30)
project(Astral-codex)
set(CMAKE_CXX_STANDARD 20)
add_executable(Astral-codex main.cpp)

64
Errorseal.h Normal file
View File

@ -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 <iostream>
#include <limits>
namespace error {
// Clears the buffer for std::cin.
inline void ignoreLine() {
std::cin.ignore(std::numeric_limits<std::streamsize>::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

151
main.cpp Normal file
View File

@ -0,0 +1,151 @@
#include <iostream>
#include <sstream>
#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;
}
}