brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · c71446e Raw
46 lines · c
1//===-- Reader definition for scanf -----------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC_STDIO_SCANF_CORE_READER_H10#define LLVM_LIBC_SRC_STDIO_SCANF_CORE_READER_H11 12#include "src/__support/macros/attributes.h" // For LIBC_INLINE13#include "src/__support/macros/config.h"14 15#include <stddef.h>16 17namespace LIBC_NAMESPACE_DECL {18namespace scanf_core {19 20template <typename Derived> class Reader {21  size_t cur_chars_read = 0;22 23public:24  // This returns the next character from the input and advances it by one25  // character. When it hits the end of the string or file it returns '\0' to26  // signal to stop parsing.27  LIBC_INLINE char getc() {28    ++cur_chars_read;29    return static_cast<Derived *>(this)->getc();30  }31 32  // This moves the input back by one character, placing c into the buffer if33  // this is a file reader, else c is ignored.34  LIBC_INLINE void ungetc(int c) {35    --cur_chars_read;36    static_cast<Derived *>(this)->ungetc(c);37  }38 39  LIBC_INLINE size_t chars_read() { return cur_chars_read; }40};41 42} // namespace scanf_core43} // namespace LIBC_NAMESPACE_DECL44 45#endif // LLVM_LIBC_SRC_STDIO_SCANF_CORE_READER_H46