JX Application Framework
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
JInterpolate Class Reference

#include <JInterpolate.h>

Inheritance diagram for JInterpolate:
[legend]

Public Member Functions

 JInterpolate ()
 
 ~JInterpolate () override
 
JString Interpolate (const JString &pattern, const JStringMatch &m)
 
- Public Member Functions inherited from JSubstitute
 JSubstitute ()
 
 JSubstitute (const JSubstitute &source)
 
virtual ~JSubstitute ()
 
JSubstituteoperator= (const JSubstitute &source)
 
void Substitute (JString *s) const
 
JError ContainsError (const JString &s, JCharacterRange *errRange) const
 
bool EscapeExists (const unsigned char character) const
 
bool GetEscape (const unsigned char character, const JString **value) const
 
bool SetEscape (const unsigned char character, const JUtf8Byte *value)
 
bool ClearEscape (const unsigned char character)
 
void ClearAllEscapes ()
 
void SetNonprintingEscapes ()
 
void ClearNonprintingEscapes ()
 
void SetWhitespaceEscapes ()
 
void ClearWhitespaceEscapes ()
 
void SetCEscapes ()
 
void ClearCEscapes ()
 
void SetRegexExtensions ()
 
void ClearRegexExtensions ()
 
void DefineVariable (const JUtf8Byte *name, const JString &value)
 
bool SetVariableValue (const JUtf8Byte *name, const JString &value)
 
void DefineVariables (const JUtf8Byte *regexPattern)
 
void UndefineVariable (const JUtf8Byte *name)
 
void UndefineAllVariables ()
 
void Reset ()
 
bool IsUsingControlEscapes () const
 
void UseControlEscapes (const bool use=true)
 
bool WillIgnoreUnrecognized () const
 
void IgnoreUnrecognized (const bool ignore=true)
 
bool IsPureEscapeEngine () const
 
void SetPureEscapeEngine (const bool is=true)
 

Protected Member Functions

bool GetValue (const JString &name, JString *value) const override
 
- Protected Member Functions inherited from JSubstitute
virtual bool Evaluate (JStringIterator &iter, JString *value) const
 

Additional Inherited Members

- Static Public Attributes inherited from JSubstitute
static const JUtf8BytekLoneDollar = "LoneDollar::JSubstitute"
 
static const JUtf8BytekTrailingBackslash = "TrailingBackslash::JSubstitute"
 
static const JUtf8BytekIllegalControlChar = "IllegalControlChar::JSubstitute"
 

Detailed Description

JInterpolate does the interpolation of replacement strings for JRegex.

A summary of the default behavior is as follows.  The replacement
metacharacter is '$', which marks the beginning of a replacement token.
'Unclean' replacement patterns are patterns which contain a
metacharacter not immediately followed either by a second metacharacter
or by an optional sign ('-' or '+') preceding one or more decimal
digits.  All other patterns are 'clean'.  Clean patterns will be
replaced by their corresponding match value, while unclean patterns are
left intact except their '$' is removed; to insert a literal '$'
preface it with a backslash.

In other words, the only clean replacement tokens are those of the form
'$[+-]?[0-9]+' and '${...}', and a replacement pattern is clean unless
it contains at least one unclean replacement token.

The $ pattern behavior is as follows.  A $ followed by a positive
number N is replaced by the (N+1)st element of matchList, counting from
the beginning of the list.  A $ followed by a negative number -N is
replaced by the Nth element of matchList, *counting from the end of the
list*.  If the number refers to an element which does not exist in
matchList, the replacement string is "".  Replacement is done in one
pass, so matches which contain '$N' are not subject to further
replacement.  Maniacs who want a convenient way to, say, iterate until
a fixed point is reached should write their own loop.

${x} is replaced by the subexpression named "x".

The above rules are easier to understand in the normal case where
matchList was generated by a previous match.  Then $0 is the entire
match, while $1 is the first subexpression, $2 the second, and so forth
up to $9, numbering subexpressions by counting left parentheses from
left to right.  Similarly, $-1 is the last subexpression, $-2 is the
second to the last, and so on.  If the pattern actually only contained
four subexpressions, then $5 through $9 and $-6 through $-10 would be
replaced by "", while both $0 and $-5 would be replaced by the overall
match.  Similarly, both $1 and $-4 would be replaced by the first
parenthesized subexpression, $2 and $-3) by the second, $3 and $-2 by
the third, and finally $4 and $-1 by the fourth.

Constructor & Destructor Documentation

◆ JInterpolate()

JInterpolate::JInterpolate ( )

◆ ~JInterpolate()

JInterpolate::~JInterpolate ( )
override

Member Function Documentation

◆ GetValue()

bool JInterpolate::GetValue ( const JString name,
JString value 
) const
overrideprotectedvirtual

Returns true if there is a variable with the given name. The default is to return false. This function can't be pure virtual because one shouldn't have to create a derived class if one only has literal variable names.

Reimplemented from JSubstitute.

◆ Interpolate()

JString JInterpolate::Interpolate ( const JString pattern,
const JStringMatch m 
)

Not to be confused with exterminate. – The Doctor


The documentation for this class was generated from the following files: