Logo Search packages:      
Sourcecode: pan version File versions

std::string Scorefile::build_score_string ( const StringView section_wildmat,
int  score_value,
bool  score_assign_flag,
int  lifespan_days,
bool  all_items_must_be_true,
const AddItem items,
size_t  item_count 
) [static]

Utility to generate text for a new slrn-style scorefile entry.

See also:
AddItem

Definition at line 446 of file scorefile.cc.

References pan::StringView::empty(), pan::Scorefile::AddItem::key, pan::Scorefile::AddItem::negate, pan::Scorefile::AddItem::on, and pan::Scorefile::AddItem::value.

{
  const time_t now (time (0));
  std::ostringstream out;
  out << "%BOS" << std::endl
      << "%Score created by Pan on " << ctime(&now)
      << "[" << (section_wildmat.empty() ? "*" : section_wildmat) << ']' << std::endl
      << "Score" << (all_items_must_be_true ? ":" : "::") << " " << (score_assign_flag?"=":"") << score_value << std::endl;
  if (lifespan_days > 0) {
    time_t expire_time_t = now + lifespan_days * 24 * 3600;
    struct tm expire_tm (*localtime (&expire_time_t));
    int dd = expire_tm.tm_mday;
    int mm = expire_tm.tm_mon + 1;
    int yyyy = expire_tm.tm_year + 1900;
    out << "Expires: " << mm << '/' << dd << '/' << yyyy << std::endl;
  }
  for (size_t i(0); i!=item_count; ++i) {
    const Scorefile::AddItem& item (items[i]);
    if (!item.value.empty())
      out << (item.on ? "" : "%") << (item.negate ? "~" : "") << item.key << ": " << item.value << std::endl;
  }
  out << "%EOS";
  return out.str ();
}


Generated by  Doxygen 1.6.0   Back to index