Tokenisation working
This commit is contained in:
41
CMakeLists.txt
Normal file
41
CMakeLists.txt
Normal file
@@ -0,0 +1,41 @@
|
||||
cmake_minimum_required(VERSION 4.2)
|
||||
|
||||
# ============================
|
||||
# Project configuration
|
||||
# ============================
|
||||
project(
|
||||
splain
|
||||
VERSION 1.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
# ============================
|
||||
# C++ standard
|
||||
# ============================
|
||||
set(CMAKE_CXX_STANDARD 26)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
# ============================
|
||||
# Build type (optional default)
|
||||
# ============================
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
||||
endif()
|
||||
|
||||
# ============================
|
||||
# Sources
|
||||
# ============================
|
||||
add_executable(${PROJECT_NAME}
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
|
||||
# ============================
|
||||
# Compiler warnings
|
||||
# ============================
|
||||
if(MSVC)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /permissive-)
|
||||
else()
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
13
src/main.cpp
13
src/main.cpp
@@ -1,4 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
/*
|
||||
* Make sure to do
|
||||
* splain() {
|
||||
@@ -6,8 +8,8 @@
|
||||
* }
|
||||
* in the bash during installation
|
||||
*/
|
||||
char** tokenisation(std::string arg) {
|
||||
std::vector<std::string> tokenList;
|
||||
std::vector<std::string> /* char** */ tokenisation(std::string arg) {
|
||||
std::vector<std::string> tokenList = {""};
|
||||
bool inQuotes = false;
|
||||
unsigned char activeToken = 0;
|
||||
for (int i = 0; i < arg.length(); i++) {
|
||||
@@ -28,12 +30,17 @@ char** tokenisation(std::string arg) {
|
||||
tokenList[activeToken] += arg[i];
|
||||
}
|
||||
}
|
||||
return tokenList;
|
||||
}
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 2) {
|
||||
std::cerr << "Usage: splain [OPTIONS] <INPUT>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::vector<std::string> tokens = tokenisation(std::string(argv[1]));
|
||||
//simple demo
|
||||
for (int i = 0; i < tokens.size(); i++) {
|
||||
std::cout << i + 1 << ". " << tokens[i] << "\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user