17#include "arcane/core/internal/StringVariableReplace.h"
19#include "arcane/utils/CommandLineArguments.h"
20#include "arcane/utils/PlatformUtils.h"
21#include "arcane/utils/SmallArray.h"
22#include "arcane/utils/StringBuilder.h"
23#include "arcane/utils/String.h"
24#include "arcane/utils/FatalErrorException.h"
25#include "arcane/utils/List.h"
36String StringVariableReplace::
37replaceWithCmdLineArgs(
StringView string_with_symbols,
bool fatal_if_not_found,
bool fatal_if_invalid)
41 const CommandLineArguments cla{ args };
42 ParameterListWithCaseOption parameters;
43 parameters.addParameters(cla.parameters());
44 return replaceWithCmdLineArgs(parameters, string_with_symbols, fatal_if_not_found, fatal_if_invalid);
99 bool fatal_if_not_found,
bool fatal_if_invalid)
105 return string_with_symbols;
108 if (string_with_symbols.
empty())
109 return string_with_symbols;
116 _countChar(string_with_symbols,
'@', nb_at, nb_at_with_escape);
117 if (nb_at == 0 && nb_at_with_escape == 0)
118 return string_with_symbols;
121 if (fatal_if_invalid && nb_at % 2 == 1) {
129 const Integer size_array_w_splits = (nb_at + 1) + (nb_at_with_escape * 2);
134 const Integer max_index = size_array_w_splits % 2 == 0 ? size_array_w_splits - 1 : size_array_w_splits;
143 for (
Integer i = 0; i < max_index; ++i) {
150 if (i % 2 == 0 || part.
bytes()[0] ==
'@') {
155 if (reference_input.
null()) {
156 if (fatal_if_not_found) {
157 ARCANE_FATAL(
"Symbol @{0}@ not found in the parameter list", part);
161 combined.
append(reference_input);
168 if (size_array_w_splits % 2 == 0) {
169 combined.
append(string_splited[string_splited.
size() - 1]);
214 bool previous_backslash =
false;
216 for (
Int64 i = 0; i < len; ++i) {
218 if (str_span[i] == c) {
220 if (previous_backslash) {
222 str_view_array[index++] = str_view.
subView(offset, i - 1 - offset);
224 str_view_array[index++] = str_view.
subView(i, 1);
227 previous_backslash =
false;
231 str_view_array[index++] = str_view.
subView(offset, i - offset);
237 else if (str_span[i] ==
'\\') {
239 if (previous_backslash)
240 previous_backslash =
false;
242 previous_backslash =
true;
245 previous_backslash =
false;
249 str_view_array[index] = str_view.
subView(offset, len - offset);
268 count_c_with_escape = 0;
269 bool previous_backslash =
false;
271 for (
const Byte byte : str_view.
bytes()) {
273 if (previous_backslash) {
274 count_c_with_escape++;
275 previous_backslash =
false;
281 else if (
byte ==
'\\') {
283 if (previous_backslash)
284 previous_backslash =
false;
286 previous_backslash =
true;
289 previous_backslash =
false;
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Integer size() const
Number of elements in the vector.
Modifiable view of an array of type T.
Parameter list with information to override dataset options.
String getParameterOrNull(const String ¶m_name) const
Retrieves the parameter with name param_name.
1D data array with pre-allocated stack buffer.
View of an array of elements of type T.
Unicode character string constructor.
StringBuilder & append(const String &str)
Appends str.
String toString() const
Returns the constructed character string.
static void _countChar(StringView str_view, char c, Integer &count_c, Integer &count_c_with_escape)
Method allowing counting the number of separator characters in a character string.
static void _splitString(StringView str_view, ArrayView< StringView > str_view_array, char c)
Method allowing the string "str_view" to be split into multiple segments. The splits will occur betwe...
View of a UTF-8 character string.
constexpr Span< const Byte > bytes() const ARCCORE_NOEXCEPT
Returns the conversion of the instance in UTF-8 encoding.
constexpr Int64 length() const ARCCORE_NOEXCEPT
Length in bytes of the character string.
StringView subView(Int64 pos) const
Substring starting at position pos.
constexpr bool empty() const ARCCORE_NOEXCEPT
True if the string is null or empty.
Unicode character string.
bool null() const
Returns true if the string is null.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
List< String > StringList
Unicode string list.
unsigned char Byte
Type of a byte.