Again, thanks for the quick response.  I switched over to the
StringAttribute from Parameter.  I still seem to get embedded
newlines stripped.  "\n" escape remains "\n" in the resulting string.
Editing the xml to test results in the elimination of the embedded newline:

<property name="scenarioPrefire" class="ptolemy.kernel.util.StringAttribute" value="hello
world">
</property>
becomes "hello world" when viewed in Vergil.


Is there an appropriate encoding of newline that will survive?

Thanks again - Jim

PS, I am on the hackers email list so no need to copy both me and the list.

Stephen Andrew Neuendorffer wrote:

A ptolemy.kernel.util.StringAttribute is very similar to a Parameter in terms of how it appears in Vergil, and in the XML file.
The difference is that StringAttribute always contain a literal, unprocessed string. In contrast, the
string contained in a parameter is parsed and interpreted as an expression. Expressions that start and end with
double quotes are interpreted as strings and turned into StringTokens. During this interpretation, the standard set
of backslash escapes is converted into characters.


If you are writing your own actors in Java, then it is a relatively simple matter to use a StringAttribute instead of a
Parameter... StringAttributes do not have token types, so calling setTypeEquals() is not necessary. The string
contained in the attribute is retrieved by the getExpression() method.


If you are making this change to an existing Java actor, then you will likely need to edit (by hand...) the XML of any models as well..


If you are trying to do this to an existing library actor (say the Const actor), then the above solution doesn't really work...
Christopher thinks that we've had this discussion before, so we're going to sit down and try to come up with a better solution
for library actors...


Steve

At 10:35 AM 3/19/2003 -0800, Jim Kleckner wrote:

Thanks for the quick response.  I presume then that to set this
attribute would require directly editing the xml file since Vergil
would not expose the StringAttribute as a visible (and therefore
configurable) attribute.  Is that true?

Thanks - Jim

Stephen Andrew Neuendorffer wrote:

Assuming you are writing your own actor, the easiest way to deal with this is to
use a StringAttribute instead of a Parameter.


This issue comes up in other contexts as well... for example, if you have a string with
octal codes in it, the expression parser properly substitutes them into the string,
However, StringToken does not convert non-printable characters back into escape codes...


Steve

At 10:11 AM 3/19/2003 -0800, Jim Kleckner wrote:

Is there a clean way to pass a string parameter to an
actor without it being interpreted as an expression?  I
have a situation where I want the actor to do the
interpretation, complete with semantically significant
embedded newlines.  If I enter something with "\" and
\"" surrounding the text, it will get entered.  But all
the newlines appear stripped.

Suggestions?  I suppose I can read it from a file
instead but it is a bit indirect.

Thanks - Jim



----------------------------------------------------------------------------

Posted to the ptolemy-hackers mailing list. Please send administrative
mail for this list to: [EMAIL PROTECTED]






----------------------------------------------------------------------------


Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]






---------------------------------------------------------------------------- Posted to the ptolemy-hackers mailing list. Please send administrative mail for this list to: [EMAIL PROTECTED]

Reply via email to