<commit_before>package com.intellij.codeInsight.editorActions;

import com.intellij.openapi.editor.RawText;
import com.intellij.openapi.util.text.StringUtil;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

class TextBlockTransferable implements Transferable {
  private final Collection<TextBlockTransferableData> myExtraData;
  private final RawText myRawText;
  private final String myText;
  private final DataFlavor[] myTransferDataFlavors;

  public TextBlockTransferable(String text, Collection<TextBlockTransferableData> extraData, RawText rawText) {
    myText = text;
    myExtraData = extraData;
    myRawText = rawText;

    List<DataFlavor> dataFlavors = new ArrayList<DataFlavor>();
    Collections.addAll(dataFlavors, DataFlavor.stringFlavor, DataFlavor.plainTextFlavor, RawText.FLAVOR);
    for(TextBlockTransferableData data: extraData) {
      dataFlavors.add(data.getFlavor());
    }
    myTransferDataFlavors = dataFlavors.toArray(new DataFlavor[dataFlavors.size()]);
  }

  public DataFlavor[] getTransferDataFlavors() {
    return myTransferDataFlavors;
  }

  public boolean isDataFlavorSupported(DataFlavor flavor) {
    DataFlavor[] flavors = getTransferDataFlavors();
    for (DataFlavor flavor1 : flavors) {
      if (flavor.equals(flavor1)) {
        return true;
      }
    }
    return false;
  }

  public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    for(TextBlockTransferableData data: myExtraData) {
      if (data.getFlavor().equals(flavor)) {
        return data;
      }
    }
    if (RawText.FLAVOR.equals(flavor)) {
      return myRawText;
    }
    else if (DataFlavor.stringFlavor.equals(flavor)) {
      return myText;
    }
    else if (DataFlavor.plainTextFlavor.equals(flavor)) {
      return new StringReader(myText);
    }
    else {
      throw new UnsupportedFlavorException(flavor);
    }
  }

  public static String convertLineSeparators(String text,
                                             String newSeparator,
                                             Collection<TextBlockTransferableData> transferableDatas) {
    if (transferableDatas.size() > 0){
      int size = 0;
      for(TextBlockTransferableData data: transferableDatas) {
        size += data.getOffsetCount();
      }

      int[] offsets = new int[size];
      int index = 0;
      for(TextBlockTransferableData data: transferableDatas) {
        index = data.getOffsets(offsets, index);
      }

      text = StringUtil.convertLineSeparators(text, newSeparator, offsets);<commit_msg>protect against NCDFE (IDEADEV-24788)<commit_after>package com.intellij.codeInsight.editorActions;

import com.intellij.openapi.editor.RawText;
import com.intellij.openapi.util.text.StringUtil;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

class TextBlockTransferable implements Transferable {
  private final Collection<TextBlockTransferableData> myExtraData;
  private final RawText myRawText;
  private final String myText;
  private final DataFlavor[] myTransferDataFlavors;

  public TextBlockTransferable(String text, Collection<TextBlockTransferableData> extraData, RawText rawText) {
    myText = text;
    myExtraData = extraData;
    myRawText = rawText;

    List<DataFlavor> dataFlavors = new ArrayList<DataFlavor>();
    Collections.addAll(dataFlavors, DataFlavor.stringFlavor, DataFlavor.plainTextFlavor, RawText.FLAVOR);
    for(TextBlockTransferableData data: extraData) {
      dataFlavors.add(data.getFlavor());
    }
    myTransferDataFlavors = dataFlavors.toArray(new DataFlavor[dataFlavors.size()]);
  }

  public DataFlavor[] getTransferDataFlavors() {
    return myTransferDataFlavors;
  }

  public boolean isDataFlavorSupported(DataFlavor flavor) {
    DataFlavor[] flavors = getTransferDataFlavors();
    for (DataFlavor flavor1 : flavors) {
      if (flavor.equals(flavor1)) {
        return true;
      }
    }
    return false;
  }

  public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    try {
      for(TextBlockTransferableData data: myExtraData) {
        if (data.getFlavor().equals(flavor)) {
          return data;
        }
      }
      if (RawText.FLAVOR.equals(flavor)) {
        return myRawText;
      }
      else if (DataFlavor.stringFlavor.equals(flavor)) {
        return myText;
      }
      else if (DataFlavor.plainTextFlavor.equals(flavor)) {
        return new StringReader(myText);
      }
    }
    catch(NoClassDefFoundError e) {
      // ignore
    }
    throw new UnsupportedFlavorException(flavor);
  }

  public static String convertLineSeparators(String text,
                                             String newSeparator,
                                             Collection<TextBlockTransferableData> transferableDatas) {
    if (transferableDatas.size() > 0){
      int size = 0;
      for(TextBlockTransferableData data: transferableDatas) {
        size += data.getOffsetCount();
      }

      int[] offsets = new int[size];
      int index = 0;
      for(TextBlockTransferableData data: transferableDatas) {
        index = data.getOffsets(offsets, index);
      }

      text = StringUtil.convertLineSeparators(text, newSeparator, offsets);
{'fraction_non_alphanumeric': 0.0885987815491732, 'fraction_numerical': 0.0026109660574412533, 'mean_word_length': 3.4439288476411445, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6746805', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1686, 'n_words': 333}