This manual is for the String NodeBrain Module (version 0.9.03, December 2014) used for string manipulation.
Copyright © 2014 Ed Trettevik <eat@nodebrain.org>
Permission is granted to copy, distribute and/or modify this document under the terms of either the MIT License (Expat) or NodeBrain License. See the Licenses section at the end of this document for details.Short Table Of Contents
The String module implements nodes that manipulate strings in some way.
This is initially a very minimal set of evaluation methods.
NodeBrain is not intended to perform string manipulation with the goal of
producing output for human consumption. However, it is helpful to have
some string manipulation capability to consume text representations of events.
Regular expressions provide the functionality needed to extract information
from text. Once extracted, we sometimes need to transform the extracted
strings. In general, it is best to delegate this function to servants
using your favorate string manipulation language. But where we see a repeating
need for a simple string manipulation, additional skills will be added to
this module.
Regular expression based substitution supported by the PCRE library will
most likely be included in the language in a future release. The operations
provided by this module are expected to be less complex and more special
purpose.
Generosity with strings is not generosity; It is a deal. —Marya Mannes
Here's the deal with NodeBrain strings.
Translators and regular expressions are used to recognize and take strings apart and symbolic substitution is used to
construct new strings. Tree nodes can be used to translate strings by looking up one string
and substituting another. But that's about the limit of NodeBrain's generosity with strings.
The string module exists to enable additional string manipulation capability as needed to digest
input event attributes for processing with rules. So far, little has been needed, and this is a trivial module.
The following example illustrates how a string.utc
node can be used to transform a time stamp in a broken down
format into a UTC time string. This transformation is based on the strptime C function.
> define utc node string.utc; > define whenUtc cell utc(when,"%Y-%m-%d %H:%M:%S"); > assert when="2012-06-19 10:20:35"; > assert x=whenUtc; # force evaluation of whenUtc since there is no rule depending on it > show x; x = "1340101235" > assert when="2012-05-12 12:15:50"; > assert x=whenUtc; > show x; x = "1336824950" |
The next example might apply in a case where a string value is to be used in an output alarm passed to an application where ";" has a special meaning. A
string.chrsub
node is used
to substitute a "," for any ";" in the string.
> define chrsub node string.chrsub; > define clean cell chrsub(dirty,";,"); > assert dirty="There is always hope; at least for now."; > assert x=clean; # force evaluation of clean since there is no rule depending on it > show x; x = "There is always hope, at least for now." |
This section describes commands used with a String node.
The define command is used to create String manipulation nodes. Although any term can be defined for a String node, using the skill name for the term is generally a good idea.
Syntax
|
String manipulation cells use String nodes to perform operations on string operands and/or produce strings.
Syntax
|
The chrsub
node substitutes one character for another in a string.
strsub(text,"xy") # character x replaces y strsub(text,"xyab") # character x replaces y and a replaced b |
The utc
node converts a time string into UTC time. See the man page for strptime for a description of the format string.
utc("2001-11-12 18:31:01","%Y-%m-%d %H:%M:%S") utc(mytimestamp,"%Y-%m-%d %H:%M:%S") |
Assertions are not supported by this module.
This module does not implement node commands.
This module does not implement module commands.
This module does not implement triggers.
NodeBrain is free software; you can modify and/or redistribute it, including this document, under the terms of either the MIT License (Expat) or the NodeBrain License.
MIT License
Copyright © 2014 Ed Trettevik <eat@nodebrain.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
NodeBrain License
Copyright © 2014 Ed Trettevik <eat@nodebrain.org>
Permission to use and redistribute with or without fee, in source and binary forms, with or without modification, is granted free of charge to any person obtaining a copy of this software and included documentation, provided that the above copyright notice, this permission notice, and the following disclaimer are retained with source files and reproduced in documention included with source and binary distributions.
Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.