Issue Comparing Rich Text Strings

I am having a issue comparing rich text. For example, when I have two objects with identical "Object Text". I save the contents of the "Object Text" into two strings using the function richText(). When Icompare them, the result is the text are not equal. I have printed out the strings and have confirmed that the strings are identical. Thanks for the help!

Dave
stoll12 - Wed Feb 08 16:11:55 EST 2012

Re: Issue Comparing Rich Text Strings
llandale - Wed Feb 08 17:05:41 EST 2012

The raw text can be the same but the rich-text not. If you are really printing the rich text and they appear the same, then perhaps do this instead:
  • print (length(t1)) ":\t[\n"
  • print (length(t2)) ":\t[\n"
I'll bet you see one has an extra space in there somewhere.

  • Louie

Re: Issue Comparing Rich Text Strings
Mathias Mamsch - Thu Feb 09 04:30:07 EST 2012

Just a hunch: A common pitfall in DXL is:
 

Object o1, o2
 
if (o1."Attr" != o2."Attr") print "This will always be true!"
if (o1."Attr" "" != o2."Attr" "") print "This will check for inequality of the contents!"

The reason is that Object.string returns an attribute reference (Attr__) and that DOORS will compare the two attribute references, not their content, because there is not comparison operator for Attr__ defined.


With richText there might be the same problem. There are two perms defined for richText, which are ambiguous.

 

string richText (Attr__)
RTF_string__ richText (Attr__)
RTF_buffer__ richText (Attr__)


That makes it dangarous to use it in expressions. Therefore if you wrote:

 

 

if (richText o."Attr1" == richText o."Attr2") ...


you might have used the string variant, and therefore get the correct comparison, but you also might have used one of the other variants which will always return false, since they will always return two different attribute references and the comparison operator will not compare the contents.

This is just a hunch, Regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Issue Comparing Rich Text Strings
llandale - Thu Feb 09 11:31:44 EST 2012

llandale - Wed Feb 08 17:05:41 EST 2012
The raw text can be the same but the rich-text not. If you are really printing the rich text and they appear the same, then perhaps do this instead:

  • print (length(t1)) ":\t[\n"
  • print (length(t2)) ":\t[\n"
I'll bet you see one has an extra space in there somewhere.

  • Louie

Must preview...
  • print (length(s1)) ":\t[" s1 "]\n"
  • print (length(s2)) ":\t[" s2 "]\n"

Mathias is correctly suggesting do this:
  • string s1 = richText(o.Name1)
  • string s2 = richText(o.Name2)
  • if (s1 != s2)
instead of this:
  • if (richText(o.Name1) != richText(o.Name2))
-Louie