Transformations
One of the core features of XSharper is support for text transformations, which are controlled by transform (or, shortened, tr) attribute of almost all actions.
This attribute controls:
- text whitespace trimming (start, end, internal, every line )
- replacing (~ may be replaced with spaces, non-printable characters with . dot, curved or square braces with angled, CRLF to LF or vice versa and so on)
- character escaping (for XML, or C-like, or regular expressions)
- expression expansions (whether expressions defined as ${var} or ${{var}} or [[var]] are evaluated and result inserted into text)
- order in which the escaping and trimming is done (after or before variable expansion)
<!-- PRINT.XSH -->
<print tr="trim squareToAngle">
[xml]I hate writing all these > and < but sometimes it's easier to use square brackets and replace them with angle[/xml]
</print>
<set firstName="Michael" />
<set lastName="Parker" />
<print>----BEGIN --</print>
<print tr="trim multiLine expandSquare">
Dear [firstName] [LastNAME],
Best regards,
XSharper development team
</print>
<print>----END --</print>
Default transformation is Expand, i.e. expand multi-expressions formatted as ${multi}
Another note is that transformation applies to all text attributes of an action, including the value. It's possible to explicitly exclude the value by setting verbatim="true" attribute.
<set text="Michael" />
<!-- Prints Name is: Michael -->
<print tr="expand">Name is: ${text}</print>
<!-- Prints Name is: ${text} -->
<print tr="expand" verbatim="true">Name is: ${text}</print>
Complete list of transformations can be obtained as
C:\>xsharper /? transformRules
XSharper v.0.9.1243.0 DeltaX Inc. Copyright (c) 2006-2010
enum TransformRules (XSharper.Core.TransformRules)
Enum values:
None 0x0000000000 No expansion
Expand 0x0000000001 Expand ${variables}
ExpandDual 0x0000000003 Expand variables formatted as ${{var}}
ExpandSquare 0x0000000005 Expand variables formatted as [var]
ExpandDualSquare 0x0000000009 Expand variables formatted as [[var]]
ExpandReplaceOnly 0x0000000011 Do replacements only in expanded text
ExpandTrimOnly 0x0000000021 Trim expanded text only
ExpandAfterTrim 0x0000000081 Trim first, expand later
TrimBeforeExpand 0x0000000081 Trim first, expand later
ExpandMask 0x00000000ff Expand flags mask
TrimStart 0x0000000100 Trim whitespace at the beginning of the string
TrimEnd 0x0000000200 Trim whitespace at the end of the string
Trim 0x0000000300 Trim whitespace at the beginning and at the end of the string
TrimInternal 0x0000000400 Trim internal whitespace
Multiline 0x0000000800 Treat the string as multiline, and do processing of each line
TrimMask 0x0000000f00 All trim flags mask
TildaToSpace 0x0000010000 Replace ~ with space
BackqToDouble 0x0000020000 Replace ` with "
CurvedToAngle 0x0000040000 Replace { with < , and } with >
SquareToAngle 0x0000080000 Replace [ with < , and ] with >
NewLineToLF 0x0000100000 Replace new lines with a single LF
NewLineToCRLF 0x0000200000 Replace new line with CR LF
DoubleSingleQuotes 0x0000400000 Convert ' to '' (useful for SQL)
DoubleDoubleQuotes 0x0000800000 Convert " to "" (useful for C#)
EscapeXml 0x0001000000 Escape all XML special characters
QuoteArg 0x0002000000 If the string contains spaces, wrap it in double quotes. Internal double quotes are replaced with "
EscapeRegex 0x0004000000 Escape all special regex characters
RemoveControl 0x0008000000 Replace all non-ASCII characters with . (dot)
UnescapeC 0x0010000000 Unescape C# strings, e.g. \n => newline
EscapeC 0x0020000000 Escape C# strings, e.g. newline character => \n etc
TabToSpaces2 0x0040000000 Tabs to spaces (counting tab as 2 spaces)
TabToSpaces4 0x0080000000 Tabs to spaces (counting tab as 4 spaces)
TabToSpaces8 0x00c0000000 Tabs to spaces (counting tab as 8 spaces)
ReplaceMask 0x00ffff0000 All replace flags
Default 0x0000000001 Default transformation