コード例 #1
0
void namespaces::property_op(
  property_mode mode, value const &id, value &data)
{
  local_root_scope scope;
  string name_ = id.to_string();
  xmlChar const *name = (xmlChar const*) name_.c_str();

  xmlChar *txt = 0;
  if (mode != property_get && mode != property_delete) {
    data = data.to_string();
    txt = xmlStrdup((xmlChar const *) data.get_string().c_str());
  }

  switch (mode) {
  case property_add:
    if (xmlHashAddEntry(table, name, txt) != 0)
      throw exception("Could not add entry to namespace hash table");
    break;
  case property_delete:
    if (xmlHashRemoveEntry(table, name, xmlHashDeallocator(xmlFree)) != 0)
      throw exception("Could not remove entry from namespace hash table");
    break;
  case property_set:
    if (xmlHashUpdateEntry(table, name, txt, xmlHashDeallocator(xmlFree))!=0)
      throw exception("Could not update entry in namespace hash table");
    break;
  case property_get:
    break;
  }
}
コード例 #2
0
ファイル: stream.cpp プロジェクト: the-kenny/flusspferd
string stream::read_line(value sep_) {
  local_root_scope scope;

  if (sep_.is_undefined_or_null())
    sep_ = string("\n");

  string sep = sep_.to_string();

  if (sep.length() != 1)
    throw exception("Line separators with size other than 1 are not supported");

  int sepc = sep.data()[0];

  if (sepc >= 128)
    throw exception("Non-ASCII line separators are not supported");

  std::string line;

  for (;;) {
    int ch = streambuf_->sbumpc();
    if (ch == std::char_traits<char>::eof())
      break;
    line += ch;
    if (ch == sepc)
      break;
  }

  return line;
}
コード例 #3
0
ファイル: expression_node.cpp プロジェクト: gischen/mapnik
value regex_match_node::apply(value const& v) const
{
    auto const& pattern = impl_.get()->pattern_;
#if defined(BOOST_REGEX_HAS_ICU)
    return boost::u32regex_match(v.to_unicode(),pattern);
#else
    return boost::regex_match(v.to_string(),pattern);
#endif
}
コード例 #4
0
ファイル: object.cpp プロジェクト: mmason930/kinslayer-mud
void object::delete_property(value const &id) {
  if (is_null())
    throw exception("Could not delete property (object is null)");
  local_root_scope scope;
  string name = id.to_string();
  jsval dummy;
  if (!JS_DeleteUCProperty2(Impl::current_context(), get(),
                            (jschar*)name.data(), name.length(), &dummy))
    throw exception("Could not delete property");
}
コード例 #5
0
ファイル: object.cpp プロジェクト: mmason930/kinslayer-mud
value object::set_property(value const &id, value const &v_) {
  if (is_null())
    throw exception("Could not set property (object is null)");
  local_root_scope scope;
  value v = v_;
  string name = id.to_string();
  if (!JS_SetUCProperty(Impl::current_context(), get(),
                        (jschar*)name.data(), name.length(),
                        Impl::get_jsvalp(v)))
    throw exception("Could not set property");
  return v;
}
コード例 #6
0
ファイル: object.cpp プロジェクト: mmason930/kinslayer-mud
bool object::has_property(value const &id) const {
  if (is_null())
    throw exception("Could not check property (object is null)");
  local_root_scope scope;
  string name = id.to_string();
  JSBool foundp;
  if (!JS_HasUCProperty(Impl::current_context(), get_const(),
                        (jschar*)name.data(), name.length(),
                        &foundp))
    throw exception("Could not check property");
  return foundp;
}
コード例 #7
0
ファイル: object.cpp プロジェクト: mmason930/kinslayer-mud
value object::get_property(value const &id) const {
  if (is_null())
    throw exception("Could not get property (object is null)");
  value result;
  local_root_scope scope;
  string name = id.to_string();
  if (!JS_GetUCProperty(Impl::current_context(), get_const(),
                        (jschar*)name.data(), name.length(),
                        Impl::get_jsvalp(result)))
    throw exception("Could not get property");
  return result;
}
コード例 #8
0
ファイル: expression_node.cpp プロジェクト: gischen/mapnik
value regex_replace_node::apply(value const& v) const
{
    auto const& pattern = impl_.get()->pattern_;
    auto const& format = impl_.get()->format_;
#if defined(BOOST_REGEX_HAS_ICU)
    return boost::u32regex_replace(v.to_unicode(),pattern,format);
#else
    std::string repl = boost::regex_replace(v.to_string(),pattern,format);
    transcoder tr_("utf8");
    return tr_.transcode(repl.c_str());
#endif
}
コード例 #9
0
ファイル: object.cpp プロジェクト: Flusspferd/flusspferd
bool object::has_own_property(value const &id) const {
  if (is_null())
    throw exception("Could not check property (object is null)");

  JSBool has;
  string name = id.to_string();
  if (!JS_AlreadyHasOwnPropertyById(Impl::current_context(), get_const(),
                                    Impl::get_jsid(id), &has))
  {
    throw exception("Unable to check for own property");
  }
  return has;
}
コード例 #10
0
ファイル: binary.cpp プロジェクト: Flusspferd/flusspferd
bool binary::property_resolve(value const &id, unsigned /*flags*/) {
  if (!id.is_int())
    return false;

  int uid = id.get_int();

  if (uid < 0)
    return false;

  if (size_t(uid) >= v_data.size())
    return false;
 
  value v = element(v_data[uid]);
  define_property(id.to_string(), v, permanent_shared_property);
  return true;
}
コード例 #11
0
ファイル: object.cpp プロジェクト: mmason930/kinslayer-mud
bool object::has_own_property(value const &id) const {
  if (is_null())
    throw exception("Could not check property (object is null)");

  JSBool has;
#if JS_VERSION >= 180
  string name = id.to_string();
  if (!JS_AlreadyHasOwnUCProperty(Impl::current_context(), get_const(),
                                  (jschar*)name.data(), name.length(), &has))
#else
  JSObject *obj = get_const();
  jsval argv[] = { Impl::get_jsval(id) };
  jsval vp;
  JSBool ret = js_HasOwnPropertyHelper(Impl::current_context(), obj,
                                       obj->map->ops->lookupProperty, 1, argv, 
                                       &vp);
  has = JSVAL_TO_BOOLEAN(vp);
  if (!ret)
#endif
  {
    throw exception("Unable to check for own property");
  }
  return has;
}
コード例 #12
0
 string_t perform(value const &v) {
   return v.to_string().to_utf16_string();
 }
コード例 #13
0
 std::string perform(value const &v) {
   return v.to_string().to_string();
 }
コード例 #14
0
 string perform(value const &v) {
   string s = v.to_string();
   root = s;
   return s;
 }