.foreach_part Macro

This macro iterates through and transforms the parts of the input template, with the parts delimited by a separator pattern.

.foreach_part (expression [,"separator" [,head [,tail]]])
	simple-template
.next[(separator)]

This macro creates a new scope wherein the local variable CurrentPart is defined to be the i-th part of the input template at iteration i. The Separator local variable contains the following separator.

This macro is often used in applying naming conventions (see "Naming Conventions" in Chapter 8, Customizing Your Modeling Environment of the Core Features Guide ).

The following parameters are available:

Parameter

Description

input

Input text over which iteration is performed

Type: Simple template

separator-pattern

Char and word separators


  • Any character specified in the pattern can be used as separator

  • [<c1> - <c2>] specifies a character within the range defined between both characters <c1> and <c2>

For example, the pattern " -_,[A-Z]" specifies that each part can be separated by a space, a dash, an underscore, a comma or a character between A and Z (in capital letter).

By default, the <separator-pattern> is initialized with the pattern (). If the specified pattern is empty, the pattern is initialized using the default value.

A separator <separator> can be concatenated between each part. <head> and <tail> expressions can be added respectively at the bottom or at the end of the generated expression.

There are two kinds of separator:


  • Char separator - for each char separator, the separator specified in the next statement of the macro is returned (even for consecutive separators)

  • Word separator - they are specified as interval, for example [A-Z] specifies that all capital letters are separator. For a word separator, no separator (specified in next statement) is returned

Default: " -_,\t"

Type: Text

head

[optional] Generated before output, if there is one

Type: Text

tail

[optional] Appended to the output, if there is one

Type: Text

simple-template

Template to apply to each part.

Type: Complex template

separator

[optional] Generated between non empty evaluations of complex-template

Type: Text

Examples:

Convert a name into a class code (Java naming convention). In the following example, the variable %Name% is equal to Employee shareholder, and it is converted to EmployeeShareholder:

.foreach_part (%Name%, " _-'")
	%.FU:CurrentPart%
.next

Convert a name into a class attribute code (Java naming convention). In the following example, the variable %Name% is equal to Employee shareholder, and it is converted to EmployeeShareholder:

.set_value(_First, true, new)
.foreach_part(%Name%,"' _-'")
	.if (%_First%)
		%.L:CurrentPart%
		.set_value(_First, false, update)
	.else
		%.FU:CurrentPart%
	.endif
.next