KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
string_utilities.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Vicente Mataix Ferrandiz
11 //
12 
13 #pragma once
14 
15 // System includes
16 #include <string>
17 #include <vector>
18 
19 // External includes
20 
21 // Project includes
22 #include "includes/define.h"
23 
24 namespace Kratos
25 {
28 
32 
36 
40 
44 
50 namespace StringUtilities
51 {
57  std::string KRATOS_API(KRATOS_CORE) ConvertCamelCaseToSnakeCase(const std::string& rString);
58 
67  std::string KRATOS_API(KRATOS_CORE) ConvertSnakeCaseToCamelCase(const std::string& rString);
68 
75  std::string KRATOS_API(KRATOS_CORE) ErasePartialString(
76  const std::string& rMainString,
77  const std::string& rToErase
78  );
79 
86  bool KRATOS_API(KRATOS_CORE) ContainsPartialString(
87  const std::string& rMainString,
88  const std::string& rToCheck
89  );
90 
96  std::string KRATOS_API(KRATOS_CORE) RemoveWhiteSpaces(const std::string& rString);
97 
104  std::vector<std::string> KRATOS_API(KRATOS_CORE) SplitStringByDelimiter(
105  const std::string& rString,
106  const char Delimiter
107  );
108 
116  std::string KRATOS_API(KRATOS_CORE) ReplaceAllSubstrings(
117  const std::string& rInputString,
118  const std::string& rStringToBeReplaced,
119  const std::string& rStringToReplace
120  );
121 
128  template<class TClass>
130  std::ostream& rOStream,
131  const TClass& rThisClass,
132  const std::string Identation = "\t"
133  )
134  {
135  // Auxiliary stream and line
136  std::stringstream ss;
137  std::string line;
138  rThisClass.PrintData(ss);
139 
140  // Get the output string from the stringstream.
141  const std::string& r_output = ss.str();
142 
143  // Split the output string into lines.
144  std::istringstream iss(r_output);
145  while (std::getline(iss, line)) {
146  // Here, 'line' is a single line from the output.
147  rOStream << Identation << line << "\n";
148  }
149  }
150 
151 }; // namespace StringUtilities
152 } // namespace Kratos
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
std::string ReplaceAllSubstrings(const std::string &rInputString, const std::string &rStringToBeReplaced, const std::string &rStringToReplace)
This function replaces from a string all times a certain substring is repeated.
Definition: string_utilities.cpp:163
std::string ConvertSnakeCaseToCamelCase(const std::string &rString)
Convert snake_case to CamelCase.
Definition: string_utilities.cpp:48
static void PrintDataWithIdentation(std::ostream &rOStream, const TClass &rThisClass, const std::string Identation="\t")
Prints the data of an object of type TClass to the given output stream with indentation.
Definition: string_utilities.h:129
std::vector< std::string > SplitStringByDelimiter(const std::string &rString, const char Delimiter)
This method splits a string by a delimiter.
Definition: string_utilities.cpp:144
std::string RemoveWhiteSpaces(const std::string &rString)
This method removes whitespaces.
Definition: string_utilities.cpp:127
bool ContainsPartialString(const std::string &rMainString, const std::string &rToCheck)
Checks the existence of a substring from main string.
Definition: string_utilities.cpp:105
std::string ErasePartialString(const std::string &rMainString, const std::string &rToErase)
Erase first occurrence of given substring from main string.
Definition: string_utilities.cpp:83
std::string ConvertCamelCaseToSnakeCase(const std::string &rString)
This method converts CamelCase to snake_case.
Definition: string_utilities.cpp:26
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
This namespace includes several utilities necessaries for computing string operations.