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);
100 bool fatal_if_not_found,
bool fatal_if_invalid)
106 return string_with_symbols;
109 if (string_with_symbols.
empty())
110 return string_with_symbols;
117 _countChar(string_with_symbols,
'@', nb_at, nb_at_with_escape);
118 if (nb_at == 0 && nb_at_with_escape == 0)
119 return string_with_symbols;
122 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] ==
'@') {
151 combined.append(part);
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]);
215 bool previous_backslash =
false;
217 for (
Int64 i = 0; i < len; ++i) {
219 if (str_span[i] == c) {
221 if (previous_backslash) {
223 str_view_array[index++] = str_view.
subView(offset, i - 1 - offset);
225 str_view_array[index++] = str_view.
subView(i, 1);
228 previous_backslash =
false;
232 str_view_array[index++] = str_view.
subView(offset, i - offset);
238 else if (str_span[i] ==
'\\') {
240 if (previous_backslash)
241 previous_backslash =
false;
243 previous_backslash =
true;
246 previous_backslash =
false;
250 str_view_array[index] = str_view.
subView(offset, len - offset);
269 count_c_with_escape = 0;
270 bool previous_backslash =
false;
272 for (
const Byte byte : str_view.
bytes()) {
274 if (previous_backslash) {
275 count_c_with_escape++;
276 previous_backslash =
false;
282 else if (
byte ==
'\\') {
284 if (previous_backslash)
285 previous_backslash =
false;
287 previous_backslash =
true;
290 previous_backslash =
false;
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Integer size() const
Nombre d'éléments du vecteur.
Vue modifiable d'un tableau d'un type T.
Liste de paramètres avec informations pour surcharger les options du jeu de données.
String getParameterOrNull(const String ¶m_name) const
Récupère le paramètre de nom param_name.
Tableau 1D de données avec buffer pré-alloué sur la pile.
Vue d'un tableau d'éléments de type T.
Constructeur de chaîne de caractère unicode.
String toString() const
Retourne la chaîne de caractères construite.
static void _countChar(StringView str_view, char c, Integer &count_c, Integer &count_c_with_escape)
Méthode permettant de compter le nombre de caractères séparateurs dans une chaine de caractères.
static void _splitString(StringView str_view, ArrayView< StringView > str_view_array, char c)
Méthode permettant de splitter la chaine "str_view" en plusieurs morceaux. Les splits seront entre le...
Vue sur une chaîne de caractères UTF-8.
constexpr Span< const Byte > bytes() const ARCCORE_NOEXCEPT
Retourne la conversion de l'instance dans l'encodage UTF-8.
constexpr Int64 length() const ARCCORE_NOEXCEPT
Longueur en octet de la chaîne de caractères.
StringView subView(Int64 pos) const
Sous-chaîne commençant à la position pos.
constexpr bool empty() const ARCCORE_NOEXCEPT
Vrai si la chaîne est nulle ou vide.
Chaîne de caractères unicode.
bool null() const
Retourne true si la chaîne est nulle.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
List< String > StringList
Tableau de chaînes de caractères unicode.
unsigned char Byte
Type d'un octet.