<commit_before>/*
 * Copyright 2006-2008 The FLWOR Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "stdafx.h"

// standard
#include <cstring>
#include <string>

// Zorba
#include "ascii_util.h"
#include "cxx_util.h"
#include "string_util.h"
#include "zorbatypes/zstring.h"
#include "zorbautils/locale.h"

// local
#include "time_parse.h"
#include "time_util.h"

using namespace std;
using namespace zorba::locale;

namespace zorba {
namespace time {

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

static size_t min_len( char const *buf, size_t max_len ) {
  size_t len = 0;
  for ( char const *p = buf; *p; ++p )
    if ( ++len >= max_len )
      return max_len;
  return len;
}

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

exception::exception( string const &msg ) :
  runtime_error( msg )
{
}

exception::~exception() throw() {
  // out-of-line since it's virtual
}

insufficient_buffer::insufficient_buffer() :
  exception( "insufficient buffer" )
{
}

invalid_specification::invalid_specification( char spec ) :
  invalid_argument(
    BUILD_STRING( '\'', ascii::printable_char( spec ), "': invalid %" )
  ),
  spec_( spec )
{
}

invalid_specification::~invalid_specification() throw() {
  // out-of-line since it's virtual
}

invalid_value_specs::invalid_value_specs( char spec ) :
  specs_( 1, spec )
{
}

invalid_value_specs::invalid_value_specs( char const *specs ) :
  specs_( specs )
{
}

invalid_value_value::invalid_value_value( char c ) :
  value_( 1, c )
{
}

invalid_value_value::invalid_value_value( char const *buf, size_t len ) :
  value_( buf, min_len( buf, len ) )
{
  ascii::trim_end_whitespace( value_ );
}

template<typename ValueType>
invalid_value_value::invalid_value_value( ValueType const &value ) :
  value_( BUILD_STRING( value ) )
{
}

std::string invalid_value::build_msg( string const &value,
                                      string const &specs ) {
  return BUILD_STRING( '"', value, "\": invalid value for %", specs );
}

invalid_value::invalid_value( char const *buf, size_t len, char spec ) :
  invalid_value_value( buf, len ),
  invalid_value_specs( spec ),
  exception( build_msg( value_, specs_ ) )
{
}

invalid_value::invalid_value( char const *buf, size_t len, char const *specs ) :
  invalid_value_value( buf, len ),
  invalid_value_specs( specs ),
  exception( build_msg( value_, specs_ ) )
{
}

template<typename ValueType>
invalid_value::invalid_value( ValueType const &value, char spec ) :
  invalid_value_value( value ),
  invalid_value_specs( spec ),
  exception( build_msg( value_, specs_ ) )
{
}

template<typename ValueType>
invalid_value::invalid_value( ValueType const &value, char const *specs ) :
  invalid_value_value( value ),
  invalid_value_specs( specs ),
  exception( build_msg( value_, specs_ ) )
{
}

invalid_value::~invalid_value() throw() {
  // out-of-line since it's virtual
}

literal_mismatch::literal_mismatch( char expected, char got ) :
  exception(
    BUILD_STRING(
      '\'', ascii::printable_char( got ), "': literal character mismatched '",
      expected, '\''
    )
  ),
  expected_( expected ),
  got_( got )
{
}

literal_mismatch::~literal_mismatch() throw() {
  // out-of-line since it's virtual
}

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

struct rfc2822_obs_zone {
  char const *name;
  long gmtoff;
  bool isdst;
};

//
// See RFC 2822: "Internet Message Format," section 4.3, "Obsolete Date and
// Time."
//
static rfc2822_obs_zone const rfc2822_obs_zones[] = {
  { "GMT",  0                 },
  { "UTC",  0                 }, // non-RFC: be liberal in what you accept....
  { "UT" ,  0                 }, // must go after "UTC"
  { "EDT", -4 * 60 * 60, true },
  { "EST", -5 * 60 * 60       },
  { "CDT", -5 * 60 * 60, true },
  { "CST", -6 * 60 * 60       },
  { "MDT", -6 * 60 * 60, true },
  { "MST", -7 * 60 * 60       },
  { "PDT", -7 * 60 * 60, true },
  { "PST", -8 * 60 * 60       },
  { 0, 0, 0 }
};

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

typedef zstring (*locale_fn_type)(unsigned,iso639_1::type,iso3166_1::type);

template<typename IntType> inline
bool bits_set( IntType flags, IntType bits ) {
  return (flags & bits) == bits;
}
<commit_msg>Fixed warnings.<commit_after>/*
 * Copyright 2006-2008 The FLWOR Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "stdafx.h"

// standard
#include <cstring>
#include <string>

// Zorba
#include "ascii_util.h"
#include "cxx_util.h"
#include "string_util.h"
#include "zorbatypes/zstring.h"
#include "zorbautils/locale.h"

// local
#include "time_parse.h"
#include "time_util.h"

using namespace std;
using namespace zorba::locale;

namespace zorba {
namespace time {

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

static size_t min_len( char const *buf, size_t max_len ) {
  size_t len = 0;
  for ( char const *p = buf; *p; ++p )
    if ( ++len >= max_len )
      return max_len;
  return len;
}

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

exception::exception( string const &msg ) :
  runtime_error( msg )
{
}

exception::~exception() throw() {
  // out-of-line since it's virtual
}

insufficient_buffer::insufficient_buffer() :
  exception( "insufficient buffer" )
{
}

invalid_specification::invalid_specification( char spec ) :
  invalid_argument(
    BUILD_STRING( '\'', ascii::printable_char( spec ), "': invalid %" )
  ),
  spec_( spec )
{
}

invalid_specification::~invalid_specification() throw() {
  // out-of-line since it's virtual
}

invalid_value_specs::invalid_value_specs( char spec ) :
  specs_( 1, spec )
{
}

invalid_value_specs::invalid_value_specs( char const *specs ) :
  specs_( specs )
{
}

invalid_value_value::invalid_value_value( char c ) :
  value_( 1, c )
{
}

invalid_value_value::invalid_value_value( char const *buf, size_t len ) :
  value_( buf, min_len( buf, len ) )
{
  ascii::trim_end_whitespace( value_ );
}

template<typename ValueType>
invalid_value_value::invalid_value_value( ValueType const &value ) :
  value_( BUILD_STRING( value ) )
{
}

std::string invalid_value::build_msg( string const &value,
                                      string const &specs ) {
  return BUILD_STRING( '"', value, "\": invalid value for %", specs );
}

invalid_value::invalid_value( char const *buf, size_t len, char spec ) :
  invalid_value_value( buf, len ),
  invalid_value_specs( spec ),
  exception( build_msg( value_, specs_ ) )
{
}

invalid_value::invalid_value( char const *buf, size_t len, char const *specs ) :
  invalid_value_value( buf, len ),
  invalid_value_specs( specs ),
  exception( build_msg( value_, specs_ ) )
{
}

template<typename ValueType>
invalid_value::invalid_value( ValueType const &value, char spec ) :
  invalid_value_value( value ),
  invalid_value_specs( spec ),
  exception( build_msg( value_, specs_ ) )
{
}

template<typename ValueType>
invalid_value::invalid_value( ValueType const &value, char const *specs ) :
  invalid_value_value( value ),
  invalid_value_specs( specs ),
  exception( build_msg( value_, specs_ ) )
{
}

invalid_value::~invalid_value() throw() {
  // out-of-line since it's virtual
}

literal_mismatch::literal_mismatch( char expected, char got ) :
  exception(
    BUILD_STRING(
      '\'', ascii::printable_char( got ), "': literal character mismatched '",
      expected, '\''
    )
  ),
  expected_( expected ),
  got_( got )
{
}

literal_mismatch::~literal_mismatch() throw() {
  // out-of-line since it's virtual
}

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

struct rfc2822_obs_zone {
  char const *name;
  long gmtoff;
  bool isdst;
};

//
// See RFC 2822: "Internet Message Format," section 4.3, "Obsolete Date and
// Time."
//
static rfc2822_obs_zone const rfc2822_obs_zones[] = {
  { "GMT",  0          , false },
  { "UTC",  0          , false }, // non-RFC: be liberal in what you accept....
  { "UT" ,  0          , false }, // must go after "UTC"
  { "EDT", -4 * 60 * 60, true  },
  { "EST", -5 * 60 * 60, false },
  { "CDT", -5 * 60 * 60, true  },
  { "CST", -6 * 60 * 60, false },
  { "MDT", -6 * 60 * 60, true  },
  { "MST", -7 * 60 * 60, false },
  { "PDT", -7 * 60 * 60, true  },
  { "PST", -8 * 60 * 60, false },
  { 0, 0, false }
};

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

typedef zstring (*locale_fn_type)(unsigned,iso639_1::type,iso3166_1::type);

template<typename IntType> inline
bool bits_set( IntType flags, IntType bits ) {
  return (flags & bits) == bits;
}

{'fraction_non_alphanumeric': 0.19254978846352286, 'fraction_numerical': 0.018057991951295017, 'mean_word_length': 2.713409961685824, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2191818', 'n_tokens_mistral': 3279, 'n_tokens_neox': 3121, 'n_words': 854}