| public String getModesEnabled() { | ||
| + // Force the processor to select particular sigils. | ||
| final var processor = new VariableProcessor( IDENTITY, this ); | ||
| final var needles = processor.getDefinitions(); | ||
| final var haystack = mMutator.mModesEnabled.get(); | ||
| + | ||
| return needles.containsKey( haystack ) | ||
| ? replace( haystack, needles ) | ||
| + : processor.hasSigils( haystack ) | ||
| + ? "" | ||
| : haystack; | ||
| } |
| package com.keenwrite.processors; | ||
| +import com.keenwrite.sigils.SigilKeyOperator; | ||
| + | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.function.Function; | ||
| -import java.util.function.UnaryOperator; | ||
| import static com.keenwrite.processors.text.TextReplacementFactory.replace; | ||
| private final ProcessorContext mContext; | ||
| - private final UnaryOperator<String> mSigilOperator; | ||
| + private final SigilKeyOperator mSigilOperator; | ||
| /** | ||
| * @return An operator for transforming key names. | ||
| */ | ||
| - protected UnaryOperator<String> createKeyOperator( | ||
| + protected SigilKeyOperator createKeyOperator( | ||
| final ProcessorContext context ) { | ||
| return context.createKeyOperator(); | ||
| protected String processValue( final String value ) { | ||
| return value; | ||
| + } | ||
| + | ||
| + /** | ||
| + * Answers whether the given key is wrapped in sigil tokens. | ||
| + * | ||
| + * @param key The key to analyze. | ||
| + * @return {@code true} if the key is wrapped in sigils. | ||
| + */ | ||
| + public boolean hasSigils( final String key ) { | ||
| + return mSigilOperator.match( key ).find(); | ||
| } | ||
| import com.keenwrite.processors.VariableProcessor; | ||
| import com.keenwrite.sigils.RKeyOperator; | ||
| +import com.keenwrite.sigils.SigilKeyOperator; | ||
| import java.util.function.UnaryOperator; | ||
| @Override | ||
| - protected UnaryOperator<String> createKeyOperator( | ||
| + protected SigilKeyOperator createKeyOperator( | ||
| final ProcessorContext context ) { | ||
| return new RKeyOperator(); | ||
| import com.keenwrite.collections.BoundedCache; | ||
| -import java.util.function.UnaryOperator; | ||
| - | ||
| /** | ||
| * Converts dot-separated variable names into names compatible with R. That is, | ||
| * {@code variable.name.qualified} becomes {@code v$variable$name$qualified}. | ||
| */ | ||
| -public final class RKeyOperator implements UnaryOperator<String> { | ||
| +public final class RKeyOperator extends SigilKeyOperator { | ||
| private static final char KEY_SEPARATOR_DEF = '.'; | ||
| private static final char KEY_SEPARATOR_R = '$'; | ||
| * names into R's dollar-symbol-separated names. | ||
| */ | ||
| - public RKeyOperator() { } | ||
| + public RKeyOperator() { | ||
| + // The keys are not delimited. | ||
| + super( "", "" ); | ||
| + } | ||
| /** | ||
| public String apply( final String key ) { | ||
| assert key != null; | ||
| - assert key.length() > 0; | ||
| assert !key.isBlank(); | ||
| Author | DaveJarvis <email> |
|---|---|
| Date | 2024-01-18 22:18:44 GMT-0800 |
| Commit | ee1e6657ff1fed4d525300548ba630048da3455b |
| Parent | e8869a0 |
| Delta | 25 lines added, 9 lines removed, 16-line increase |