Package io.jawk.ext
Class GawkExtension
java.lang.Object
io.jawk.ext.AbstractExtension
io.jawk.ext.GawkExtension
- All Implemented Interfaces:
JawkExtension
GNU awk compatibility extension for array sorting and type introspection.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSorts an array by value, optionally writing the result to another array.Sorts an array by index, optionally writing the result to another array.bindtextdomain(Object directory, Object domain) Binds a text domain to a message catalog directory and returns the binding, mirroring gawk'sbindtextdomain().Returns the translation of a string in the given text domain and locale category.Returns the singular or plural form of a message according to a number.Performs a small gawk-compatiblegensub()substitution.getExtensionName.voidinitializeGawkVariables(AVM avmParam, JRT jrt) Installs thePROCINFO["sorted_in"]traversal order forfor-inloops and binds this per-engine extension instance to its interpreter.Returns whether the supplied value is an array.Creates a boolean-typed numeric value used by gawk's test suite.Converts a gawk"YYYY MM DD HH MM SS [DST]"date specification into seconds since the epoch, normalizing out-of-range values.Splits a string by content: pieces matchingfieldpatbecome fields, the text between them becomes separators.Formats a timestamp with Cstrftime(3)conversion specifiers.Converts a string to a number, recognizing gawk's non-decimal notation: a0xprefix selects hexadecimal and a leading0over octal digits selects octal.systime()Returns the current time in seconds since the epoch.Returns the gawk type category for a value.Methods inherited from class io.jawk.ext.AbstractExtension
beforeStart, checkNumArgs, getExtensionFunctions, getJrt, getSettings, getVm, init, toAwkStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.jawk.ext.JawkExtension
beforeStart, getExtensionFunctions, init
-
Constructor Details
-
GawkExtension
public GawkExtension()
-
-
Method Details
-
getExtensionName
getExtensionName.
- Specified by:
getExtensionNamein interfaceJawkExtension- Overrides:
getExtensionNamein classAbstractExtension- Returns:
- name of the extension package.
-
initializeGawkVariables
Installs thePROCINFO["sorted_in"]traversal order forfor-inloops and binds this per-engine extension instance to its interpreter. SYMTAB and FUNCTAB are populated by the interpreter itself.- Parameters:
avmParam- interpreter about to executejrt- runtime associated withavmParam
-
asort
Sorts an array by value, optionally writing the result to another array.- Parameters:
source- source arraydest- destination array, ornullto sort in placehow- predefined sorting mode, ornullfor the default- Returns:
- number of sorted elements
-
asorti
Sorts an array by index, optionally writing the result to another array.- Parameters:
source- source arraydest- destination array, ornullto sort in placehow- predefined sorting mode, ornullfor the default- Returns:
- number of sorted elements
-
typeof
Returns the gawk type category for a value.- Parameters:
value- value to inspectmeta- optional metadata destination array- Returns:
- gawk type name
-
isarray
Returns whether the supplied value is an array.- Parameters:
value- value to inspect- Returns:
- 1 for arrays, 0 otherwise
-
mkbool
Creates a boolean-typed numeric value used by gawk's test suite.- Parameters:
value- truth value- Returns:
- boolean numeric value
-
gensub
Performs a small gawk-compatiblegensub()substitution.- Parameters:
regexp- regular expressionreplacement- replacement texthow- occurrence selector orgtarget- target text, ornullto default to$0- Returns:
- substituted text
-
systime
Returns the current time in seconds since the epoch.- Returns:
- seconds since 1970-01-01 00:00:00 UTC
-
mktime
Converts a gawk"YYYY MM DD HH MM SS [DST]"date specification into seconds since the epoch, normalizing out-of-range values.The conversion follows Java's calendar rules: an ambiguous wall time during a DST fall-back resolves to its standard-time occurrence, and a positive DST hint applies the zone's current savings (zones without DST ignore the hint). See the documented differences with gawk, whose behavior in these edge cases follows the C library.
- Parameters:
datespec- date specification with six or seven numeric fieldsutcFlag- when truthy, interpret the specification as UTC- Returns:
- seconds since the epoch, or -1 when the specification is invalid
-
strftime
Formats a timestamp with Cstrftime(3)conversion specifiers.- Parameters:
format- format string; defaults toPROCINFO["strftime"]or gawk's"%a %b %e %H:%M:%S %Z %Y"timestamp- seconds since the epoch; defaults to the current timeutcFlag- when truthy, format in UTC instead of the local time zone- Returns:
- formatted timestamp
-
strtonum
Converts a string to a number, recognizing gawk's non-decimal notation: a0xprefix selects hexadecimal and a leading0over octal digits selects octal.- Parameters:
value- value to convert- Returns:
- numeric value
-
patsplit
public Long patsplit(Object source, Map<Object, Object> array, Object fieldpat, Map<Object, Object> seps) Splits a string by content: pieces matchingfieldpatbecome fields, the text between them becomes separators. This is gawk'spatsplit(), the function form ofFPATfield splitting.- Parameters:
source- text to splitarray- destination array for the fieldsfieldpat- field pattern, ornullto use theFPATglobal variable (default"[^[:space:]]+")seps- optional destination array for the separators; entry 0 holds the text before the first field- Returns:
- number of fields
-
dcgettext
Returns the translation of a string in the given text domain and locale category. Jawk ships no message catalogs, so the text is returned untranslated, exactly like gawk without a matching.mofile.- Parameters:
string- text to translatedomain- text domain; defaults toTEXTDOMAINcategory- locale category; validated, then ignored (no catalogs)- Returns:
- the untranslated text
-
dcngettext
public String dcngettext(Object singular, Object plural, Object number, Object domain, Object category) Returns the singular or plural form of a message according to a number. Without message catalogs this applies the English plural rule, exactly like gawk without a matching.mofile.- Parameters:
singular- singular formplural- plural formnumber- quantity deciding the formdomain- text domain; defaults toTEXTDOMAINcategory- locale category; validated, then ignored (no catalogs)- Returns:
singularwhen the number is 1,pluralotherwise
-
bindtextdomain
Binds a text domain to a message catalog directory and returns the binding, mirroring gawk'sbindtextdomain().- Parameters:
directory- directory to bind; the AWK empty string queries the current binding without changing itdomain- text domain; defaults toTEXTDOMAIN- Returns:
- the directory now bound to the domain
-