Beispiel #1
0
const char *AbstractMacroReplacer::replace(const char *source){
   if (isempty(source))
      return NULL;

   StringEscaper *se   = new StringEscaper(source);
   StringBuffer  *pole = new StringBuffer();

   sb->clear();

   boolean b = false;

   while (!se->eof()){
      char x = se->getChar();
      
      if (!b){
         if ((!se->getStatus() ) && (x == bdelim))
   	    b = true; 
         else
	    sb->add(x);
      }else{
         if ((!se->getStatus() ) && (x == edelim)){
	    sb->add( replaceField( pole->get() ) );
            b = false;
            pole->clear();
         }
else
            pole->add(x);
 
      }
   }

   delete(pole);
   delete(se);
   return sb->get();
};
Beispiel #2
0
void PVStructure::appendPVFields(
    StringArray const & fieldNames,
    PVFieldPtrArray const & pvFields)
{
    size_t origLength = this->pvFields.size();
    size_t extra = fieldNames.size();
    if(extra==0) return;
    size_t newLength = origLength + extra;
    PVFieldPtrArray * xxx = const_cast<PVFieldPtrArray *>(&this->pvFields);
    xxx->reserve(newLength);
    for(size_t i=0; i<extra; i++) {
        xxx->push_back(pvFields[i]);
    }
    FieldConstPtrArray fields;
    fields.reserve(extra);
    for(size_t i=0; i<extra; i++) fields.push_back(pvFields[i]->getField());
    FieldConstPtr field = getFieldCreate()->appendFields(
        structurePtr,fieldNames,fields);
    replaceField(field);
    structurePtr = static_pointer_cast<const Structure>(field);
    StringArray names = structurePtr->getFieldNames();
    for(size_t i=0; i<newLength; i++) {
        (*xxx)[i]->setParentAndName(this,names[i]);
    }
    fixParentStructure();
}
Beispiel #3
0
bool    Replacer::replaceFieldInTextWidget( const TextWidgetPtr & widget, const ReportPtr & report, int i )
{
    auto text = widget->getOriginalText();
    auto replacedText = replaceField( text, report, i );
    widget->setText( replacedText );

    return true;
}
Beispiel #4
0
void PVStructure::appendPVField(
    String const &fieldName,
    PVFieldPtr const & pvField)
{
    size_t origLength = pvFields.size();
    size_t newLength = origLength+1;
    PVFieldPtrArray * xxx = const_cast<PVFieldPtrArray *>(&pvFields);
    xxx->push_back(pvField);
    FieldConstPtr field = getFieldCreate()->appendField(
        structurePtr,fieldName,pvField->getField());
    replaceField(field);
    structurePtr = static_pointer_cast<const Structure>(field);
    StringArray fieldNames = structurePtr->getFieldNames();
    for(size_t i=0; i<newLength; i++) {
        pvFields[i]->setParentAndName(this,fieldNames[i]);
    }
    fixParentStructure();
}
static void simplifyRecursive(WordSimplification *simp, DFNode *node)
{
    switch (node->tag) {
        case WORD_FLDCHAR: {
            const char *type = DFGetAttribute(node,WORD_FLDCHARTYPE);
            if (DFStringEquals(type,"begin")) {
                if (simp->depth == 0) {
                    DFBufferRelease(simp->instrText);
                    simp->instrText = DFBufferNew();
                    simp->beginNode = node;
                    simp->endNode = NULL;
                    simp->inSeparate = 0;
                }
                simp->depth++;
            }
            else if (DFStringEquals(type,"end") && (simp->depth > 0)) {
                simp->depth--;
                if (simp->depth == 0) {
                    simp->endNode = node;
                    replaceField(simp);
                }
            }
            else if (DFStringEquals(type,"separate")) {
                if (simp->depth == 1)
                    simp->inSeparate = 1;
            }
            break;
        }
        case WORD_INSTRTEXT: {
            if ((simp->depth == 1) && !simp->inSeparate) {
                char *value = DFNodeTextToString(node);
                DFBufferFormat(simp->instrText,"%s",value);
                free(value);
            }
            break;
        }
    }

    DFNode *next;
    for (DFNode *child = node->first; child != NULL; child = next) {
        next = child->next;
        simplifyRecursive(simp,child);
    }
}
Beispiel #6
0
void PVStructure::removePVField(String const &fieldName)
{
    PVFieldPtr pvField = getSubField(fieldName);
    if(pvField.get()==NULL) {
        String message("removePVField ");
        message +=  fieldName + " does not exist";
        this->message(message, errorMessage);
        return;
    }
    size_t origLength = pvFields.size();
    size_t newLength = origLength - 1;
    PVFieldPtrArray const & origPVFields = pvFields;
    FieldConstPtrArray origFields = structurePtr->getFields();
    PVFieldPtrArray newPVFields;
    newPVFields.reserve(newLength);
    StringArray newFieldNames;
    newFieldNames.reserve(newLength);
    FieldConstPtrArray fields;
    fields.reserve(newLength);
    for(size_t i=0; i<origLength; i++) {
        if(origPVFields[i]!=pvField) {
            newFieldNames.push_back(origPVFields[i]->getFieldName());
            newPVFields.push_back(origPVFields[i]);
            fields.push_back(origFields[i]);
        }
    }
    PVFieldPtrArray * xxx = const_cast<PVFieldPtrArray *>(&pvFields);
    xxx->swap(newPVFields);
    FieldConstPtr field = getFieldCreate()->createStructure(
        structurePtr->getID(),newFieldNames,fields);
    replaceField(field);
    structurePtr = static_pointer_cast<const Structure>(field);
    StringArray fieldNames = structurePtr->getFieldNames();
    for(size_t i=0; i<newLength; i++) {
        pvFields[i]->setParentAndName(this,fieldNames[i]);
    }
}