strexpr Expressions

This expression provides string processing capabilities on an expression sequence. The strexpr expression has the following general form:

<strexpr expr=”...”>
	<arg> <!-- some expression sequence --> </arg>
	<arg> <!-- some expression sequence --> </arg>
	...
	<arg> <!-- some expression sequence --> </arg>
</strexpr>

The value of this expression depends on the string operation that is specified through the expression string, i.e., the expr attribute. This also dictates the number of arguments (i.e., the number of <arg> elements) that the strexpr expression should have.

The following lists the available operations and their arguments.

charAt:

<strexpr expr=”charAt”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- index					 --> </arg>
</strexpr>

It returns the character of the source string at the specified index. The index must be in 0 and (the length of the source string minus 1).

contains:

<strexpr expr=”contains”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- string to search --> </arg>
	<arg> <!-- value to return if true --> </arg>
	<arg> <!-- value to return if false --> </arg>
</strexpr>

Evaluates containment of the string to search within the source string. It returns the evaluated expression sequence for the third argument when the source string contains the string to search, otherwise it returns the evaluated expression sequence for the fourth argument.

extract:

<strexpr expr=”extract”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- start --> </arg>
	<arg> <!-- length --> </arg>
</strexpr>

Returns the characters that are in the range start and (start + length) of the source string.

findAndReplace:

<strexpr expr=”findAndReplace”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- old text --> </arg>
	<arg> <!-- new text --> </arg>
	<arg> <!-- string to return if no replace --> </arg>
</strexpr>

Replaces all the occurrences of old text with new text in the source string. The 4th argument is optional, it allows the expression to return an alternate evaluated expression sequence when no old text is present in the source string. Both new text and old text are fixed strings. Use regexReplace for regular expression support.

first:

<strexpr expr=”first”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- text to search --> </arg>
</strexpr>

Returns the index of the first occurrence of the text to search in the source string, or the empty string if the text to search is not found.

last:

<strexpr expr=”last”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- text to search --> </arg>
</strexpr>

Returns the index of the last occurrence of the text to search in the source string, or the empty string if the text to search is not found.

leftOf:

<strexpr expr=”leftOf”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- index --> </arg>
</strexpr>

Returns the sub-string left of the specified index in the source string; the empty string is returned if the index is out of range.

leftOfString:

<strexpr expr=”leftOfString”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- separator --> </arg>
</strexpr>

Returns the sub-string left of the first separator in the source string; the empty string is returned if the separator is absent in the source string.

length:

<strexpr expr=”length”>
	<arg> <!-- source string --> </arg>
</strexpr>

It returns the character length of the source string.

normalizeBoolean:

<strexpr expr=”normalizeBoolean”>
 	<arg> <!-- source string --> </arg>
 </strexpr>

Returns “true” for “1” or “TRUE” regardless of its casing, and “false” for “0” or “FALSE” regardless of its casing; otherwise, it returns the original source string if the Boolean value cannot be normalized.

normalizeWhitespace:

<strexpr expr=”normalizeWhitespace”>
	<arg> <!-- source string --> </arg>
</strexpr>

Returns the source string with all consecutive whitespace, tabs, line feeds, and spaces collapsed into a single space.

padLeading:

<strexpr expr=”padLeading”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- target length --> </arg>
	<arg> <!-- pad char --> </arg>
</strexpr>

Pads the beginning of the source string with the pad char character until the resulting string length equals target length. Only the first character of pad char is taken when pad char length is > 1.

padTrailing:

<strexpr expr=”padTrailing”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- target length --> </arg>
	<arg> <!-- pad char -->			 </arg> 
</strexpr>

Pads the end of the source string with the pad char character until the resulting string length equals target length. Only the first character of pad char is taken when pad char length is > 1.

regexMatch:

<strexpr expr=”regexMatch”>
	<arg> <!-- regular expression --> </arg>
	<arg> <!-- source string --> </arg>
</strexpr>

Returns either the string ‘true’ or ‘false’ depending on whether the regular expression matches the entire source string. The regular expression supports Perl Compatible Regular Expressions (PCRE).

regexReplace:

<strexpr expr=”regexReplace”>
	<arg> <!-- matching regular expression --> </arg>
	<arg> <!-- source string --> </arg>
	<arg> <!-- replacement regular expression --> </arg>
	<arg> <!-- optional return value if no matches --> </arg>
</strexpr>

Returns the result of replacing all occurrences of matching regular expression with replacement regular expression in source string. If there are no matches and if the optional 4th argument is absent then the source string is returned untouched, otherwise the value for the 4th argument is returned. The regular expressions support Perl Compatible Regular Expressions (PCRE).

rightOf:

<strexpr expr=”rightOf”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- index --> </arg>
</strexpr>

Returns the sub-string right of the specified index in the source string; the empty string is returned if the index is out of range

rightOfString:

<strexpr expr=”rightOfString”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- separator --> </arg>
</strexpr>

Returns the sub-string right of the first separator in the source string; the empty string is returned if the separator is absent in the source string.

remove:

<strexpr expr=”remove”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- start -->				 		</arg>
	<arg> <!-- length -->		 </arg>
</strexpr>

Removes the characters in the range of start to (start + length) from the source string.

toLower:

<strexpr expr=”toLower”>
	<arg> <!-- source string --> </arg>
</strexpr>

Returns the source string converted to lowercase.

toUpper:

<strexpr expr=”toUpper”>
	<arg> <!-- source string --> </arg>
</strexpr>

Returns the source string converted to uppercase.

trim:

<strexpr expr=”trim”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- char to trim --> </arg>
</strexpr>

Trims all of the leading and trailing char to trim characters from the source string. If value of the char to trim argument is whitespace, for example, <arg> <literal expr=”whitespace”/> </arg>, then leading and trailing whitespaces will be removed from the source string.

trimLeading:

<strexpr expr=”trimLeading”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- char to trim --> </arg>
</strexpr>

Trims all of the leading char to trim characters from the source string.

trimTrailing:

<strexpr expr=”trimTrailing”>
	<arg> <!-- source string --> </arg>
	<arg> <!-- char to trim --> </arg>
</strexpr>

Trims all of the trailing char to trim characters from the source string.

Example

The example below illustrates several of the strexpr expression operations. Please refer to the comments in the strexpr.xmp for the details.

strexpr.xml

<?xml version=”1.0”?>
<strings>
	<id>78</id>
	<date>05,12,1999</date>
</strings>

strexpr.xmp

<?xml version=”1.0”?>
<!DOCTYPE xfMap SYSTEM ”xfMap.dtd”>

<xfMap>
	<feature-map>
		<mapping match=”strings”>
			<define>
				<let name=”featType”>
					<!-- define the ‘featType’ expression sequence
						to be an id of exactly 15 digits. Pad it with leading 0’s
						until the results length is 15 digits. -->
					<strexpr expr=”padLeading”>
					<arg> <extract expr=”./id”/> </arg>
					<arg> <literal expr=”15”/> </arg>
					<arg> <literal expr=”0”/> </arg>
				</strexpr>
				</let>
			</define>
			
			<feature-type> <defnval expr=”featType”/> </feature-type>
			
			<attributes>
				<attribute>
					<name> <literal expr=”date”/> </name>
					<value>
						<!-- Replace all the commas in the date element content
							by a dash -->
						<strexpr expr=”findAndReplace”>
						<arg> <extract expr=”./date”> </arg>
						<arg> <literal expr=”,”/> </arg>
						<arg> <literal expr=”-”/> </arg>
				    </strexpr>
					</value>
				</attribute>
				
				<attribute>
					<name> <literal expr=”orig-id”/> </name>
					<value>
						<!-- trim off all leading 0’s from the featType 
							expression sequence -->
						<strexpr expr=”trimLeading”>
						<arg> <defnval expr=”featType”/> </arg>
						<arg> <literal expr=”0”/> </arg>
				   </strexpr>
					</value>
				</attribute>

				<attribute>
					<name> <literal expr=”featType-length”/> </name>
					<value> 
						<!-- the length of the featType expression sequence -->							
						<strexpr expr=”length”>
						<arg> <defnval expr=”featType”/> </arg>
				   </strexpr>
					</value>			
				</attribute>
			</attributes>			
		</mapping>
	</feature-map>
</xfMap>

FME feature constructed:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Feature Type: `000000000000078'                                            
Attribute: `date' has value `05-12-1999'                                   
Attribute: `featType-length' has value `15'                                
Attribute: `orig-id' has value `78'                                        
Attribute: `xml_type' has value `xml_no_geom'                              
Geometry Type: Unknown (0)                                                 
===================================================================