MolSim
Loading...
Searching...
No Matches
Namespaces | Functions | Variables
StringUtils.h File Reference

Utility functions for working with strings. More...

#include "Arguments.h"
#include "CLIUtils.h"
#include <algorithm>
#include <cctype>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  StringUtils
 Namespace defining utility functions for working with strings.
 

Functions

static bool findStringIC (const std::string &haystack, const std::string &needle)
 Finds a given substring in a string. Case-insensitive.
 
static double StringUtils::toDouble (const std::string &str)
 Converts a string to a double.
 
static double StringUtils::toInt (const std::string &str)
 Converts a string to an integer.
 
template<size_t N>
static std::array< int, N > StringUtils::toIntArray (const std::string &str)
 Converts a string into an integer array.
 
template<size_t N>
static std::array< double, N > StringUtils::toDoubleArray (const std::string &str, bool reqBrackets=true)
 Converts a string into a double array.
 
static WriterType StringUtils::toWriterType (const std::string &type)
 Converts a string to a WriterType enum using a dedicated map.
 
static SimulationType StringUtils::toSimulationType (const std::string &type)
 Converts a string to a SimulationType enum using a dedicated map.
 
static ParallelizationType StringUtils::toParallelizationType (const std::string &type)
 Converts a string to a ParallelizationType enum using a dedicated map.
 
static std::string StringUtils::fromChar (char c)
 Converts a char to a string.
 
static std::string StringUtils::fromWriterType (WriterType writerType)
 Converts a WriterType to a string.
 
static std::string StringUtils::fromSimulationType (SimulationType simulationType)
 Converts a SimulationType to a string.
 
static std::string StringUtils::fromParallelizationType (ParallelizationType parallelizationType)
 Converts a ParallelizationType to a string.
 
template<typename T >
static std::string StringUtils::fromNumber (T number)
 Converts a number to a string.
 
template<typename T >
static std::string StringUtils::fromVector (const std::vector< T > &vec)
 Converts a vector to a string.
 

Variables

static const std::unordered_map< std::string, WriterTypewriterTable
 Map containing conversion information for converting a string to a WriterType enum.
 
static const std::unordered_map< std::string, SimulationTypesimulationTable
 Map containing conversion information for converting a string to a SimulationType enum.
 
static const std::unordered_map< std::string, ParallelizationTypeparallelizationTable
 Map containing conversion information for converting a string to a ParallelizationType enum.
 
static const std::unordered_map< WriterType, std::string > writerStringTable
 Reverse map containing conversion information for converting a WriterType enum to a string.
 
static const std::unordered_map< SimulationType, std::string > simulationStringTable
 Reverse map containing conversion information for converting a SimulationType enum to a string.
 
static const std::unordered_map< ParallelizationType, std::string > parallelizationStringTable
 Reverse map containing conversion information for converting a ParallelizationType enum to a string.
 

Detailed Description

Utility functions for working with strings.

Date
2024-10-21

Function Documentation

◆ findStringIC()

static bool findStringIC ( const std::string &  haystack,
const std::string &  needle 
)
inlinestatic

Finds a given substring in a string. Case-insensitive.

Source: https://stackoverflow.com/a/19839371

Parameters
haystackThe string which may or may not contain the substring.
needleThe substring to search for in the string.
Returns
true if the string contains the substring, case-insensitive.
false if the string does not contain the substring, case-insensitive.

Variable Documentation

◆ parallelizationStringTable

const std::unordered_map<ParallelizationType, std::string> parallelizationStringTable
inlinestatic
Initial value:
= []() {
std::unordered_map<ParallelizationType, std::string> reverseMap;
for (const auto &pair : parallelizationTable)
reverseMap[pair.second] = pair.first;
return reverseMap;
}()
static const std::unordered_map< std::string, ParallelizationType > parallelizationTable
Map containing conversion information for converting a string to a ParallelizationType enum.
Definition StringUtils.h:31

Reverse map containing conversion information for converting a ParallelizationType enum to a string.

◆ parallelizationTable

const std::unordered_map<std::string, ParallelizationType> parallelizationTable
inlinestatic
Initial value:

Map containing conversion information for converting a string to a ParallelizationType enum.

◆ simulationStringTable

const std::unordered_map<SimulationType, std::string> simulationStringTable
inlinestatic
Initial value:
= []() {
std::unordered_map<SimulationType, std::string> reverseMap;
for (const auto &pair : simulationTable)
reverseMap[pair.second] = pair.first;
return reverseMap;
}()
static const std::unordered_map< std::string, SimulationType > simulationTable
Map containing conversion information for converting a string to a SimulationType enum.
Definition StringUtils.h:27

Reverse map containing conversion information for converting a SimulationType enum to a string.

◆ simulationTable

const std::unordered_map<std::string, SimulationType> simulationTable
inlinestatic
Initial value:

Map containing conversion information for converting a string to a SimulationType enum.

◆ writerStringTable

const std::unordered_map<WriterType, std::string> writerStringTable
inlinestatic
Initial value:
= []() {
std::unordered_map<WriterType, std::string> reverseMap;
for (const auto &pair : writerTable)
reverseMap[pair.second] = pair.first;
return reverseMap;
}()
static const std::unordered_map< std::string, WriterType > writerTable
Map containing conversion information for converting a string to a WriterType enum.
Definition StringUtils.h:23

Reverse map containing conversion information for converting a WriterType enum to a string.

◆ writerTable

const std::unordered_map<std::string, WriterType> writerTable
inlinestatic
Initial value:

Map containing conversion information for converting a string to a WriterType enum.