The <custom:rg:delim>
RULE (a.k.a tag) parses a delimited string and returns an iterable %ArrayOfDataTypes
object.
Each object has been assigned to the attribute item
which you can access in each iteration of the tag's loop.
<custom:rg:get:pics>
attributes:
string
: String to parse (required).parent
: Parent delimiter; the default is a|
(pipe).child
: Optional child delimiter.limit
: Limit the number of parsed items returned; the default is0
(no limit).reverse
: Use to reverse the direction of the loop; this attribute does not require a value.key
: The loop key variable name; the default name iskey
.count
: Local loop counter variable name; the default name iscount
.item
: Local item object variable name; the default name isitem
.total
: Local variable name for total number of parent items; the default name istotal
.obj
: Local%ArrayOfDataTypes
object variable name; the default name isobj
.
##class(custom.rg.Delim).parse()
parameters:
string
: String to parse (required).parent
: Parent delimiter; the default is a|
(pipe).child
: Optional child delimiter.limit
: Limit the number of parsed items returned; the default is0
(no limit).
Returns: Parsed string as iterable %ArrayOfDataTypes
object(s).
Check out delim.csp
(and here's the HTML output).
Of course, this goes without saying, but never install "stranger" code on your production system. Always use your test server to play!
With that said, there's a couple ways (that I can think of) to install this code:
- "File" >> "New..." and choose "Caché Class Definition" from the "General" tab.
- Type "custom.rg" as the "package name".
- Type "Delim" as the "class name".
- Copy/paste the RAW contents of
custom.rg.Delim.cls
into this new file. - Save and compile.
- "File" >> "New..." and choose "Caché Server Page" from the "CSP File" tab.
- Copy/paste the RAW contents of
custom.rg.DelimRule.csr
into this new file. - Save this file as
custom.rg.DelimRule.csr
to the "CSP Files" >>/csp/cms/customrules
package/folder/location. - Compile.
- Download and unzip this repo to your local machine.
- Open Studio.
- Change to the
CMS
namespace. - "Tools" >> "Import Local...".
- Import
custom.rg.DelimRule.csr
andcustom.rg.Delim.xml
and check the compile box.
Non-DTI customers should remove these lines from custom.rg.DelimRule.csr
:
-
Remove
dt.common.page.Rule,
from:<csr:class super="dt.common.page.Rule, %CSP.RuleBlock" />
-
<script language="cache" runat="compiler"> do ##this.RenderDTStartTag() </script>
-
<script language="cache" runat="compiler"> do ##this.RenderDTEndTag() </script>
- Trim whitespace around items in a delimited string
- Multi-line string variable?
- Trucate and
$number
? - [2009.1] $list questions: Best/optimal ways to remove empty list items and how to reverse?
- v2.0.1
- 2013/06/27
- Updated/normalized docblocks.
- Changed a few argument names.
- Cleaned up code.
- Added a
limit
attribute/argument. - Fixed a few logic errors.
- Explored my options for limiting/reversing/forwarding items and loops; not enough time to finalize code and will have to revisit.
- 2013/06/27
- v2.0.0:
- 2013/06/27
- Renamed
custom.rg.Delim.csr
tocustom.rg.DelimRule.csr
and updated all references to the old name.
- Renamed
- 2013/06/26
- Second push to GitHub.
- Changed a bunch of stuff. :)
- 2013/06/27
- Pre-v2.0.0
- It's the first commit.
Copyright © 2013 Micky Hulse
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.