Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: andymc73 on May 09, 2007, 05:23:23 pm

Title: Problem with MDA transform double quotes
Post by: andymc73 on May 09, 2007, 05:23:23 pm
Hi

I have a class with notes like:

  This is "something"

When I try an MDA transform on it, the transform fails.  The exact error varies but it is usually of the form:

  Unexpected symbol: something

Where 'something' was the thing in double quotes in the class notes.

I found several similar posts to do with escaping backslashes etc. but nothing that handles double quotes.

I tried to strip double quotes from the notes using various combinations of %REPLACE($notes,"\"","")% along the lines of C++ etc but none of them work.

Basically the problem seems to be:

1. Macros (e.g. replace) dont understand %qt%. Thus, %REPLACE($somevar,"%qt%","XXX")% fails, as does %REPLACE($somevar,%qt%,"XXX")%

2. Backslash escapes dont work for \".  Why would the program work for \t and \n but not for everything else which is a special character?

I hope there is a solution for this, other than "Dont use quotes in notes". This needs to be robust.

tia
--Andrew
Title: Re: Problem with MDA transform double quotes
Post by: Eve on May 09, 2007, 08:00:06 pm
Yes, there is a way, and you were close.

Firstly, parameters to function macros can be other (simple) macros, but they have the percent characters removed in this situation.

ie. %REPLACE($somevar,qt,"XXX")%

However, %qt%, %dl% and %pc% can't be used in this context.

But you can assign them to a variable and then do the replace.

$quote = %qt%
%REPLACE(classNotes, $quote, "\"")%
Title: Re: Problem with MDA transform double quotes
Post by: andymc73 on May 16, 2007, 09:35:36 pm
That works really well

Thank you! :D
Title: Re: Problem with MDA transform double quotes
Post by: Adam on August 20, 2007, 11:14:58 pm
Ahh, but what if you are trying to replace \ with / ? for example to generate proper c++ includes...

to define a '\' character is impossible, you cannot go:
$backslash = "\"

you need to be a smartass:
$backslash = %TRIM("\ ")%

so the resulting code in my situation is:
$RSFileImports = %fileImports%
$backslash = %TRIM("\ ")%
$RSFileImports = %REPLACE($RSFileImports,$backslash,"/")%
$RSFileImports
Title: Re: Problem with MDA transform double quotes
Post by: glen_kidd on August 20, 2007, 11:23:31 pm
And I thought my dumb*ss solution was cool:

Quote
$RSFileImports = %REPLACE($RSFileImports,"\a","/a")%
$RSFileImports = %REPLACE($RSFileImports,"\b","/b")%
...


Score 1 point for Adam... Total so far Adam 1; EA 93948 :P