<commit_before>/*-------------------------------------------------------------------------
 *
 *   FILE
 *	binarystring.cxx
 *
 *   DESCRIPTION
 *      implementation of bytea (binary string) conversions
 *
 * Copyright (c) 2003-2004, <NAME> <<EMAIL>>
 *
 * See COPYING for copyright license.  If you did not receive a file called
 * COPYING with this source code, please notify the distributor of this mistake,
 * or contact the author.
 *
 *-------------------------------------------------------------------------
 */
#include "pqxx/compiler.h"

#include <new>
#include <stdexcept>

#include "libpq-fe.h"

#include "pqxx/binarystring"


using namespace PGSTD;
using namespace pqxx::internal;

namespace
{
// Convert textual digit to value
inline char DV(unsigned char d) { return d - '0'; }
}

pqxx::binarystring::binarystring(const result::field &F) :
  super(),
  m_size(0)
{
  unsigned char *p = const_cast<unsigned char *>(
      reinterpret_cast<const_iterator>(F.c_str()));

#ifdef PQXX_HAVE_PQUNESCAPEBYTEA

  size_t sz = 0;
  super::operator=(PQunescapeBytea(p, &sz));
  if (!c_ptr()) throw bad_alloc();
  m_size = sz;

#else

  m_str.reserve(F.size()+1);
  for (result::field::size_type i=0; i<F.size(); ++i)
  {
    unsigned char c = p[i];
    if (c == '\\')
    {
      c = p[++i];
      if (isdigit(c) && isdigit(p[i+1]) && isdigit(p[i+2]))
      {
	c = (DV(p[c])<<9) | (DV(p[i+1])<<3) | DV(p[i+2]);
	i += 2;
      }
    }
    m_str += char(c);
  }

  m_size = m_str.size();<commit_msg>Removed unneeded "+1" in string reservation<commit_after>/*-------------------------------------------------------------------------
 *
 *   FILE
 *	binarystring.cxx
 *
 *   DESCRIPTION
 *      implementation of bytea (binary string) conversions
 *
 * Copyright (c) 2003-2004, <NAME> <<EMAIL>>
 *
 * See COPYING for copyright license.  If you did not receive a file called
 * COPYING with this source code, please notify the distributor of this mistake,
 * or contact the author.
 *
 *-------------------------------------------------------------------------
 */
#include "pqxx/compiler.h"

#include <new>
#include <stdexcept>

#include "libpq-fe.h"

#include "pqxx/binarystring"


using namespace PGSTD;
using namespace pqxx::internal;

namespace
{
// Convert textual digit to value
inline char DV(unsigned char d) { return d - '0'; }
}

pqxx::binarystring::binarystring(const result::field &F) :
  super(),
  m_size(0)
{
  unsigned char *p = const_cast<unsigned char *>(
      reinterpret_cast<const_iterator>(F.c_str()));

#ifdef PQXX_HAVE_PQUNESCAPEBYTEA

  size_t sz = 0;
  super::operator=(PQunescapeBytea(p, &sz));
  if (!c_ptr()) throw bad_alloc();
  m_size = sz;

#else

  m_str.reserve(F.size());
  for (result::field::size_type i=0; i<F.size(); ++i)
  {
    unsigned char c = p[i];
    if (c == '\\')
    {
      c = p[++i];
      if (isdigit(c) && isdigit(p[i+1]) && isdigit(p[i+2]))
      {
	c = (DV(p[c])<<9) | (DV(p[i+1])<<3) | DV(p[i+2]);
	i += 2;
      }
    }
    m_str += char(c);
  }

  m_size = m_str.size();
{'fraction_non_alphanumeric': 0.2508250825082508, 'fraction_numerical': 0.013201320132013201, 'mean_word_length': 2.3381057268722465, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2947149', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1052, 'n_words': 258}