Example #1
0
    bool prepare(
        MemoryManager                  mm,
        const Functional::value_vec_t& static_args,
        Environment                    environment,
        NodeReporter                   reporter
    )
    {
        ConstByteString expression = static_args[0].as_string();
        try {
            m_expression.assign(
                expression.const_data(), expression.length(),
                boost::regex_constants::normal
            );
        }
        catch (const boost::bad_expression& e) {
            reporter.error(
                "Could not compile regexp: " +
                expression.to_s() +
                " (" + e.what() + ")"
            );
            return false;
        }

        m_replacement = static_args[1].as_string().to_s();
        return true;
    }
Example #2
0
    Value eval_map(
        MemoryManager                  mm,
        const Functional::value_vec_t& secondary_args,
        boost::any&                    map_state,
        Value                          subvalue
    ) const
    {
        /* If the subvalue we've been given is NULL, likewise return a NULL
         * subvalue. We can't change anything. */
        if (! subvalue) {
            return Value();
        }

        if (subvalue.type() != Value::STRING) {
            return Value();
        }

        ConstByteString text = subvalue.as_string();
        boost::shared_ptr<vector<char> > result(new vector<char>());
        // Ensure that result.data() is non-null, even if we never insert
        // anything.
        result->reserve(1);

        // value_to_data() ensures that a copy is associated with the memory
        // pool and will be deleted when the memory pool goes away.
        value_to_data(result, mm.ib());

        boost::regex_replace(
            back_inserter(*result),
            text.const_data(), text.const_data() + text.length(),
            m_expression,
            m_replacement
        );

        return Value::create_string(
            mm,
            subvalue.name(), subvalue.name_length(),
            ByteString::create_alias(
                mm,
                result->data(), result->size()
            )
        );
    }
Example #3
0
void Transformation::pre_eval(Environment environment, NodeReporter reporter)
{
    // Validation guarantees that the first child is a string interval
    // and thus can be evaluated with default EvalContext.

    Value name_value = literal_value(children().front());
    ConstByteString name = name_value.value_as_byte_string();

    if (! name) {
        reporter.error("Missing transformation name.");
        return;
    }

    m_data->transformation = ConstTransformation::lookup(
        environment, string(name.const_data(), name.length()).c_str()
    );
}
Example #4
0
ConstField get(ConstContext ctx, ConstByteString key)
{
    return get(ctx, key.const_data(), key.size());
}
Example #5
0
 /**
  * Remove a value from hash.
  *
  * @param[in] key Key.
  *
  * @return Value removed.
  *
  * @throw enoent if no such key.
  **/
 T remove(ConstByteString key) const
 {
     return remove(key.const_data(), key.length());
 }
Example #6
0
 /**
  * Set a value in hash.
  *
  * @param[in] key   Key.
  * @param[in] value Value.
  **/
 void set(ConstByteString key, T value) const
 {
     set(key.const_data(), key.length(), value);
 }
Example #7
0
 /**
  * Fetch value from hash.
  *
  * @param[in] key Key.
  *
  * @return Value.
  *
  * @throw enoent if no such key.
  **/
 T get(ConstByteString key) const
 {
     return get(key.const_data(), key.length());
 }