Initial Commit

This commit is contained in:
2025-05-22 22:35:44 -05:00
commit 4f67b35199
5 changed files with 129 additions and 0 deletions

28
CMakeLists.txt Normal file
View File

@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.18..3.30)
project(jutils
VERSION 1.0
LANGUAGES CXX)
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed!")
endif()
set(CMAKE_CXX_STANDARD 20)
file(GLOB_RECURSE HEADERS "include/*.hpp")
file(GLOB_RECURSE SOURCES "src/*.cpp")
include_directories("include")
if (UNIX)
add_library(jutils SHARED ${SOURCES})
endif()
if (WIN32)
add_library(jutils STATIC ${SOURCES})
endif()
add_executable(jutils_app main.cpp)
target_link_libraries(jutils_app jutils)

26
README.md Normal file
View File

@@ -0,0 +1,26 @@
# Josh's Utilities - C++ Edition
jutils is a project to compile reusable and generic functions that are very useful, but don't merit having an entirely separate library for each one.
Think of it like a swiss-army knife for programming, or an orphanage for otherwise homeless code.
## Included Utilities
* `vector<string> string_expand(string input, char delimiter=' ');`
* `bool string_matches(string input, vector<string> matches);`
## Design Goals
* Minimal dependencies with other libraries. If it depends on another library (say, JJX), it should be packaged with it, or maybe as an addon library to the parent.
* As functions are collected that could be grouped into their own library in a sensible way, they should be moved as such.
* All jutils functions are completely stateless. The input arguments solely determine the output.
* All functions should be rigorously documented, sanity-checked, and unit tested.
## Contributions
Have your own useful stuff that doesn't seem to fit anywhere else? Send in a pull request!!
## License
As part of our philosophy and policy, This work is expressly dedicated to the Public Domain.

23
include/jutils.hpp Normal file
View File

@@ -0,0 +1,23 @@
/// Josh's Utility Library - C++ Functions without a Home.
/// https://git.redacted.cc/josh/jutils
/// Contact: josh@redacted.cc
/// (c) 2025 redacted.cc
/// This work is explicitly dedicated to the Public Domain.
#pragma once
#include <vector>
#include <string>
namespace jutils
{
/// Returns a list of individual tokens from a given string, which is split where instances of the delimiter character occur.
/// Sample: The Quick Brown Fox -> {The, Quick, Brown, Fox}
///
std::vector<std::string> string_expand(const std::string& input, char delimiter = ' ');
bool string_matches(const std::string& x, const std::vector<std::string>& v);
}

27
main.cpp Normal file
View File

@@ -0,0 +1,27 @@
#include <iostream>
// TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
int main()
{
// TIP Press <shortcut actionId="RenameElement"/> when your caret is at the
// <b>lang</b> variable name to see how CLion can help you rename it.
auto lang = "C++";
std::cout << "Hello and welcome to " << lang << "!\n";
for (int i = 1; i <= 5; i++)
{
// TIP Press <shortcut actionId="Debug"/> to start debugging your code.
// We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/>
// breakpoint for you, but you can always add more by pressing
// <shortcut actionId="ToggleLineBreakpoint"/>.
std::cout << "i = " << i << std::endl;
}
return 0;
}
// TIP See CLion help at <a
// href="https://www.jetbrains.com/help/clion/">jetbrains.com/help/clion/</a>.
// Also, you can try interactive lessons for CLion by selecting
// 'Help | Learn IDE Features' from the main menu.

25
src/jutils.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include <jutils.hpp>
#include <sstream>
namespace jutils
{
std::vector<std::string> string_expand(const std::string& input, char delimiter)
{
std::vector<std::string> result;
std::stringstream ss (input);
std::string item;
while (getline(ss, item, delimiter)) {
result.push_back(item);
}
return result;
}
auto string_matches(const std::string &x, const std::vector<std::string> &v) -> bool {
return std::find(v.begin(), v.end(), x) != v.end();
}
}