Types

Str

String type

Parent types

Constructors

Str(regexp:RegExp)
Represents RegExp
Str(r:Real)
Convert Real to Str
Str(n:Int)
Convert Int to Str
Str(c:NativeMethod)
String representation of native method.
Str(c:Closure)
String representation of a closure
Str(t:Type)
String representation of a type
Str(i:NormalTypeInstance)
String representation of normal type instance i Normal type is a user defined type. In addition some types defined by NGS are also normal types.
Str(r:Range)
Convert range to human readable representation
Str(s:Str)
No-op constructor
Str(n:Null)
Convert Null to string
Str(b:Bool)
Str(a:Arr)
Convert Arr to string
Str(h:Hash)
Convert Hash to string
Str(x:Any, target_width:Int)
Convert anything to Str of a given width
Str(s:Str, target_width:Int)
Pad a string to given width with spaces
Str(n:Int, target_width:Int)
Convert a number to a string and pad it
Str(p:Path)
String representation of a Path (or it's sub-type)
Str(p:Pipe)
Str(f:File)
String representation of File
Str(r:Redir)
TODO
Str(p:Process)
Wait for the process to finish and return its standard output.
Str(s:SubSeq)
Str(rd:ResDef)
Str(r:Res)
Str(r:Vpc)
Str(ds:DelimStr)
Str(i:ArrIter)
Textual representation of ArrIter.
Str(i:HashIter)
Str(kv:KV)
Str(t:TextCollector)

Methods

*(s:Str, n:Int)
Repeat string n times
+(s1:Str, s2:Str)
Concatenate strings
+(s:Str, a:Arr)
Prepend each line in a with s
+(a:Arr, s:Str)
Append s to each line in a
-(s:Str, pfx:Pfx)
Return string without the prefix. Throws MatchFail if pfx is MustPfx but s does not start with it.
-(s:Str, sfx:Sfx)
Return string without the suffix. Throws MatchFail if pfx is MustSfx but s does not end with it.
-(s:Str, r:RegExp)
Returns the string with one occurrence of regexp cut out of it. Throws InvalidArgument if s does not contain r.
.(regexp:RegExp, attr:Str)
Get attributes of a RegExp. Throws AttrNotFound if attr is not one of the allowed values. You should not use this directly. Use "~" and "~~" operators.
.(pa:c_pthread_attr_t, attr:Str)
.(obj:BasicType, attr:Str)
Get BasicType (Int, Arr, Hash, ...) attribute. Throws AttrNotFound.
.(obj:NormalType, attr:Str)
Get NormalType (a type that is typically defined by user) attribute. Throws AttrNotFound.
.(obj:NormalTypeInstance, attr:Str)
Get NormalType (a type that is typically defined by user) instance attribute. Throws AttrNotFound.
.(h:Hash, attr:Str)
Get hash key.
.(a:Arr, attr:Str)
Return array made of given attribute of each element of given array
.(p:Process, attr:Str)
Get process "stdout"
.(p:Process, attr:Str)
Get process "stderr"
.=(obj:NormalTypeInstance, attr:Str, v:Any)
Set Normal type (a type that is typically defined by user) instance attribute. Throws AttrNotFound.
.=(h:Hash, attr:Str, v:Any)
Set hash key.
.=(p:Process, attr:Str, v:Any)
Set process "stdout"
.=(p:Process, attr:Str, v:Any)
Set process "stderr"
/(a:Str, b:Str)
Concatenate two path parts using STDLIB_PATH_SEP (currently "/") but should be platform-specific later.
/(a:Str, b:Str)
Concatenate two path parts using STDLIB_PATH_SEP (currently "/") but should be platform-specific later.
/(a:Str, b:Str)
Concatenate two path parts using STDLIB_PATH_SEP (currently "/") but should be platform-specific later.
//(regexp:Str, flags:Str)
Regular expression constructor. Called by NGS when /myregex/ syntax is used.
<=(a:Str, b:Str)
Case sensitive LessThan or Equal comparison for strings
==(a:Str, b:Str)
Equality comparison
[](lib:CLib, symbol:Str)
Unfinished feature. Don't use!
[](s:Str, range:NumRange)
Get substring
[](s:Str, i:Int)
Get given character (currently byte) of the string
[](s:Str, i:Int)
Get given character (currently byte) of the string. TODO: Document InvalidArgument exception.
[](s:Str, r:NumRange)
Get a substring. Indexes in s are specified by NumRange.
[](s:Str, r:RegExp)
Get substring of a string that corresponds to first match of given regular expression %EX "x10ab20c30y"[/[0-9]+/] # "10"
[]=(s:Str, range:NumRange, replacement:Str)
Change substring
Arg(x:Str)
ArgvMatcher(option:Str, value:Any, f:Closure)
Sets ARGV matching option.
assert(condition:Bool, msg:Str)
Throws AssertFail with givens message if condition is false
assert_resolvable(h:Str, title:Any=Resolve host, times:Any=45, sleep:Any=2, check:Any=(a function))
basename(s:Str)
Get basename of the file. Uses BASENAME(1).
c_access(pathname:Str, mode:Int)
Call ACCESS(2)
c_dlopen(filename:Str, flags:Int)
Unfinished feature. Don't use!
c_execve(filename:Str, argv:Arr, envp:Arr)
c_lseek(fd:Int, offset:Int, whence:Str)
c_lstat(pathname:Str)
Call LSTAT(2)
c_open(pathname:Str, flags:Str)
c_opendir(name:Str)
c_pcre_compile(regexp:Str, flags:Int)
Throws RegExpCompileFail on errors.
c_pcre_exec(regexp:RegExp, subject:Str, offset:Int, options:Int)
Search string for regular expression. Uses PCRE_EXEC(3). Do not use this function directly!
c_stat(pathname:Str)
Call STAT(2)
c_strcasecmp(a:Str, b:Str)
c_strcmp(a:Str, b:Str)
c_write(fd:Int, s:Str)
code(s:Str)
Convert a Str to NGS code that would produce the string when executed. Not fully functional yet. BUG: Does not do escaping.
column(t:Table, k:Str)
compile(code:Str, fname:Str)
Compile NGS source to bytecode.
config(k:Str)
Get configuration for the given key. Lookup order / first wins: (1) Environment variable NGS_$k (2) previously set config(k, v)
config(k:Str, v:Any)
Set configuration. To be used with config(k:Str).
debug(s:Str)
Same as debug('default', s)
debug(facility:Str, s:Str)
Debug to standard error. "DEBUG" environment variable must be non-empty string to activate. Otherwise nothing is outputted. TODO: Not output thread ID if there is only one thread. TODO: Timestamps?
decode_json(s:Str)
Decode (parse) JSON.
die(s:Str, exit_code:Any=1)
Write message in s to standard error and exit
dir(dirname:Str, subtype:Any=false)
List directory contents. Warning: "." and ".." are included. Throws DirFail when directory can not be listed.
dir(dirname:Str, cb:Fun, subtype:Any=false)
List directory contents and call cb with Path() of each found item. Warning: "." and ".." are included.
each(s:Str, cb:Fun)
Iterates over all string characters (currently bytes). TODO: example.
echo(s:Str)
Print given string and a newline to stdout.
echo(fd:Int, s:Str)
Print given string and a newline to a file referenced by descriptor.
encode_hex(s:Str)
Encodes each character in a string as two uppercase hexadecimal digits
encode_html(s:Str)
Encodes HTML. Escapes &, < and > .
encode_html_attr(s:Str)
Encodes HTML attribute. Escapes &, <, >, " and ' .
encode_uri_component(s:Str)
Encodes URI component, escaping with %XX hexadecimal codes.
ends_with(haystack:Str, needle:Str)
Check whether a string ends with another string
error(s:Str)
Write error message to standard error.
fetch(filename:Str, parse_hints:Hash={})
read() and parse() the given file
find_in_path(executable_name:Str)
Finds given binary and returns it's full path. Throws ExecutableNotFound if the binary was not found. Search strategy: "/" in the name of the binary means that given executable_name is a path so it's returned as-is (wrapped in Path). If PATH environment variable exists, the given directories are searched. If PATH is not set built-in value for PATH is used to search: /usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin
get(e:Eachable1, attr:Str)
Return array made of given attribute of each element of given Eachable1 where present
get(e:Eachable1, attr:Str, dflt:Any)
Return array made of given attribute of each element of given Eachable1 where present or default value where the attribute is not present Return array (? depends on map() ?) made of given attribute of each element of given Eachable1
glob(pattern:Str, start_dir:Any=.)
Work in progress, do not use!
global_not_found_handler(name:Str)
Called when reading undefined global. Implements autoloading. Searches in $NGS_DIR/autoload/NAME.ngs WARNING: May have security implications when looking up a name from untrusted source.
Hash(arr:Arr, attr:Str)
TODO. Not sure it's used anywhere. Maybe remove?
Hash(arr:Arr, key_attr:Str, val_attr:Str)
Create Hash from Arr of something that has key and value attribute
in(symbol:Str, lib:CLib)
Unfinished feature. Don't use!
in(attr:Str, obj:NormalTypeInstance)
Check whether NormalType (a type that is typically defined by user) instance has an attribute.
in(name:Str, hl:HashLike)
in(needle:Str, haystack:Str)
Determin if needle substring occurs at least once in haystack
init(e:Exception, message:Str)
init(e:IndexNotFound, message:Str, container:Any, key:Any)
IndexNotFound exception constructor
init(al:ArrLike, attr:Str=items)
ArrLike constructor
init(e:CException, message:Str)
CException constructor. In addition to storing message attribute, adds errno and errno_name attributes.
init(p:Path, s:Str)
Path constructor
init(f:File, path:Str)
init(mf:MatchFail, msg:Str, container:Any, pattern:Any)
init(tf:TestFail, message:Str)
init(rd:ResDef, _ngs_name:Str)
init(rd:SecGroup, name:Str, VpcId:Any)
init(ds:DelimStr, s:Str, delim:Str=:)
DelimStr constructor
init(ds:DelimStr, a:Arr, delim:Str=:)
DelimStr constructor
init(e:LockFail, op:Str, code:Int, msg:Str)
init(tdn:TextDocNode, text:Str)
inspect(s:Str)
Inspect Str
Int(s:Str, base:Int)
Convert Str to Int.
Int(s:Str)
Convert base-10 string to Int. Throws InvalidArgument if the number in s is not well-formatted.
join(arr:Arr, s:Str)
join(a:Arr, s:Str)
Join non-strings. Converts a elements to string first, then uses built-in join().
len(s:Str)
Get Str length in bytes
limit(s:Str, n:Int, marker:Str=)
Truncate a string if necessary so it would have maximum n characters (currently bytes).
lines(s:Str)
Split s to strings using end-of-line separators. UNIX and Windows line endings supported (Windows - not tested yet). Warning: Max OS <= 9 line separation of CR (\r) is not supported
lines(s:Str, cb:Fun)
Split s to strings using end-of-line separators and call cb for each one of the lines. TODO: More efficient implementation, which would not have temporary array of all lines.
load(bytecode:Str, func_name:Str)
Load compiled bytecode.
log(s:Str)
Log to standard output. Later log output will be treated specially by the shell. It will have suitable representation in the UI. Use log() when it's semantically a log.
log(rd:ResDef, method:Str, s:Str)
log(r:Res, method:Str, s:Str)
log_test_ok(s:Str)
lstat(pathname:Str)
Issue lstat() system call. Throws StatFail if the call fails.
lte(a:Str, b:Str)
Case-insensitive LessThan or Equal comparison for strings
open(f:File, flags:Str)
Open a file and set the "fd" field to the file descriptor. Uses OPEN(2). Throws InvalidArgument if file is already open. Throws FileIOFail if an underlying error occurs.
opt_prop(rd:ResDef, name:Str, props:Hash)
Get optional resource property, looking up in properties first and then in anchor
opt_prop(rd:ResDef, name:Str, props:Hash, cb:Fun)
Run cb with optional resource property if it exists, uses opt_prop(ResDef, Str, Hash)
ord(s:Str, idx:Int)
Get character (byte) ordinal value. Throws InvalidArgument if idx is not pointing into s.
ord(s:Str)
Get character (currently byte) code. Throws InvalidArgument if s is not of length 1.
parse(s:Str)
Call parse(s, {})
parse(s:Str, hints:Hash)
Attempt to parse JSON. Uses decode_json().
parse(s:Str, hints:Hash)
EXPERIMENTAL. KVS (key-value separator) hint for parse()
parse(s:Str, hints:Hash)
EXPERIMENTAL. FS (field separator) hint for parse()
parse(s:Str, hints:Hash)
Handle fields_names hint - run parse() and make Arr[Hash] from Arr[Arr] using provided fields_names
parse(s:Str, hints:Hash)
Parse the output of "aws" command. Extracts the array (see "s" below"). For "describe-instances", flattens the instance list.
parse(s:Str, hints:Hash)
Parse the output of "find" command which does not use "-printf". Handles "-print0".
Path(s:Str, subtype:Any=false)
Path constructor
pos(haystack:Str, needle:Str, start:Int)
Find substring position
pos(haystack:Str, needle:Str)
Find substring in a string.
push(t:TextCollector, s:Str)
rand(a:Str)
Pick random character from a string
rand(a:Str, n:Int)
read(fname:Str)
Fetches the whole file
Real(s:Str)
Convert a string to real (floating) number, inefficiently
replace(s:Str, r:RegExp, mapper:Fun)
Replace all occurrences of r
req_prop(rd:ResDef, name:Str, props:Hash)
Get resource property, looking up in properties first and then in anchor
require(fname:Str)
Runs the given file
resolve_global_variable(name:Str)
Do not use directly! Get global variable index by name.
run(r:Res, log_pfx:Str, cmd:Command)
run(rd:ResDef, log_pfx:Str, cmd:Command)
set(obj:Any, attr:Str, val:Any)
Sets the given attribute to the given value
sort(a:Arr, attr:Str, lte:Fun=(a function))
Sort an array based on attribute value
split(s:Str, delim:Str)
Split string by substring
split(s:Str, r:RegExp)
%EX "x10ab20c30y".split(/[0-9]+/).join(" :: ") # "x :: ab :: c :: y"
starts_with(haystack:Str, needle:Str)
Check whether a string starts with another string
stat(pathname:Str)
Issue stat() system call. Throws StatFail if the call fails.
status(s:Str)
Send status to standard error. Later status output will be treated specially by the shell. It will have suitable representation in the UI. Use status() when it's semantically a status - a task that's being done.
stdlib_aws_straighten_tags(s:Str)
A no-op
Str(s:Str)
No-op constructor
Str(s:Str, target_width:Int)
Pad a string to given width with spaces
test(name:Str, f:Fun)
Type(name:Str, doc:Any)
Create a new type. Do not use directly. Use "type MyType".
Type(t:Str, doc:Any, parent:Type)
Type constructor
Type(t:Str, doc:Any, parents:Arr)
Type constructor
warn(s:Str)
Write error message to standard error.
without(s:Str, r:RegExp)
Get string with all occurrences of r removed
write(s:Str, fd:Int)
Write data to a file referenced by file descriptor. WARNING: Incomplete implementation. TODO: handle errors, throw exceptions. TODO: handle possible EINTR.
write(s:Str, p:Pipe)
Write to Pipe. TODO: document if it throws.
write(s:Str, fname:Str)
~(a:Str, b:Str)
EXPERIMENTAL. For use with AWS Anchors.
~(s:Str, pfx:Pfx)
Check whether s starts with pfx.
~(s:Str, sfx:Sfx)
Check whether s ends with pfx.
~(s:Str, r:RegExp, offset:Int=0, options:Int=0)
Find PCRE regular expression in s. Empty string without options returns MatchN. Throws Error if more than 20 captures are used or if there is an error during matching.
~~(s:Str, r:RegExp, collect_unmatched:Bool=false)
Find all non-overlapping matches of regular expression in a string.