示例#1
0
文件: timezone.cpp 项目: alyst/zorba
static TimeZone::value_type check_value( TimeZone::value_type gmtoff ) {
  if ( gmtoff < MinValue )
    throw range_error(
      BUILD_STRING( gmtoff, ": value < minimum value of ", MinValue )
    );
  if ( gmtoff > MaxValue )
    throw range_error(
      BUILD_STRING( gmtoff, ": value > maximum value of ", MaxValue )
    );
  return gmtoff;
}
示例#2
0
void Properties::setOptimizationLevel( unsigned opt_level ) {
  if ( opt_level > 2 )
    throw invalid_argument(
      BUILD_STRING( opt_level, ": invalid optimization level; must be [0-2]" )
    );
  optimization_level_ = opt_level;
}
示例#3
0
文件: timezone.cpp 项目: alyst/zorba
static TimeZone::value_type check_value( int hours, int minutes ) {
  bool const negative = hours < 0 || minutes < 0;

  if ( (hours = ::abs( hours )) > MaxHour )
    throw range_error(
      BUILD_STRING( hours, ": |hours| > maximum of ", MaxHour )
    );
  if ( (minutes = ::abs( minutes )) > 59 )
    throw range_error(
      BUILD_STRING( minutes, ": |minutes| > maximum of 59" )
    );
  if ( hours == MaxHour && minutes )
    throw range_error(
      BUILD_STRING( minutes, ": |minutes| > 0 when |hours| is ", MaxHour )
    );

  return (hours * 60 * 60 + minutes * 60) * (negative ? -1 : 1);
}
示例#4
0
bool parameters::then_else( bool expr, value_type const &s,
                            value_type::size_type *pos,
                            value_type *replacement ) const {
  value_type::value_type c = s[ *pos ];
  bool found_param = false, not_empty = false;

  switch ( c ) {
    case_123456789:
      found_param = true;
      if ( expr ) {
        *replacement = lookup_param( to_index( c ) );
        not_empty = !replacement->empty();
      }
      break;
    case '{':
      while ( ++*pos < s.size() ) {
        c = s[ *pos ];
        switch ( c ) {
          case_123456789:
            found_param = true;
            if ( expr ) {
              value_type const param = lookup_param( to_index( c ) );
              not_empty = !param.empty() || not_empty;
              *replacement += param;
            }
            break;
          case '}':
            goto done;
          case '\\':
            if ( *pos + 1 < s.size() )
              c = s[ ++*pos ];
            // no break;
          default:
            if ( expr )
              *replacement += c;
        } // switch
      } // while
      throw invalid_argument( "'}' expected for ?:" );
    default:
      throw invalid_argument(
        BUILD_STRING(
          '\'', c, "': invalid character after '", (expr ? '?' : ':'),
          "' (one of [1-9{] expected)"
        )
      );
  } // switch

done:
  return !found_param || not_empty;
}
示例#5
0
void dynamic_context::set_environment_variables()
{
  if (!theEnvironmentVariables)
    theEnvironmentVariables = new EnvVarMap();

#if defined (WIN32)
    LPTCH envVarsCH = GetEnvironmentStrings();
    LPTSTR envVarsSTR = (LPTSTR) envVarsCH;

    while (*envVarsSTR)
    {
      int size = lstrlen(envVarsSTR);

      char * envVar = new char[size+1];

      WideCharToMultiByte( CP_ACP,
                           WC_NO_BEST_FIT_CHARS|WC_COMPOSITECHECK|WC_DEFAULTCHAR,
                           envVarsSTR,
                           size+1,
                           envVar,
                           size+1,
                           NULL,
                           NULL);

      zstring envVarZS(envVar);

      int eqPos = envVarZS.find_first_of("=");

      if (eqPos > 0)
      {
        zstring varname(envVarZS.substr(0, eqPos));
        zstring varvalue(envVarZS.substr(eqPos+1, size));

        if (!varname.empty() || !varvalue.empty())
          theEnvironmentVariables->insert(std::pair<zstring, zstring>(varname,varvalue));
      }

      delete envVar;
      envVarsSTR += lstrlen(envVarsSTR) + 1;
    }

    FreeEnvironmentStrings(envVarsCH);
#else
    const char* invalid_char;
    for (char **env = environ; *env; ++env)
    {
      zstring envVarZS(*env);

      if ((invalid_char = utf8::validate(envVarZS.c_str())) != NULL)
        throw XQUERY_EXCEPTION(err::FOCH0001,
          ERROR_PARAMS(zstring("#x") +
          BUILD_STRING(std::uppercase << std::hex
            << (static_cast<unsigned int>(*invalid_char)&0xFF))));

      if ((invalid_char = utf8::validate(envVarZS.c_str())) != NULL)
      {
        throw XQUERY_EXCEPTION(err::FOCH0001,
        ERROR_PARAMS(zstring("#x") +
        BUILD_STRING(std::uppercase << std::hex
                     << (static_cast<unsigned int>(*invalid_char) & 0xFF)) ));
      }

      int size = envVarZS.size();

      int eqPos = envVarZS.find_first_of("=");

      if (eqPos > 0)
      {
        zstring varname(envVarZS.substr(0, eqPos));
        zstring varvalue(envVarZS.substr(eqPos+1, size));

        if (!varname.empty() || !varvalue.empty())
          theEnvironmentVariables->insert(std::pair<zstring, zstring>(varname,varvalue));
      }
    }

#endif

}
示例#6
0
void external_function::serialize(::zorba::serialization::Archiver& ar)
{
  zorba::serialization::serialize_baseclass(ar, (function*)this);

  ar & theNamespace;
  ar & theScriptingKind;

  // also serialize the localname of the function
  zstring lLocalName;
  if (ar.is_serializing_out()) 
  {
    computeCacheSettings(NULL);
    ZORBA_ASSERT(theImpl);
    lLocalName = Unmarshaller::getInternalString(theImpl->getLocalName());
  }
  ar.set_is_temp_field(true);
  ar & lLocalName;
  ar.set_is_temp_field(false);

  // if loaded, theImpl needs to be set immediately
  // this is covered by test/unit/external_function.cpp
  if (!ar.is_serializing_out()) 
  {
    try
    {
      theImpl = theModuleSctx->lookup_external_function(theNamespace, lLocalName);
    }
    catch (XQueryException& e)
    {
      set_source( e, theLoc );
      throw;
    }

    if (theImpl == NULL)
    {
      RAISE_ERROR(zerr::ZXQP0008_FUNCTION_IMPL_NOT_FOUND, theLoc,
        ERROR_PARAMS(BUILD_STRING( '{', theNamespace, '}', lLocalName)));
    }
  }

  ar & theLoc;
  ar & theHasCache;
  ar & theCacheAcrossSnapshots;
  if (ar.is_serializing_out())
  {
    saveFlags(theExcludeFromCacheKey, ar);
    saveFlags(theCompareWithDeepEqual, ar);
  }
  else
  {
    loadFlags(theExcludeFromCacheKey, ar);
    loadFlags(theCompareWithDeepEqual, ar);
  }
  ar & theAreCacheSettingsComputed;
  ar & theIsCacheAutomatic;

  if (!ar.is_serializing_out())
  {
    theCache.reset(new FunctionCache(
      theModuleSctx,
      theExcludeFromCacheKey,
      theCompareWithDeepEqual,
      theCacheAcrossSnapshots));
  }
}