<commit_before>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkSplitField.cxx

  Copyright (c) <NAME>, <NAME>, <NAME>
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkSplitField.h"

#include "vtkCellData.h"
#include "vtkDataSet.h"
#include "vtkDataSetAttributes.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"

vtkCxxRevisionMacro(vtkSplitField, "1.15");
vtkStandardNewMacro(vtkSplitField);

char vtkSplitField::FieldLocationNames[3][12] 
= { "DATA_OBJECT",
    "POINT_DATA",
    "CELL_DATA" };

char vtkSplitField::AttributeNames[vtkDataSetAttributes::NUM_ATTRIBUTES][10] 
=  { "SCALARS",
     "VECTORS",
     "NORMALS",
     "TCOORDS",
     "TENSORS" };

typedef vtkSplitField::Component Component;

vtkSplitField::vtkSplitField()
{
  this->FieldName = 0;
  this->FieldLocation = -1;
  this->AttributeType = -1;
  this->FieldType = -1;

  this->Head = 0;
  this->Tail = 0;
}

vtkSplitField::~vtkSplitField()
{
  delete[] this->FieldName;
  this->FieldName = 0;
  this->DeleteAllComponents();
}

void vtkSplitField::SetInputField(const char* name, int fieldLoc)
{
  if (!name)
    {
    return;
    }

  if ( (fieldLoc !=  vtkSplitField::DATA_OBJECT) &&
       (fieldLoc !=  vtkSplitField::POINT_DATA) &&
       (fieldLoc !=  vtkSplitField::CELL_DATA) )
    {
    vtkErrorMacro("The source for the field is wrong.");
    return;
    }

  this->Modified();
  this->FieldLocation = fieldLoc;
  this->FieldType = vtkSplitField::NAME;

  delete[] this->FieldName;
  this->FieldName = new char[strlen(name)+1];
  strcpy(this->FieldName, name);
}

void vtkSplitField::SetInputField(int attributeType, int fieldLoc)
{
  if ( (fieldLoc !=  vtkSplitField::POINT_DATA) &&
       (fieldLoc !=  vtkSplitField::CELL_DATA) )
    {
    vtkErrorMacro("The source for the field is wrong.");
    return;
    }

  this->Modified();
  this->FieldLocation = fieldLoc;
  this->FieldType = vtkSplitField::ATTRIBUTE;
  this->AttributeType = attributeType;

}

void vtkSplitField::SetInputField(const char* name,
                                  const char* fieldLoc)
{
  if ( !name || !fieldLoc)
    {
    return;
    }

  int numAttr = vtkDataSetAttributes::NUM_ATTRIBUTES;
  int numFieldLocs = 3;
  int i;

  // Convert strings to ints and call the appropriate SetInputField()
  int attrType=-1;
  for(i=0; i<numAttr; i++)
    {
    if (!strcmp(name, AttributeNames[i]))
      {
      attrType = i;
      break;
      }
    }

  int loc=-1;
  for(i=0; i<numFieldLocs; i++)
    {
    if (!strcmp(fieldLoc, FieldLocationNames[i]))
      {
      loc = i;
      break;
      }
    }
  if (loc == -1)
    {
    vtkErrorMacro("Location for the field is invalid.");
    return;
    }

  if (attrType == -1)
    {
    this->SetInputField(name, fieldLoc);
    }
  else
    {
    this->SetInputField(attrType, loc);
    }

}

void vtkSplitField::Split(int component, const char* arrayName)
{<commit_msg>BUG: Fix Bug #989 - vtkSplitField::SetInputField(char*,char*) fails with stack overflow. Thanks to <NAME> for patch.<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkSplitField.cxx

  Copyright (c) <NAME>, <NAME>, <NAME>
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkSplitField.h"

#include "vtkCellData.h"
#include "vtkDataSet.h"
#include "vtkDataSetAttributes.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"

vtkCxxRevisionMacro(vtkSplitField, "1.16");
vtkStandardNewMacro(vtkSplitField);

char vtkSplitField::FieldLocationNames[3][12] 
= { "DATA_OBJECT",
    "POINT_DATA",
    "CELL_DATA" };

char vtkSplitField::AttributeNames[vtkDataSetAttributes::NUM_ATTRIBUTES][10] 
=  { "SCALARS",
     "VECTORS",
     "NORMALS",
     "TCOORDS",
     "TENSORS" };

typedef vtkSplitField::Component Component;

vtkSplitField::vtkSplitField()
{
  this->FieldName = 0;
  this->FieldLocation = -1;
  this->AttributeType = -1;
  this->FieldType = -1;

  this->Head = 0;
  this->Tail = 0;
}

vtkSplitField::~vtkSplitField()
{
  delete[] this->FieldName;
  this->FieldName = 0;
  this->DeleteAllComponents();
}

void vtkSplitField::SetInputField(const char* name, int fieldLoc)
{
  if (!name)
    {
    return;
    }

  if ( (fieldLoc !=  vtkSplitField::DATA_OBJECT) &&
       (fieldLoc !=  vtkSplitField::POINT_DATA) &&
       (fieldLoc !=  vtkSplitField::CELL_DATA) )
    {
    vtkErrorMacro("The source for the field is wrong.");
    return;
    }

  this->Modified();
  this->FieldLocation = fieldLoc;
  this->FieldType = vtkSplitField::NAME;

  delete[] this->FieldName;
  this->FieldName = new char[strlen(name)+1];
  strcpy(this->FieldName, name);
}

void vtkSplitField::SetInputField(int attributeType, int fieldLoc)
{
  if ( (fieldLoc !=  vtkSplitField::POINT_DATA) &&
       (fieldLoc !=  vtkSplitField::CELL_DATA) )
    {
    vtkErrorMacro("The source for the field is wrong.");
    return;
    }

  this->Modified();
  this->FieldLocation = fieldLoc;
  this->FieldType = vtkSplitField::ATTRIBUTE;
  this->AttributeType = attributeType;

}

void vtkSplitField::SetInputField(const char* name,
                                  const char* fieldLoc)
{
  if ( !name || !fieldLoc)
    {
    return;
    }

  int numAttr = vtkDataSetAttributes::NUM_ATTRIBUTES;
  int numFieldLocs = 3;
  int i;

  // Convert strings to ints and call the appropriate SetInputField()
  int attrType=-1;
  for(i=0; i<numAttr; i++)
    {
    if (!strcmp(name, AttributeNames[i]))
      {
      attrType = i;
      break;
      }
    }

  int loc=-1;
  for(i=0; i<numFieldLocs; i++)
    {
    if (!strcmp(fieldLoc, FieldLocationNames[i]))
      {
      loc = i;
      break;
      }
    }
  if (loc == -1)
    {
    vtkErrorMacro("Location for the field is invalid.");
    return;
    }

  if (attrType == -1)
    {
    this->SetInputField(name, loc);
    }
  else
    {
    this->SetInputField(attrType, loc);
    }

}

void vtkSplitField::Split(int component, const char* arrayName)
{
{'fraction_non_alphanumeric': 0.1716750966974115, 'fraction_numerical': 0.00728949717346028, 'mean_word_length': 3.4700797872340425, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5687451', 'n_tokens_mistral': 2277, 'n_tokens_neox': 2230, 'n_words': 477}