String and replace {placeholder} recursion problem

Discussion in 'C++' started by Lothar Behrens, Apr 19, 2011.

  1. 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
     
    Lothar Behrens, Apr 19, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alun
    Replies:
    3
    Views:
    4,536
    Masudur
    Feb 18, 2008
  2. nail

    Build control in a placeholder or like a placeholder

    nail, Sep 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    346
  3. Prasad S
    Replies:
    2
    Views:
    240
    Dr John Stockton
    Aug 27, 2004
  4. V S Rawat
    Replies:
    5
    Views:
    315
    Richard Cornford
    Jul 3, 2007
  5. Replies:
    8
    Views:
    752
    John Reye
    Apr 26, 2012
Loading...

Share This Page