Logo Search packages:      
Sourcecode: schroot version File versions  Download package

template<class charT, class traits>
std::basic_istream<charT,traits>& operator>> ( std::basic_istream< charT, traits > &  stream,
keyfile kf 
) [friend]

keyfile initialisation from an istream.

Definition at line 500 of file sbuild-keyfile.h.

    {
      keyfile tmp;
      size_t linecount = 0;
      std::string line;
      std::string group;
      std::string comment;
      std::string key;
      std::string value;

      while (std::getline(stream, line))
      {
      linecount++;

      if (line[0] == '#') // Comment line
        {
          if (!comment.empty())
            comment += '\n';
          comment += line.substr(1);
        }
      else if (line[0] == '[') // Group
        {
          std::string::size_type fpos = line.find_first_of(']');
          std::string::size_type lpos = line.find_last_of(']');
          if (fpos == std::string::npos || fpos != lpos)
            {
            boost::format fmt(_("line %1%: invalid group entry: %2%"));
            fmt % linecount % line;
            throw error(fmt);
            }
          group = line.substr(1, fpos - 1);

          // Insert group
          if (tmp.has_group(group))
            {
            log_warning()
              << boost::format(_("line %1%: duplicate group entry: %2%"))
              % linecount % group
              << std::endl;
            }
          else
            tmp.set_group(group, comment);
          comment.clear();
        }
      else if (line.length() == 0)
        {
          // Empty line; do nothing.
        }
      else // Item
        {
          std::string::size_type pos = line.find_first_of('=');
          if (pos == std::string::npos)
            {
            boost::format fmt(_("line %1%: invalid line: %2%"));
            fmt % linecount % line;
            throw error(fmt);
            }
          if (pos == 0)
            {
            boost::format fmt(_("line %1%: no key specified: %2%"));
            fmt % linecount % line;
            throw error(fmt);
            }
          key = line.substr(0, pos);
          if (pos == line.length() - 1)
            value = "";
          else
            value = line.substr(pos + 1);

          // Insert item
          if (tmp.has_key(group, key))
            {
            log_warning()
              << boost::format(_("line %1%: group %2%: duplicate key entry: %3%"))
              % linecount % group % key
              << std::endl;
            }
          else
            tmp.set_value(group, key, value, comment);
          comment.clear();
        }
      }

      kf += tmp;

      return stream;
    }


Generated by  Doxygen 1.6.0   Back to index