<commit_before>﻿/* -*- coding: utf-8; mode: c++; tab-width: 3; indent-tabs-mode: nil -*-

Copyright 2010, 2011, 2012, 2013, 2014
<NAME>

This file is part of Application-Building Components (henceforth referred to as ABC).

ABC is free software: you can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.

ABC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.

You should have received a copy of the GNU General Public License along with ABC. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------------------------*/

#include <abc/core.hxx>
#include <abc/utf_traits.hxx>
#include <abc/iostream.hxx>



////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::enum_member


namespace abc {

/*static*/ enum_member const * enum_member::find_in_map(enum_member const * pem, int i) {
   ABC_TRACE_FN((pem, i));

   for (; pem->pszName; ++pem) {
      if (i == pem->iValue) {
         return pem;
      }
   }
   // TODO: provide more information in the exception.
   ABC_THROW(domain_error, ());
}
/*static*/ enum_member const * enum_member::find_in_map(
   enum_member const * pem, char_t const * psz
) {
   ABC_TRACE_FN((pem, psz));

   for (; pem->pszName; ++pem) {
      if (text::utf_traits<>::str_cmp(psz, pem->pszName) == 0) {
         return pem;
      }
   }
   // TODO: provide more information in the exception.
   ABC_THROW(domain_error, ());
}

} //namespace abc


////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::_enum_to_str_backend_impl


namespace abc {

_enum_to_str_backend_impl::_enum_to_str_backend_impl(char_range const & crFormat) {
   ABC_TRACE_FN((this, crFormat));

   auto it(crFormat.cbegin());

   // TODO: parse the format string.

   // If we still have any characters, they are garbage.
   if (it != crFormat.cend()) {
      ABC_THROW(syntax_error, (
         SL("unexpected character"), crFormat, unsigned(it - crFormat.cbegin())
      ));
   }
}


void _enum_to_str_backend_impl::write_impl(int i, enum_member const * pem, io::ostream * posOut) {
   ABC_TRACE_FN((this, i, pem, posOut));

   enum_member const * petvp(enum_member::find_in_map(pem, i));
   // TODO: apply format options.
   posOut->write(petvp->pszName);
}

} //namespace abc


////////////////////////////////////////////////////////////////////////////////////////////////////
<commit_msg>Ensure string pointer is printed as string<commit_after>﻿/* -*- coding: utf-8; mode: c++; tab-width: 3; indent-tabs-mode: nil -*-

Copyright 2010, 2011, 2012, 2013, 2014
<NAME>

This file is part of Application-Building Components (henceforth referred to as ABC).

ABC is free software: you can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.

ABC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.

You should have received a copy of the GNU General Public License along with ABC. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------------------------*/

#include <abc/core.hxx>
#include <abc/utf_traits.hxx>
#include <abc/iostream.hxx>



////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::enum_member


namespace abc {

/*static*/ enum_member const * enum_member::find_in_map(enum_member const * pem, int i) {
   ABC_TRACE_FN((pem, i));

   for (; pem->pszName; ++pem) {
      if (i == pem->iValue) {
         return pem;
      }
   }
   // TODO: provide more information in the exception.
   ABC_THROW(domain_error, ());
}
/*static*/ enum_member const * enum_member::find_in_map(
   enum_member const * pem, char_t const * psz
) {
   ABC_TRACE_FN((pem, psz));

   for (; pem->pszName; ++pem) {
      if (text::utf_traits<>::str_cmp(psz, pem->pszName) == 0) {
         return pem;
      }
   }
   // TODO: provide more information in the exception.
   ABC_THROW(domain_error, ());
}

} //namespace abc


////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::_enum_to_str_backend_impl


namespace abc {

_enum_to_str_backend_impl::_enum_to_str_backend_impl(char_range const & crFormat) {
   ABC_TRACE_FN((this, crFormat));

   auto it(crFormat.cbegin());

   // TODO: parse the format string.

   // If we still have any characters, they are garbage.
   if (it != crFormat.cend()) {
      ABC_THROW(syntax_error, (
         SL("unexpected character"), crFormat, unsigned(it - crFormat.cbegin())
      ));
   }
}


void _enum_to_str_backend_impl::write_impl(int i, enum_member const * pem, io::ostream * posOut) {
   ABC_TRACE_FN((this, i, pem, posOut));

   enum_member const * petvp(enum_member::find_in_map(pem, i));
   // TODO: apply format options.
   posOut->write(istr(petvp->pszName));
}

} //namespace abc


////////////////////////////////////////////////////////////////////////////////////////////////////

{'fraction_non_alphanumeric': 0.2456827487982909, 'fraction_numerical': 0.008545486914723162, 'mean_word_length': 2.038399134667388, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5064454', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1595, 'n_words': 498}