示例#1
0
inline std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, uuid& id)
{
    typedef typename std::basic_istream<CharT,Traits>::sentry sentry_t;
    sentry_t ok(is);
    if (ok)
    {
        CharT c;
        if (!is.get(c))
            return is;

        is.unget();

        if (c == is.widen('{'))
        {
            CharT buf[38+1];
            if (!is.read(buf, 38))
                return is;
            buf[38] = CharT();
            id = uuid(buf);
        }
        else
        {
            CharT buf[36+1];
            if (!is.read(buf, 36))
                return is;
            buf[36] = CharT();
            id = uuid(buf);
        }
    }
    return is;
}
示例#2
0
文件: quote.hpp 项目: zjucsxxd/carmel
template <class Output, class Ch, class Tr, class IsSpecial> inline
Output
in_quote(std::basic_istream<Ch, Tr> &i, Output out, IsSpecial is_special = IsSpecial(),
         char quote_char='"', char escape_char='\\')
{
  char c;
  if (i.get(c)) {
    *out++=c;
    if (c==quote_char) { // quoted - end delimited by unescape quote
      for (;;) {
        if (!i.get(c))
          goto fail;
        if (c==quote_char)
          break;
        if (c==escape_char)
          if (!i.get(c))
            goto fail;
        *out++=c;
      }
    } else { // unquoted - end delimited by an is_special char
      while (i.get(c)) {
        if (is_special(c)) {
          i.unget();
          break;
        }
        *out++=c;
      }
    }
  } // else end of stream.  shouldn't interpret as empty token but not throwing exception either.  check status of i before you use.
  return out;
fail:
  throw std::runtime_error("end of file reached when parsing quoted string (in_quote)");
}
示例#3
0
std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& in, pcg128_t& value)
{
    typename std::basic_istream<CharT,Traits>::sentry s(in);

    if (!s)
         return in;

    constexpr auto BASE = pcg128_t(10ULL);
    pcg128_t current(0ULL);
    bool did_nothing = true;
    bool overflow = false;
    for(;;) {
        CharT wide_ch = in.get();
        if (!in.good())
            break;
        auto ch = in.narrow(wide_ch, '\0');
        if (ch < '0' || ch > '9') {
            in.unget();
            break;
        }
        did_nothing = false;
        pcg128_t digit(uint32_t(ch - '0'));
        pcg128_t timesbase = current*BASE;
        overflow = overflow || timesbase < current;
        current = timesbase + digit;
        overflow = overflow || current < digit;
    }

    if (did_nothing || overflow) {
        in.setstate(std::ios::failbit);
        if (overflow)
            current = ~pcg128_t(0ULL);
    }

    value = current;

    return in;
}