package jgrasp_viewers_python;


import jgrasp.viewer.ViewerCreateData;
import jgrasp.viewer.ViewerException;
import jgrasp.viewer.ViewerInfo;
import jgrasp.viewer.ViewerPriorityData;
import jgrasp.viewer.jgrdi.DebugContext;
import jgrasp.viewer.jgrdi.Value;
import jgrasp.viewer.text.TextAreaView;


/** A viewer that displays a string as it could appear in source code. **/
public class builtins___str_SourceView extends TextAreaView {

   /** Creates a new string source-code-format viewer.
    *
    * @param vcd creation data. **/
   public builtins___str_SourceView(final ViewerCreateData vcd) {
   }


   /** {@inheritDoc} **/
   @Override
   public String getDisplayText(final Value value, final DebugContext context) throws ViewerException {
      //String result = value.toString(context);
      //***if (result.length() < 50) {
      return "not implemented";
      //return "\"" + result + "\"";
      //}
      // StringBuilder buf = new StringBuilder((int) (result.length() * 1.2));
      // for (int start = 0; start < result.length();) {
         // int end = start + 50;
         // if (end >= result.length()) {
            // end = result.length();
         // }
         // else {
            // int lastBackslash = result.lastIndexOf('\\', end - 1);
            // if (lastBackslash >= end - 1 || lastBackslash >= end - 6 && result.charAt(lastBackslash + 1) == 'u') {
            //    // Escape sequence would be broken.
               // end = lastBackslash;
            // }
         // }
         // if (start > 0) {
            // buf.append("+ ");
         // }
         // buf.append("\"");
         // buf.append(result, start, end);
         // buf.append("\"");
         // if (end < result.length()) {
            // buf.append('\n');
         // }
         // start = end;
      // }
      // return buf.toString();
   }


   /** {@inheritDoc} **/
   @Override
   public void getInfo(final ViewerInfo vi) {
      vi.setShortDescription("Source format viewer for string");
      vi.setLongDescription("This viewer displays a string as it would appear in Python source code. Note that if "
            + "the string does appear in source code, the format may not be exactly the same, but it will produce an "
            + "equivalent string.");
   }


   /** {@inheritDoc} **/
   @Override
   public int getPriority(final ViewerPriorityData vpd) {
      return 7;
   }


   /** {@inheritDoc} **/
   @Override
   public String getViewName() {
      return "Source Format";
   }
}
