L
Lothar Behrens
Hi,
my code can replace the following placeholder in a string by the
second.
char* Foo = "Foo {placeholder}";
char* Bar = "Bar";
MyString s = Foo;
s.substitutePlaceholder(list of named value pairs); // Contains
"placeholder" => "Bar"
The s is now "Foo Bar".
But the following is an endless loop until all the memory has been
eaten up:
char* Foo = "Foo {placeholder}";
char* Bar = "Bar {placeholder}";
MyString s = Foo;
s.substitutePlaceholder(list of named value pairs); // Contains
"placeholder" => "Bar {placeholder}"
The reason is because I have made a quick hack using the following
code in substitutePlaceholder:
while (substituted->strpos("{") > -1) {
// Do the work
}
What solution would you suggest when using the different attempts?
Using functions in string.h (http://www.cplusplus.com/reference/
clibrary/cstring/).
Using STL basic_string (http://www.sgi.com/tech/stl/
basic_string.html).
Using Lex&Yacc or any other parser generators.
I tried to not use the STL, but it may be time to do so in the near
future. The reason for not using STL was a compiler in the past, but
the compiler will support it increasingly.
What problems I do see are as follows:
The placeholders are code snippets entered by humans, thus malformed
values may be entered: "Bar {placeholder", "Bar placeholder}" or even
"Bar {{placeholder} {placeholder}}".
So I don't yet support placeholder in placeholders.
Off topic context:
The code snippets are spread around in my model and used there in
isolation, thus A = {B}, A = automatically_a_string is used there and
A == "" is used there. Thus I do have
simple assignment statements and boolean expressions. But not yet A =
B == "".
I use these different statements and expressions for my UML Activity
execution engine and I am not sure if I can use one parser at all
possible UML Activity elements (transition, guard and parameters)
My UML Activity interpreter currently can understand making decisions
(A == "") and change/add values in a named value pair list (Value1 = 1
or Value2 = {Value1}). Value1 is handled as a String. I do not yet
support other types.
The overall model is a UML Activity diagram I do convert in a list of
numbered statements. The transitions are the jumps between the
statements.
A last question may be answered as well:
With the full outline where I have the problem, would it be best to
implement one parser to get either a statement or a boolean expression
and test against expecting one of these, or keep it as simple with
two?
Thanks,
Lothar
my code can replace the following placeholder in a string by the
second.
char* Foo = "Foo {placeholder}";
char* Bar = "Bar";
MyString s = Foo;
s.substitutePlaceholder(list of named value pairs); // Contains
"placeholder" => "Bar"
The s is now "Foo Bar".
But the following is an endless loop until all the memory has been
eaten up:
char* Foo = "Foo {placeholder}";
char* Bar = "Bar {placeholder}";
MyString s = Foo;
s.substitutePlaceholder(list of named value pairs); // Contains
"placeholder" => "Bar {placeholder}"
The reason is because I have made a quick hack using the following
code in substitutePlaceholder:
while (substituted->strpos("{") > -1) {
// Do the work
}
What solution would you suggest when using the different attempts?
Using functions in string.h (http://www.cplusplus.com/reference/
clibrary/cstring/).
Using STL basic_string (http://www.sgi.com/tech/stl/
basic_string.html).
Using Lex&Yacc or any other parser generators.
I tried to not use the STL, but it may be time to do so in the near
future. The reason for not using STL was a compiler in the past, but
the compiler will support it increasingly.
What problems I do see are as follows:
The placeholders are code snippets entered by humans, thus malformed
values may be entered: "Bar {placeholder", "Bar placeholder}" or even
"Bar {{placeholder} {placeholder}}".
So I don't yet support placeholder in placeholders.
Off topic context:
The code snippets are spread around in my model and used there in
isolation, thus A = {B}, A = automatically_a_string is used there and
A == "" is used there. Thus I do have
simple assignment statements and boolean expressions. But not yet A =
B == "".
I use these different statements and expressions for my UML Activity
execution engine and I am not sure if I can use one parser at all
possible UML Activity elements (transition, guard and parameters)
My UML Activity interpreter currently can understand making decisions
(A == "") and change/add values in a named value pair list (Value1 = 1
or Value2 = {Value1}). Value1 is handled as a String. I do not yet
support other types.
The overall model is a UML Activity diagram I do convert in a list of
numbered statements. The transitions are the jumps between the
statements.
A last question may be answered as well:
With the full outline where I have the problem, would it be best to
implement one parser to get either a statement or a boolean expression
and test against expecting one of these, or keep it as simple with
two?
Thanks,
Lothar