public final class SedArguments extends Object implements Arguments<SedArguments>
sed
command.Constructor and Description |
---|
SedArguments()
Constructor to use if no options are specified.
|
SedArguments(SedOptions options)
Constructor with option set containing the selected command options.
|
SedArguments(String... args)
Constructor string arguments encoding options and arguments, possibly
also containing variable expressions.
|
Modifier and Type | Method and Description |
---|---|
String[] |
getArgs()
Returns the
<args> operand value: String arguments defining the options and operands for the command. |
SedArguments |
getForContext(ExecutionContext context)
Returns an arguments object for the given execution context with resolved
variables if necessary and possible.
|
int[] |
getOccurrence()
Returns the
<occurrence> operand value: Substitute for the given occurrences only of the regexp found within
the matched string; the occurrence indices are one-based. |
SedOptions |
getOptions()
Returns the options set containing the selected command options.
|
String |
getRegexp()
Returns the
<regexp> operand value (variables are NOT resolved): Regular expression matched against a line. |
String |
getRegexp(ExecutionContext context)
Returns the
<regexp> (variables are resolved): Regular expression matched against a line. |
String |
getReplacement()
Returns the
<replacement> operand value (variables are NOT resolved): Replacement string for substitute command. |
String |
getReplacement(ExecutionContext context)
Returns the
<replacement> (variables are resolved): Replacement string for substitute command. |
String |
getScript()
Returns the
<script> operand value (variables are NOT resolved): Sed script as one string, such as "s/original/replacement/g". |
String |
getScript(ExecutionContext context)
Returns the
<script> (variables are resolved): Sed script as one string, such as "s/original/replacement/g". |
String |
getString1()
Returns the
<string1> operand value (variables are NOT resolved): Regular expression matched against a line for all commands except
for command y where string1 contains the source characters for the
translation. |
String |
getString1(ExecutionContext context)
Returns the
<string1> (variables are resolved): Regular expression matched against a line for all commands except
for command y where string1 contains the source characters for the
translation. |
String |
getString2()
Returns the
<string2> operand value (variables are NOT resolved): Replacement string for substitute command s; appended, inserted or
changed text for a, i and c command; destination characters for
translate command y; ignored by all other commands. |
String |
getString2(ExecutionContext context)
Returns the
<string2> (variables are resolved): Replacement string for substitute command s; appended, inserted or
changed text for a, i and c command; destination characters for
translate command y; ignored by all other commands. |
boolean |
isAppend()
Returns true if the
-- append option
is set. |
boolean |
isArgsSet()
Returns true if the
<args> operand has been set. |
boolean |
isChange()
Returns true if the
-- change option
is set. |
boolean |
isDelete()
Returns true if the
-- delete option
is set. |
boolean |
isGlobal()
Returns true if the
-- global option
is set. |
boolean |
isIgnoreCase()
Returns true if the
-- ignoreCase option
is set. |
boolean |
isInsert()
Returns true if the
-- insert option
is set. |
boolean |
isLineNumber()
Returns true if the
-- lineNumber option
is set. |
boolean |
isOccurrenceSet()
Returns true if the
<occurrence> operand has been set. |
boolean |
isPrint()
Returns true if the
-- print option
is set. |
boolean |
isQuiet()
Returns true if the
-- quiet option
is set. |
boolean |
isRegexpSet()
Returns true if the
<regexp> operand has been set. |
boolean |
isReplacementSet()
Returns true if the
<replacement> operand has been set. |
boolean |
isScriptSet()
Returns true if the
<script> operand has been set. |
boolean |
isString1Set()
Returns true if the
<string1> operand has been set. |
boolean |
isString2Set()
Returns true if the
<string2> operand has been set. |
boolean |
isSubstitute()
Returns true if the
-- substitute option
is set. |
boolean |
isTranslate()
Returns true if the
-- translate option
is set. |
void |
setOccurrence(int... occurrence)
Sets
<occurrence> : Substitute for the given occurrences only of the regexp found within
the matched string; the occurrence indices are one-based. |
void |
setRegexp(String regexp)
Sets
<regexp> : Regular expression matched against a line. |
void |
setReplacement(String replacement)
Sets
<replacement> : Replacement string for substitute command. |
void |
setScript(String script)
Sets
<script> : Sed script as one string, such as "s/original/replacement/g". |
void |
setString1(String string1)
Sets
<string1> : Regular expression matched against a line for all commands except
for command y where string1 contains the source characters for the
translation. |
void |
setString2(String string2)
Sets
<string2> : Replacement string for substitute command s; appended, inserted or
changed text for a, i and c command; destination characters for
translate command y; ignored by all other commands. |
String |
toString()
Returns a string representation of the command arguments and options.
|
public SedArguments()
public SedArguments(SedOptions options)
options
- the selected optionsNullPointerException
- if the argument is nullpublic SedArguments(String... args)
args
- string arguments for the commandNullPointerException
- if args is nullpublic SedOptions getOptions()
public SedArguments getForContext(ExecutionContext context)
Arguments
this
arguments instance is simply returned.
If variables are present, they are resolved if such a variable is defined
in the VariableContext
returned by
context.
getVariableContext()
.
Values are converted if necessary with the ValueConverter
s
returned by
context.
getValueConverterFor(Class)
.
getForContext
in interface Arguments<SedArguments>
context
- the execution context providing access to variables and
converterspublic String getScript()
<script>
operand value (variables are NOT resolved): Sed script as one string, such as "s/original/replacement/g".<script>
operand value (variables are not resolved)IllegalStateException
- if this operand has never been setgetScript(ExecutionContext)
public String getScript(ExecutionContext context)
<script>
(variables are resolved): Sed script as one string, such as "s/original/replacement/g".context
- the execution context used to resolve variables<script>
operand value after resolving variablesIllegalStateException
- if this operand has never been setgetScript()
public boolean isScriptSet()
<script>
operand has been set.
Note that this method returns true even if null
was passed to the
setScript(String)
method.
<script>
operand has
been called at least oncepublic void setScript(String script)
<script>
: Sed script as one string, such as "s/original/replacement/g".script
- the value for the <script>
operandpublic String getRegexp()
<regexp>
operand value (variables are NOT resolved): Regular expression matched against a line.<regexp>
operand value (variables are not resolved)IllegalStateException
- if this operand has never been setgetRegexp(ExecutionContext)
public String getRegexp(ExecutionContext context)
<regexp>
(variables are resolved): Regular expression matched against a line.context
- the execution context used to resolve variables<regexp>
operand value after resolving variablesIllegalStateException
- if this operand has never been setgetRegexp()
public boolean isRegexpSet()
<regexp>
operand has been set.
Note that this method returns true even if null
was passed to the
setRegexp(String)
method.
<regexp>
operand has
been called at least oncepublic void setRegexp(String regexp)
<regexp>
: Regular expression matched against a line.regexp
- the value for the <regexp>
operandpublic String getString1()
<string1>
operand value (variables are NOT resolved): Regular expression matched against a line for all commands except
for command y where string1 contains the source characters for the
translation.<string1>
operand value (variables are not resolved)IllegalStateException
- if this operand has never been setgetString1(ExecutionContext)
public String getString1(ExecutionContext context)
<string1>
(variables are resolved): Regular expression matched against a line for all commands except
for command y where string1 contains the source characters for the
translation.context
- the execution context used to resolve variables<string1>
operand value after resolving variablesIllegalStateException
- if this operand has never been setgetString1()
public boolean isString1Set()
<string1>
operand has been set.
Note that this method returns true even if null
was passed to the
setString1(String)
method.
<string1>
operand has
been called at least oncepublic void setString1(String string1)
<string1>
: Regular expression matched against a line for all commands except
for command y where string1 contains the source characters for the
translation.string1
- the value for the <string1>
operandpublic String getReplacement()
<replacement>
operand value (variables are NOT resolved): Replacement string for substitute command. The characters "$0"
appearing in the replacement are replaced by the line matching
the regexp. The characters "$n", where n is a digit other than zero,
are replaced by the text matched by the corresponding backreference
expression (aka group). The special meaning of "$n" in this context
can be suppressed by preceding it by a backslash.<replacement>
operand value (variables are not resolved)IllegalStateException
- if this operand has never been setgetReplacement(ExecutionContext)
public String getReplacement(ExecutionContext context)
<replacement>
(variables are resolved): Replacement string for substitute command. The characters "$0"
appearing in the replacement are replaced by the line matching
the regexp. The characters "$n", where n is a digit other than zero,
are replaced by the text matched by the corresponding backreference
expression (aka group). The special meaning of "$n" in this context
can be suppressed by preceding it by a backslash.context
- the execution context used to resolve variables<replacement>
operand value after resolving variablesIllegalStateException
- if this operand has never been setgetReplacement()
public boolean isReplacementSet()
<replacement>
operand has been set.
Note that this method returns true even if null
was passed to the
setReplacement(String)
method.
<replacement>
operand has
been called at least oncepublic void setReplacement(String replacement)
<replacement>
: Replacement string for substitute command. The characters "$0"
appearing in the replacement are replaced by the line matching
the regexp. The characters "$n", where n is a digit other than zero,
are replaced by the text matched by the corresponding backreference
expression (aka group). The special meaning of "$n" in this context
can be suppressed by preceding it by a backslash.replacement
- the value for the <replacement>
operandpublic String getString2()
<string2>
operand value (variables are NOT resolved): Replacement string for substitute command s; appended, inserted or
changed text for a, i and c command; destination characters for
translate command y; ignored by all other commands.
If string2 is a replacement string for the substitute command: the characters "$0" appearing in the replacement are replaced by the line matching the regexp; the characters "$n", where n is a digit other than zero, are replaced by the text matched by the corresponding backreference expression (aka group). The special meaning of "$n" in this context can be suppressed by preceding it by a backslash.
(This operand only applies to the commands s, a, i, c and y and is ignored by all other commands).
<string2>
operand value (variables are not resolved)IllegalStateException
- if this operand has never been setgetString2(ExecutionContext)
public String getString2(ExecutionContext context)
<string2>
(variables are resolved): Replacement string for substitute command s; appended, inserted or
changed text for a, i and c command; destination characters for
translate command y; ignored by all other commands.
If string2 is a replacement string for the substitute command: the characters "$0" appearing in the replacement are replaced by the line matching the regexp; the characters "$n", where n is a digit other than zero, are replaced by the text matched by the corresponding backreference expression (aka group). The special meaning of "$n" in this context can be suppressed by preceding it by a backslash.
(This operand only applies to the commands s, a, i, c and y and is ignored by all other commands).
context
- the execution context used to resolve variables<string2>
operand value after resolving variablesIllegalStateException
- if this operand has never been setgetString2()
public boolean isString2Set()
<string2>
operand has been set.
Note that this method returns true even if null
was passed to the
setString2(String)
method.
<string2>
operand has
been called at least oncepublic void setString2(String string2)
<string2>
: Replacement string for substitute command s; appended, inserted or
changed text for a, i and c command; destination characters for
translate command y; ignored by all other commands.
If string2 is a replacement string for the substitute command: the characters "$0" appearing in the replacement are replaced by the line matching the regexp; the characters "$n", where n is a digit other than zero, are replaced by the text matched by the corresponding backreference expression (aka group). The special meaning of "$n" in this context can be suppressed by preceding it by a backslash.
(This operand only applies to the commands s, a, i, c and y and is ignored by all other commands).
string2
- the value for the <string2>
operandpublic int[] getOccurrence()
<occurrence>
operand value: Substitute for the given occurrences only of the regexp found within
the matched string; the occurrence indices are one-based. If empty
or omitted, all occurrences are substituted.
(This operand only applies to the substitute command and is ignored by all other commands).
<occurrence>
operand value (variables are not resolved)IllegalStateException
- if this operand has never been setpublic boolean isOccurrenceSet()
<occurrence>
operand has been set.
Note that this method returns true even if null
was passed to the
setOccurrence(int[])
method.
<occurrence>
operand has
been called at least oncepublic void setOccurrence(int... occurrence)
<occurrence>
: Substitute for the given occurrences only of the regexp found within
the matched string; the occurrence indices are one-based. If empty
or omitted, all occurrences are substituted.
(This operand only applies to the substitute command and is ignored by all other commands).
occurrence
- the value for the <occurrence>
operandpublic String[] getArgs()
<args>
operand value: String arguments defining the options and operands for the command.
Options can be specified by acronym (with a leading dash "-") or by
long name (with two leading dashes "--"). Operands other than the
default "--script" operand have to be prefixed with the operand name
(e.g. "--occurrence" for subsequent occurrence indices).<args>
operand value (variables are not resolved)IllegalStateException
- if this operand has never been setpublic boolean isArgsSet()
<args>
operand has been set.<args>
operand has
been called at least oncepublic boolean isQuiet()
--
quiet
option
is set. The option is also known as -
n option.
Description: Suppress the default output (in which each line, after it is examined for editing, is written to standard output). Only lines explicitly selected for output are written.
--quiet
or -n
option is setpublic boolean isGlobal()
--
global
option
is set. The option is also known as -
g option.
Description: Globally substitute for all non-overlapping instances of the regexp rather than just the first one.
(This option is ignored if the occurrence operand is specified).
--global
or -g
option is setpublic boolean isPrint()
--
print
option
is set. The option is also known as -
p option.
Description: Write the matched line to standard output.
--print
or -p
option is setpublic boolean isLineNumber()
--
lineNumber
option
is set. The option is also known as -
l option.
Description: Writes the current line number on a separate line to the standard output.
--lineNumber
or -l
option is setpublic boolean isIgnoreCase()
--
ignoreCase
option
is set. The option is also known as -
I option.
Description: Use case insensitive pattern matching.
--ignoreCase
or -I
option is setpublic boolean isSubstitute()
--
substitute
option
is set. The option is also known as -
s option.
Description: Substitutes the replacement string for instances of the regexp in the matched line.
The characters "$0" appearing in the replacement are replaced by the line matching the regexp. The characters "$n", where n is a digit other than zero, are replaced by the text matched by the corresponding backreference expression (aka group). The special meaning of "$n" in this context can be suppressed by preceding it by a backslash.
A line can be split by substituting a newline ('\n') into it.
A substitution is considered to have been performed even if the replacement string is identical to the string that it replaces.
--substitute
or -s
option is setpublic boolean isAppend()
--
append
option
is set. The option is also known as -
a option.
Description: Append string2 as a separate line after the matched line.
--append
or -a
option is setpublic boolean isInsert()
--
insert
option
is set. The option is also known as -
i option.
Description: Insert string2 as a separate line before the matched line.
--insert
or -i
option is setpublic boolean isChange()
--
change
option
is set. The option is also known as -
c option.
Description: Write string2 as a separate line instead of the matched line.
--change
or -c
option is setpublic boolean isDelete()
--
delete
option
is set. The option is also known as -
d option.
Description: Delete the matched line.
--delete
or -d
option is setpublic boolean isTranslate()
--
translate
option
is set. The option is also known as -
y option.
Description: Replace all occurrences of characters in string1 with the corresponding characters in string2. If the number of characters in the two strings are not equal, or if any of the characters in string1 appear more than once, the results are undefined.
--translate
or -y
option is setpublic String toString()
Arguments
toString
in interface Arguments<SedArguments>
toString
in class Object
Copyright © 2024. All rights reserved.