/*******************************************************************\

Module: C/C++ Language Conversion

Author: Daniel Kroening, kroening@kroening.com

\*******************************************************************/

#include <assert.h>

#include <arith_tools.h>

#include "c_types.h"
#include "unescape_string.h"
#include "convert_string_literal.h"

/*******************************************************************\

Function: convert_string_literal

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/

void convert_string_literal(
  const std::string &src,
  std::string &dest)
{
  dest="";

  assert(src.size()>=2);
  assert(src[0]=='"');
  assert(src[src.size()-1]=='"');

  unescape_string(std::string(src, 1, src.size()-2), dest);
}

/*******************************************************************\

Function: convert_string_literal

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/

void convert_string_literal(const std::string &src, exprt &dest)
{
  std::string value;
  convert_string_literal(src, value);
  
  exprt size_expr=from_integer(value.size()+1, int_type());

  dest=exprt("string-constant");
  dest.type()=typet("array");
  dest.type().subtype()=char_type();
  dest.type().add("size").swap(size_expr);
  dest.add("value").id(value);
}
