Warning: This file is not a C or C++ file. It does not have highlighting.

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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC_STDIO_SCANF_CORE_READER_H
10#define LLVM_LIBC_SRC_STDIO_SCANF_CORE_READER_H
11
12#include "src/__support/macros/attributes.h" // For LIBC_INLINE
13#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 one
25 // character. When it hits the end of the string or file it returns '\0' to
26 // 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 if
33 // 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_core
43} // namespace LIBC_NAMESPACE_DECL
44
45#endif // LLVM_LIBC_SRC_STDIO_SCANF_CORE_READER_H
46

Warning: This file is not a C or C++ file. It does not have highlighting.

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of libc/src/stdio/scanf_core/reader.h