ecma_new_ecma_external_string_from_cesu8 (const lit_utf8_byte_t *string_p, /**< cesu-8 string */
                                          lit_utf8_size_t string_size, /**< string size */
                                          void *user_p) /**< user pointer passed to the callback
                                                         *   when the string is freed */
{
  JERRY_ASSERT (string_p != NULL || string_size == 0);
  JERRY_ASSERT (lit_is_valid_cesu8_string (string_p, string_size));

  if (string_size < (sizeof (ecma_external_string_t) - sizeof (ecma_short_string_t)))
  {
    /* Normal strings are created for short strings. */
    ecma_string_t *string_desc_p = ecma_new_ecma_string_from_utf8 (string_p, string_size);

    jerry_external_string_free_callback_t free_cb = JERRY_CONTEXT (external_string_free_callback_p);

    if (free_cb != NULL)
    {
      free_cb ((lit_utf8_byte_t *) string_p, string_size, user_p);
    }
    return string_desc_p;
  }

  ecma_string_t *string_desc_p = ecma_find_special_string (string_p, string_size);

  if (string_desc_p != NULL)
  {
    jerry_external_string_free_callback_t free_cb = JERRY_CONTEXT (external_string_free_callback_p);

    if (free_cb != NULL)
    {
      free_cb ((lit_utf8_byte_t *) string_p, string_size, user_p);
    }
    return string_desc_p;
  }

  ecma_external_string_t *external_string_p = ecma_alloc_external_string ();
  ecma_long_string_t *long_string_p = (ecma_long_string_t *) external_string_p;

  long_string_p->header.refs_and_container = ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING | ECMA_STRING_REF_ONE;
  long_string_p->header.u.hash = lit_utf8_string_calc_hash (string_p, string_size);
  long_string_p->string_p = string_p;
  long_string_p->size = string_size;
  long_string_p->length = lit_utf8_string_length (string_p, string_size);
  external_string_p->user_p = user_p;

  return (ecma_string_t *) external_string_p;
} /* ecma_new_ecma_external_string_from_cesu8 */
ecma_new_ecma_external_string_from_cesu8 (const lit_utf8_byte_t *string_p,  
                                          lit_utf8_size_t string_size,  
                                          void *user_p)  
{
  JERRY_ASSERT (string_p != NULL || string_size == 0);
  JERRY_ASSERT (lit_is_valid_cesu8_string (string_p, string_size));

  if (string_size < (sizeof (ecma_external_string_t) - sizeof (ecma_short_string_t)))
  {
     
    ecma_string_t *string_desc_p = ecma_new_ecma_string_from_utf8 (string_p, string_size);

    jerry_external_string_free_callback_t free_cb = JERRY_CONTEXT (external_string_free_callback_p);

    if (free_cb != NULL)
    {
      free_cb ((lit_utf8_byte_t *) string_p, string_size, user_p);
    }
    return string_desc_p;
  }

  ecma_string_t *string_desc_p = ecma_find_special_string (string_p, string_size);

  if (string_desc_p != NULL)
  {
    jerry_external_string_free_callback_t free_cb = JERRY_CONTEXT (external_string_free_callback_p);

    if (free_cb != NULL)
    {
      free_cb ((lit_utf8_byte_t *) string_p, string_size, user_p);
    }
    return string_desc_p;
  }

  ecma_external_string_t *external_string_p = ecma_alloc_external_string ();
  ecma_long_string_t *long_string_p = (ecma_long_string_t *) external_string_p;

  long_string_p->header.refs_and_container = ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING | ECMA_STRING_REF_ONE;
  long_string_p->header.u.hash = lit_utf8_string_calc_hash (string_p, string_size);
  long_string_p->string_p = string_p;
  long_string_p->size = string_size;
  long_string_p->length = lit_utf8_string_length (string_p, string_size);
  external_string_p->user_p = user_p;

  return (ecma_string_t *) external_string_p;
}  