$UnSpace: Difference between revisions
mNo edit summary |
EllieWiccan (talk | contribs) (Automatically generated page update) |
||
(31 intermediate revisions by 3 users not shown) | |||
Line 2: | Line 2: | ||
<span class="pageSubtitle">Normalize spaces and quotes</span> | <span class="pageSubtitle">Normalize spaces and quotes</span> | ||
<p class=" | <p class="warn"><b>Note: </b>Many $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $UnSpace function is the <var>[[Unspace (String function)|Unspace]]</var> function.</p> | ||
This function normalizes a string by removing leading and trailing "space" characters and collapsing other sequences of "unquoted" spaces to single spaces. Normalization can also "undouble" quoted quote characters. | This function normalizes a string by removing leading and trailing "space" characters and collapsing other sequences of "unquoted" spaces to single spaces. Normalization can also "undouble" quoted quote characters. | ||
Line 8: | Line 8: | ||
The $UnSpace function accepts three arguments and returns a string result which is the first argument, normalized according to the description of the returned value, as shown below. | The $UnSpace function accepts three arguments and returns a string result which is the first argument, normalized according to the description of the returned value, as shown below. | ||
==Syntax== | |||
<p class="syntax"><span class="term">%out</span> = <span class="literal">$UnSpace</span>(<span class="term">input</span>, <span class="term">spaces</span>, <span class="term">quotes</span>) | |||
</p> | |||
===Syntax terms=== | |||
<table> | |||
<tr><th>%out</th> | |||
<td>This string is set to the normalized value of <var class="term">input</var>.</td></tr> | |||
<tr><th>input</th> | |||
<td>The string to be normalized. </td></tr> | |||
<tr><th>spaces</th> | |||
<td>A string that is the set of space characters. The first character of this string is the replacement space character. The default set of space characters is the blank character. </td></tr> | |||
<tr><th>quotes</th> | |||
<td>A string that is the set of quote characters. If a quote character occurs twice in succession in <var class="term">quotes</var>, the quote character should be "undoubled" when it occurs within a string quoted by that same character (see the usage note, below). | |||
<p> | |||
No quote character may also occur as a space character. </p> | |||
<p> | |||
The default is that there are no quote characters. </p></td></tr> | |||
</table> | |||
The returned value is the string value of argument | ==Usage notes== | ||
<ul> | |||
<li>The returned value is the string value of the <var class="term">input</var> argument, normalized as follows: | |||
<ul> | <ul> | ||
<li>Leading space characters are removed. If there is not an unmatched quote, trailing space characters are removed. | <li>Leading space characters are removed. If there is not an unmatched quote, trailing space characters are removed. | ||
If a quote character is not matched, the rest of the input is quoted. | <li>Within a quoted substring, spaces are not collapsed nor replaced. If the quote character introducing the substring is specified as two occurrences in the <var class="term">quotes</var> argument, each pair of consecutive occurrences of that character in the substring is replaced by a single occurrence of that character. | ||
<p> | |||
If a quote character is not matched, the rest of the input is quoted. </p> | |||
<li>Outside quoted substrings, each sequence of length one or more of any mixture of space characters is replaced by a single occurrence of the replacement space character. | <li>Outside quoted substrings, each sequence of length one or more of any mixture of space characters is replaced by a single occurrence of the replacement space character. | ||
</ul> | |||
</ul> | </ul> | ||
== | ==Examples== | ||
Several examples follow, each one showing an invocation of $UnSpace and the corresponding result. | Several examples follow, each one showing an invocation of $UnSpace and the corresponding result. | ||
<ol> | |||
<li>With only one argument, $UnSpace simply removes leading and trailing blank sequences and collapses other blank sequences: | |||
<p class="code">$UnSpace(' A B C ') </p> | |||
The result is: <code>A B C</code> | |||
< | <li><var>$UnSpace</var> can be used to make all space characters the same; here the space characters include the letters "X" and "S" and the blank character; they are all replaced by the letter "X": | ||
</ | |||
< | <p class="code">$UnSpace(' ASSSBSSXC ', 'XS ') </p> | ||
The result is: <code>AXBXC</code> | |||
< | <li>Within a quoted substring, spaces are not changed: | ||
<p class="code">$UnSpace('."XAX"XBX', '.X', '"')</p> | |||
The result is: <code>"XAX".B</code> | |||
< | <li>An unmatched quote (which is therefore, by definition, a trailing unmatched quote), causes the remander of the string to be quoted: | ||
<p class="code">$UnSpace('".A..."..B...C.."..', '.', '"') </p> | |||
The result is: <code>".A...".B.C."..</code> | |||
< | <li>Doubling a quote character in the <var class="term">quotes</var> argument causes undoubling of quotes within a string quoted by that character: | ||
</ | |||
<p class="code">$UnSpace('" "" "', , '""') </p> | |||
The result is: <code>" " "</code> | |||
<p class="code"> $UnSpace('" "" "', , '""') | |||
</ | |||
The following two inputs produce the same output; the first is a null quoted substring followed by the letter A and a final unmatched quote; the second is a quoted string whose first pair of characters is a doubled quote: | <li>The following two inputs produce the same output; the first is a null quoted substring followed by the letter A and a final unmatched quote; the second is a quoted string whose first pair of characters is a doubled quote: | ||
<p class="code"> $UnSpace('""A"', , '""') | <p class="code">$UnSpace('""A"', , '""') </p> | ||
The result is: <code>""A"</code> | |||
<p class="code">$UnSpace('"""A"', , '""') </p> | |||
The result is: <code>""A"</code> | |||
</ | |||
If a quote character is not doubled in argument 3, undoubling for it is not performed: | <li>If a quote character is not doubled in argument 3, undoubling for it is not performed: | ||
<p class="code"> $UnSpace('" "" "', , '"') | <p class="code">$UnSpace('" "" "', , '"') </p> | ||
The result is: <code>" "" "</code> | |||
</ | |||
Multiple quote characters can be specified; a quote character inside a substring quoted by a different character is not undoubled: | <li>Multiple quote characters can be specified; a quote character inside a substring quoted by a different character is not undoubled: | ||
<p class="code">$UnSpace('./A$$B/..$C//D$../E//F.', '.', '$$//') </p> | |||
The result is: <code>/A$$B/.$C//D$./E/F.</code> | |||
</ol> | |||
==Products authorizing {{PAGENAMEE}}== | |||
<ul class="smallAndTightList"> | <ul class="smallAndTightList"> | ||
<li>[[Sirius functions]]</li> | <li>[[List of $functions|Sirius functions]]</li> | ||
<li>[[Fast/Unload User Language Interface]]</li> | <li>[[Fast/Unload User Language Interface]]</li> | ||
<li>[[Janus Open Client]]</li> | <li>[[Media:JoclrNew.pdf|Janus Open Client]]</li> | ||
<li>[[Janus Open Server]]</li> | <li>[[Media:JosrvrNew.pdf|Janus Open Server]]</li> | ||
<li>[[Janus Sockets]]</li> | <li>[[Janus Sockets]]</li> | ||
<li>[[Janus Web Server]]</li> | <li>[[Janus Web Server]]</li> | ||
<li> | <li>Japanese functions</li> | ||
<li>[[Sir2000 Field Migration Facility]]</li> | <li>[[Media:SirfieldNew.pdf|Sir2000 Field Migration Facility]]</li> | ||
</ul> | </ul> | ||
[[Category:$Functions|$UnSpace]] | [[Category:$Functions|$UnSpace]] |
Latest revision as of 23:27, 20 September 2018
Normalize spaces and quotes
Note: Many $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $UnSpace function is the Unspace function.
This function normalizes a string by removing leading and trailing "space" characters and collapsing other sequences of "unquoted" spaces to single spaces. Normalization can also "undouble" quoted quote characters.
The $UnSpace function accepts three arguments and returns a string result which is the first argument, normalized according to the description of the returned value, as shown below.
Syntax
%out = $UnSpace(input, spaces, quotes)
Syntax terms
%out | This string is set to the normalized value of input. |
---|---|
input | The string to be normalized. |
spaces | A string that is the set of space characters. The first character of this string is the replacement space character. The default set of space characters is the blank character. |
quotes | A string that is the set of quote characters. If a quote character occurs twice in succession in quotes, the quote character should be "undoubled" when it occurs within a string quoted by that same character (see the usage note, below).
No quote character may also occur as a space character. The default is that there are no quote characters. |
Usage notes
- The returned value is the string value of the input argument, normalized as follows:
- Leading space characters are removed. If there is not an unmatched quote, trailing space characters are removed.
- Within a quoted substring, spaces are not collapsed nor replaced. If the quote character introducing the substring is specified as two occurrences in the quotes argument, each pair of consecutive occurrences of that character in the substring is replaced by a single occurrence of that character.
If a quote character is not matched, the rest of the input is quoted.
- Outside quoted substrings, each sequence of length one or more of any mixture of space characters is replaced by a single occurrence of the replacement space character.
Examples
Several examples follow, each one showing an invocation of $UnSpace and the corresponding result.
- With only one argument, $UnSpace simply removes leading and trailing blank sequences and collapses other blank sequences:
$UnSpace(' A B C ')
The result is:
A B C
- $UnSpace can be used to make all space characters the same; here the space characters include the letters "X" and "S" and the blank character; they are all replaced by the letter "X":
$UnSpace(' ASSSBSSXC ', 'XS ')
The result is:
AXBXC
- Within a quoted substring, spaces are not changed:
$UnSpace('."XAX"XBX', '.X', '"')
The result is:
"XAX".B
- An unmatched quote (which is therefore, by definition, a trailing unmatched quote), causes the remander of the string to be quoted:
$UnSpace('".A..."..B...C.."..', '.', '"')
The result is:
".A...".B.C."..
- Doubling a quote character in the quotes argument causes undoubling of quotes within a string quoted by that character:
$UnSpace('" "" "', , '""')
The result is:
" " "
- The following two inputs produce the same output; the first is a null quoted substring followed by the letter A and a final unmatched quote; the second is a quoted string whose first pair of characters is a doubled quote:
$UnSpace('""A"', , '""')
The result is:
""A"
$UnSpace('"""A"', , '""')
The result is:
""A"
- If a quote character is not doubled in argument 3, undoubling for it is not performed:
$UnSpace('" "" "', , '"')
The result is:
" "" "
- Multiple quote characters can be specified; a quote character inside a substring quoted by a different character is not undoubled:
$UnSpace('./A$$B/..$C//D$../E//F.', '.', '$$//')
The result is:
/A$$B/.$C//D$./E/F.