示例#1
0
// Returns true iff the given atom (specified by escaped and pattern)
// matches ch.  The result is undefined if the atom is invalid.
bool AtomMatchesChar(bool escaped, char pattern_char, char ch) {
  if (escaped) {  // "\\p" where p is pattern_char.
    switch (pattern_char) {
      case 'd': return IsAsciiDigit(ch);
      case 'D': return !IsAsciiDigit(ch);
      case 'f': return ch == '\f';
      case 'n': return ch == '\n';
      case 'r': return ch == '\r';
      case 's': return IsAsciiWhiteSpace(ch);
      case 'S': return !IsAsciiWhiteSpace(ch);
      case 't': return ch == '\t';
      case 'v': return ch == '\v';
      case 'w': return IsAsciiWordChar(ch);
      case 'W': return !IsAsciiWordChar(ch);
    }
    return IsAsciiPunct(pattern_char) && pattern_char == ch;
  }

  return (pattern_char == '.' && ch != '\n') || pattern_char == ch;
}
示例#2
0
// Reads an integer.
bool SymFile::ReadInteger(unsigned long& n)
{
    SkipWhitespace();

    if (!IsAsciiDigit(m_buffer[m_pos]))
        return false;

    int startPos = m_pos;
    int radix = 10;

    if (m_buffer[m_pos] == '0' && m_buffer[m_pos + 1] == 'x')
    {
        radix = 16;
        m_pos += 2;
    }

    unsigned long cutoff = ULONG_MAX / radix;
    unsigned long cutoffRemainder = ULONG_MAX % radix;
    int digit;

    n = 0;

    while ((digit = ConvertDigit(m_buffer[m_pos], radix)) != -1)
    {
        if (n < cutoff || (n == cutoff && (unsigned long)digit <= cutoffRemainder))
        {
            n = n * radix + digit;
        }
        else
        {
            m_pos++;

            while (ConvertDigit(m_buffer[m_pos], radix) != -1)
                m_pos++;

            RaiseError("integer is too large (%s)", std::string(&m_buffer[startPos], m_pos - startPos).c_str());
        }

        m_pos++;
    }

    return true;
}