|Prev - Next - Down||SDMetrics - the UML design measurement tool|
<metric name="width_string" domain="diagramelement"> <substring source="geometry" separator="','" position="2"/> </metric>Attribute source specifies a metric expression that yields the string we want to dissect. Attribute separator specifies the separator string, which can be of any length. This will usually be just a string constant, so it needs to be enclosed in single quotes (see Section 188.8.131.52 "Constants"). In our example, the separator is a single comma, which will split the string "206, 320, 69, 13" into four parts: "206", "320", "69", and "13". Leading or trailing whitespaces are automatically trimmed from each substring.
With the position parameter, we tell SDMetrics which substring we want; the first substring is at position 0, position 2 yields the third value, "69". With negative positions -1, -2, etc. we can access the last substring, last but one substring, and so on, without having to know how many substrings there are. The default value for attribute position is -1 (return the last substring).
Often we do not want to use the substring as is, but process it further, e.g., retrieve its numerical value. We can do this directly with the optional attribute result. The following metric extracts the first value of a comma-separated list and converts it to a number:
<metric name="left" domain="diagramelement"> <substring source="geometry" separator="','" position="0" result="parsenumber(_value)"/> </metric>Attribute result specifies a metric expression, variable _value contains the value of the substring we extracted.
In a source string such as "Left=620 ; Top=743 ; Right=732 ;", the beginning and end of the interesting substrings are delimited by different separators. The optional argument endseparator deals with this situation:
<metric name="top" domain="diagramelement"> <substring source="location" separator="'Top='" endseparator="';'" result="parsenumber(_value)"/> </metric>The separator 'Top=' cuts up the source string into two substrings: "Left=620 ;" and "743 ; Right=732 ;". Of these, we use the second (last) substring, because the position argument is missing. The attribute endseparator="';'" instructs SDMetrics to cut off the substring at the first semicolon. After automatic trimming of whitespace, this leaves us with the string "743", which then gets converted to the number 743.
The "substring" procedure has the following attributes:
|Section 8.1.8 "Subelements"||Contents||Section 8.2 "Definition of Sets"|