⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attribute.cxx

📁 SP是一个基于GNU C++编译器
💻 CXX
📖 第 1 页 / 共 3 页
字号:
  return 0;}NotationAttributeSemantics::NotationAttributeSemantics(const ConstPtr<Notation> &notation): notation_(notation){}ConstPtr<Notation> NotationAttributeSemantics::notation() const{  return notation_;}AttributeSemantics *NotationAttributeSemantics::copy() const{  return new NotationAttributeSemantics(*this);}EntityAttributeSemantics::EntityAttributeSemantics(Vector<ConstPtr<Entity> > &entity){  entity.swap(entity_);}size_t EntityAttributeSemantics::nEntities() const{  return entity_.size();}ConstPtr<Entity> EntityAttributeSemantics::entity(size_t i) const{  return entity_[i];}AttributeSemantics *EntityAttributeSemantics::copy() const{  return new EntityAttributeSemantics(*this);}AttributeValue::AttributeValue(){}AttributeValue::~AttributeValue(){}AttributeSemantics *AttributeValue::makeSemantics(const DeclaredValue *,						  AttributeContext &,						  const StringC &,						  unsigned &,						  unsigned &) const{  return 0;}const Text *AttributeValue::text() const{  return 0;}Boolean AttributeValue::recoverUnquoted(const StringC &, const Location &,					AttributeContext &, const StringC &){  return 0;}ImpliedAttributeValue::ImpliedAttributeValue(){}AttributeValue::Type ImpliedAttributeValue::info(const Text *&,						 const StringC *&) const{  return implied;}TokenizedAttributeValue::TokenizedAttributeValue(Text &text,						 const Vector<size_t> &spaceIndex): spaceIndex_(spaceIndex){  text.swap(text_);}AttributeValue::Type TokenizedAttributeValue::info(const Text *&,						   const StringC *&string) const{  string = &text_.string();  return tokenized;}const Text *TokenizedAttributeValue::text() const{  return &text_;}AttributeSemantics *TokenizedAttributeValue::makeSemantics(const DeclaredValue *value,				       AttributeContext &context,				       const StringC &name,				       unsigned &nIdrefs,				       unsigned &nEntityNames) const{  if (text_.size() == 0)    return 0;  return value->makeSemantics(*this, context, name, nIdrefs, nEntityNames);}CdataAttributeValue::CdataAttributeValue(Text &text){  text.swap(text_);}AttributeValue::Type CdataAttributeValue::info(const Text *&text,					       const StringC *&) const{  text = &text_;  return cdata;}const Text *CdataAttributeValue::text() const{  return &text_;}Boolean CdataAttributeValue::recoverUnquoted(const StringC &str,					     const Location &strLoc,					     AttributeContext &context,					     const StringC &){  TextIter iter(text_);  TextItem::Type type;  const Char *s;  size_t len;  const Location *loc;  if (iter.next(type, s, len, loc)      && type == TextItem::data      && len == text_.size()      && loc->origin().pointer() == strLoc.origin().pointer()      && loc->index() + len == strLoc.index()      && !iter.next(type, s, len, loc)) {    text_.addChars(str, strLoc);    context.Messenger::setNextLocation(strLoc);    context.message(ParserMessages::unquotedAttributeValue);    return 1;  }  return 0;}Attribute::Attribute(): specIndexPlus_(0){}void Attribute::clear(){  specIndexPlus_ = 0;  value_.clear();  semantics_.clear();}AttributeList::AttributeList(const ConstPtr<AttributeDefinitionList> &def): def_(def), vec_(def.isNull() ? 0 : def->size()), nSpec_(0), conref_(0),  nIdrefs_(0), nEntityNames_(0){}AttributeList::AttributeList(): nSpec_(0), conref_(0){}void AttributeList::init(const ConstPtr<AttributeDefinitionList> &def){  def_ = def;  nSpec_ = 0;  conref_ = 0;  nIdrefs_ = 0;  nEntityNames_ = 0;  if (def_.isNull())    vec_.resize(0);  else {    size_t newLength = def_->size();    size_t clearLim = vec_.size();    if (clearLim > newLength)      clearLim = newLength;    vec_.resize(newLength);    for (size_t i = 0; i < clearLim; i++)      vec_[i].clear();  }}void AttributeList::changeDef(const ConstPtr<AttributeDefinitionList> &def){  vec_.resize(def.isNull() ? 0 : def->size());  def_ = def;}void AttributeList::swap(AttributeList &to){  vec_.swap(to.vec_);  def_.swap(to.def_);  {    unsigned tem = to.nIdrefs_;    to.nIdrefs_ = nIdrefs_;    nIdrefs_ = tem;  }  {    unsigned tem = to.nEntityNames_;    to.nEntityNames_ = nEntityNames_;    nEntityNames_ = tem;  }  {    size_t tem = to.nSpec_;    to.nSpec_ = nSpec_;    nSpec_ = tem;  }  {    PackedBoolean tem = to.conref_;    to.conref_ = conref_;    conref_ = tem;  }}void AttributeList::finish(AttributeContext &context){  for (size_t i = 0; i < vec_.size(); i++)    if (!vec_[i].specified()) {      ConstPtr<AttributeValue> value	= def(i)->makeMissingValue(context);      if (!conref_ || def_->notationIndex() != i) {	vec_[i].setValue(value);        if (!value.isNull())      	  vec_[i].setSemantics(def(i)->makeSemantics(value.pointer(),						     context,						     nIdrefs_,						     nEntityNames_));      }    }  const Syntax &syntax = context.attributeSyntax();  if (nIdrefs_ > syntax.grpcnt())    context.message(ParserMessages::idrefGrpcnt,		   NumberMessageArg(syntax.grpcnt()));  if (nEntityNames_ > syntax.grpcnt())    context.message(ParserMessages::entityNameGrpcnt,		   NumberMessageArg(syntax.grpcnt()));  if (context.validate()      && conref_      && def_->notationIndex() != size_t(-1)      && specified(def_->notationIndex()))    context.message(ParserMessages::conrefNotation);}void AttributeList::setSpec(unsigned i, AttributeContext &context){  if (vec_[i].specified())    context.message(ParserMessages::duplicateAttributeSpec,		   StringMessageArg(def(i)->name()));  else    vec_[i].setSpec(nSpec_++);}void AttributeList::noteInvalidSpec(){  // This is needed for error recovery.  // We don't want nSpec_ to be > 0, if there is no attribute definition.  if (nSpec_)    nSpec_++;}Boolean AttributeList::setValue(unsigned i, Text &text,				AttributeContext &context,				unsigned &specLength){  AttributeValue *value = def(i)->makeValue(text, context, specLength);  if (def(i)->isConref())    conref_ = 1;  vec_[i].setValue(value);  if (value)    vec_[i].setSemantics(def(i)->makeSemantics(value, context,					       nIdrefs_, nEntityNames_));  else if (AttributeValue::handleAsUnterminated(text, context))    return 0;  return 1;}void AttributeList::setValueToken(unsigned i, Text &text,				  AttributeContext &context,				  unsigned &specLength){  AttributeValue *value = def(i)->makeValueFromToken(text, context,						     specLength);  if (def(i)->isConref())    conref_ = 1;  vec_[i].setValue(value);  if (value)    vec_[i].setSemantics(def(i)->makeSemantics(value, context,					       nIdrefs_, nEntityNames_));}const StringC *AttributeList::getId() const{  // Check for no attributes  if (def_.isNull())    return 0;  // Check for no ID declared  size_t i = def_->idIndex();  if (i == size_t(-1))    return 0;  // Check for invalid value  const AttributeValue *v = value(i);  if (!v)    return 0;  // Check for implied value  const Text *t = v->text();  if (!t)    return 0;  return &t->string();}Boolean AttributeList::recoverUnquoted(const StringC &str,				       const Location &strLoc,				       AttributeContext &context){  if (nSpec_ > 0) {    for (size_t i = 0; i < vec_.size(); i++)      if (vec_[i].specified() && vec_[i].specIndex() == nSpec_ - 1) {	const AttributeValue *val = vec_[i].value();	if (val)	  // I wish I could avoid casting away const here.	  return ((AttributeValue *)val)->recoverUnquoted(str, strLoc, context,							  name(i));	break;      }    return 1;  }  return 0;}Boolean AttributeList::handleAsUnterminated(AttributeContext &context){  if (nSpec_ > 0) {    for (size_t i = 0; i < vec_.size(); i++) {      if (vec_[i].specified() && vec_[i].specIndex() == nSpec_ - 1) {	const AttributeValue *val = vec_[i].value();	const Text *ptr;	if (val && (ptr = val->text()) != 0	    && AttributeValue::handleAsUnterminated(*ptr, context))	  return 1;	break;      }    }  }  return 0;}// This tries to guess this attribute value looks like if it had// a missing ending quote.Boolean AttributeValue::handleAsUnterminated(const Text &text,					     AttributeContext &context){  TextIter iter(text);  const Char *lastStr = 0;  size_t lastLen;  Location startLoc;  const Location *loc;  TextItem::Type type;  const Char *str;  size_t len;  while (iter.next(type, str, len, loc)) {    if (startLoc.origin().isNull() && !loc->origin().isNull())      startLoc = *loc;    switch (type) {    case TextItem::data:      if (len != 1 || *str != context.attributeSyntax().space()) {	lastStr = str;	lastLen = len;      }      break;    case TextItem::endDelim:    case TextItem::endDelimA:    case TextItem::ignore:      break;    default:      lastStr = 0;      break;    }  }  if (lastStr) {    while (lastLen > 0	   && lastStr[lastLen - 1] == context.attributeSyntax().space())      lastLen--;    const StringC &vi = context.attributeSyntax().delimGeneral(Syntax::dVI);    if (lastLen >= vi.size()	&& (vi	    == StringC(lastStr + (lastLen - vi.size()), vi.size()))) {      context.Messenger::setNextLocation(startLoc);      context.message(ParserMessages::literalClosingDelimiter);      return 1;    }  }  return 0;}AttributeContext::AttributeContext(): mayDefaultAttribute_(0), validate_(1){}AttributeContext::~AttributeContext(){}Boolean AttributeContext::defineId(const StringC &, const Location &,				   Location &){  return 1;}void AttributeContext::noteIdref(const StringC &, const Location &){}void AttributeContext::noteCurrentAttribute(size_t, AttributeValue *){}ConstPtr<AttributeValue> AttributeContext::getCurrentAttribute(size_t) const{  return 0;}ConstPtr<Entity> AttributeContext::getAttributeEntity(const StringC &,						      const Location &){  return 0;}ConstPtr<Notation> AttributeContext::getAttributeNotation(const StringC &,							  const Location &){  return 0;}ConstPtr<AttributeValue> AttributeContext::makeImpliedAttributeValue(){  if (impliedAttributeValue_.isNull())    impliedAttributeValue_ = new ImpliedAttributeValue;  return impliedAttributeValue_;}#ifdef SP_NAMESPACE}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -