Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > String and replace {placeholder} recursion problem

Reply
Thread Tools

String and replace {placeholder} recursion problem

 
 
Lothar Behrens
Guest
Posts: n/a
 
      04-19-2011
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
va_arg... recursion: changing arguments and the using recursion jononanon@googlemail.com C Programming 8 04-26-2012 08:37 PM
Replace /n with a XHTML <br /> using string.replace Alun ASP .Net 3 02-18-2008 05:52 AM
how to make replace function replace globally in a string V S Rawat Javascript 5 07-03-2007 08:02 PM
replace a string delimited by 2 other string, regexp problem Sébastien Maurette Ruby 3 10-02-2006 09:40 PM
help with string replace - for doing selective replace Prasad S Javascript 2 08-27-2004 03:22 PM



Advertisments